Image Processing: Find nearest nonzero pixel value to specified pixel coordinates

8 vues (au cours des 30 derniers jours)
Philip
Philip le 18 Sep 2011
Is there a way to find the closest non-zero pixel value to specified x,y coordinates of an image by shifting only the horizontal 'x' direction?
For example, if I have the coordinates 100, 100, the pixel value is zero, but there is a 1 at the coordinates 100, 98. Is there a way that I can find this 1 automatically, and retrieve the correct coordinates (98,100)?
As always, thanks for your help!

Réponses (1)

Walter Roberson
Walter Roberson le 18 Sep 2011
[nz, nzidx] = find(YourArray(:,y));
[offset, offsetidx] = min(abs(x - nzidx));
nearestpixelidx = nzidx(offsetidx);

Catégories

En savoir plus sur Geometric Transformation and Image Registration dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by