Find closest non-zero pixel, but only travel through pixels of value zero?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
darova
le 15 Mai 2019
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)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!