Find closest non-zero pixel, but only travel through pixels of value zero?
6 次查看(过去 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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/219569/image.png)
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!