Binary Element Distance Function (similar to graycomatrix)

2 visualizzazioni (ultimi 30 giorni)
I would like a function that takes a binary image, and outputs the minimum distance between connected elements of different sizes.
Example:
BW =
1 1 0 1 0
0 0 0 1 0
0 0 0 0 0
1 1 0 0 0
1 0 0 0 1
MinimumDistanceMatrix =
0 2 2 0 0 0
2 1 1 0 0 0
2 1 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
This output is similar to the graycomatrix output matrix, suchthat value (1,1) represents the minimum distace between any 2 elements of size 1 and 1. And (2,1) represents the minimum distace between any 2 elements of size 2 and 1.
Note: The result will always be a symmetric matrix because the minimum distance from 2 elements of size i and j will be identical to the minimum distance from 2 elements of size j and i.
I have started going down the path of using bwlabel on the initial binary image to get a matrix of each unique elements.
LabeledBW =
1 1 0 3 0
0 0 0 3 0
0 0 0 0 0
2 2 0 0 0
2 0 0 0 4
Then selecting each element and changing each value of the element to be the size of the element.
BWElementSize =
2 2 0 2 0
0 0 0 2 0
0 0 0 0 0
3 3 0 0 0
3 0 0 0 1
But form here the only way I have thought of to get to the result I want is to use the graycomatrix function in a rediculous set of loops which will be sure to be very slow and I want to avoid coding.
So if anyone has any sugestions I would love to hear them. I feel like I am headed down the wrong path with the loops and there must be a better way to do this.
Thanks, Barrett

Risposte (0)

Categorie

Scopri di più su Convert Image Type in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by