Find closest non-zero pixel, but only travel through pixels of value zero?
조회 수: 1 (최근 30일)
이전 댓글 표시
I would like to find the closest non-zero pixel to many points in my 3D image as per [~,Idx] = bwdist(volume), except with the condition that the returned index is of the closest non-zero pixel that is reachable by travelling through zero pixels (pixels with a value of zero).
Below I have shown an example of what I would like, where I am trying to determine the closest white pixel to each dark pixel while only travelling through dark pixels. In this example we have a dark pixel near the edge of a dark region that would normally choose the white pixel circled to the right as the closest white pixel. I would like the pixel circle to the left to be chosen.
And of course I would like to be able to do this quickly and memory efficiently, but that is secondary. Anyone have any ideas?
Thank you in advance!
Cheers,
Eric
Edit: I have added this sample image unannotated if anyone wants to try out a method on it.
댓글 수: 0
답변 (1개)
darova
2019년 5월 15일
What if just use pythagoras theorem?
I = imread('capture2.PNG')
[y,x] = find(I(200:300,200:300)); % extracting non-zero pixels from region
y = y + 200;
x = x + 200;
D = sqrt( (x0-x).^2 + (y0-y).^2 );
min(D)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!