Connected Component Labeling with Different Pixel/Cell Sizes

1 view (last 30 days)
I have a 3D matrix ( 73 x 144 x 25738 ) in which I am using the following code to label clusters of pixels, then further group clusters that are within a certain distance into the same group:
data = 1 slice of 3D matrix or a 73 x 144 boolean
cc = bwconncomp(data);
L = labelmatrix(cc);
bw = bwdist(data) <= 2; % merges clusters based on distance
L2 = labelmatrix(bwconncomp(bw));
s = regionprops(L2, 'Area');
[s.Area];
L2(~data) = 0;
s = regionprops(L2, 'Area');
[s.Area];
But the problem I have is that my pixels or cells are actually lat/long grid cells, thus each pixel is technically a different area (in sq km) and using bw = bwdist(data) <= 2 would need to take this into account. Is there a way to specify the size of each pixel and then use a euclidean distance calculation like bwdist to group close clusters?

Answers (0)

Community Treasure Hunt

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

Start Hunting!