Find closest non-zero pixel, but only travel through pixels of value zero?

1 visualizzazione (ultimi 30 giorni)
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.

Risposte (1)

darova
darova il 15 Mag 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)
  1 Commento
Eric Chadwick
Eric Chadwick il 15 Mag 2019
How does this address my constraint that the path from one point to another must be through zero pixels only?
Your solution would just find the closest pixel regardless of if the path to that closest pixel crosses a region of non-zero pixels. This is the same as knnsearch.

Accedi per commentare.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by