Measure distances in binary image along specified directions
Afficher commentaires plus anciens
Hello,
In the attached image (binary_im_example), I would like to, for every black pixel, measure the distance to the nearest white pixel, along specified directions.
The second attached image (binary_dist_example) shows an example of what I mean by this, for a particular pixel. Along 8 lines (vertical up and down, horizontal left and right and along lines at 45 degrees to these) I would like to measure the distance from every black pixel to the nearest white pixel.
Overall, my goal is to find an "average" distance for each black pixel, to the nearest white pixel (by averaging the distance along these 8 lines). For this purpose the distance transform is not suitable, because this would only give the minimum distance.
If there are alternative ways to measure an average distance in this way, it would also be interesting to hear about them!
Cheers
10 commentaires
KSSV
le 28 Avr 2022
There are many pixles which are nearest, why did you choose only those pixels?
Angus Coyne
le 28 Avr 2022
DGM
le 28 Avr 2022
In this scheme, is the distance between two diagonal neighbors 1 or sqrt(2)?
Angus Coyne
le 28 Avr 2022
Jan
le 28 Avr 2022
What does "average over all possible directions" exactly mean? There is an infinite number of directions. Maybe you want to use the directions between a pixel and all pixels on the border of the image? But does this satisfy your needs for a pixel on the border? It has valid directions over 180° only, while center pixels have 360°. So the pixels at the center might be weighted higher than the pixels near to the borders.
Start with defining the wanted procedure mathematically. With an exact definition, the implementation in code is not compicated anymore.
DGM
le 28 Avr 2022
The definition seems fairly clear to me. OP wants a distance transform that only considers pixels along the four cardinal directions and four diagonals WRT any background pixel, so it's like a restricted case of a regular euclidean distance xform.
I'm not coming up with remotely elegant solutions at the moment.
Angus Coyne
le 28 Avr 2022
DGM
le 28 Avr 2022
I was going to say something to the effect of "I haven't come up with an elegant solution, but I'm sure something better than a naive approach would exist", but given the conditional handling of cases where no directional neighbor exists, I'm not so sure about that anymore.
I'm probably going to have to tap out anyway, considering I can't even stay online for more than 30 seconds at a time right now.
Matt J
le 28 Avr 2022
Certain pixels have no nearest white pixel along some of the 8 directions. For example, the black pixels along the lower edge of the image can have at most one vertical neighbor. How are those cases to be handled?
Angus Coyne
le 28 Avr 2022
Réponse acceptée
Plus de réponses (1)
Image Analyst
le 28 Avr 2022
1 vote
Is it going to be in 3-D? That measurement is called "star volume". There are papers on it.
2 commentaires
Angus Coyne
le 28 Avr 2022
Image Analyst
le 28 Avr 2022
Yes. It's commonly used in open cell foams, like trabecular bone, where you want a "cell size" but the concept of a "cell" is not so well defined, as opposed to a closed cell foam where all the cells are like air bubbles completely enclosed by the material.
Catégories
En savoir plus sur Image Processing Toolbox dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
