From: Darlis on
Dear Matlab Community,

Please help me to find the fastest way to find the nearest distance between the labels/group in binary image.
For example:
L = bwlabel(BW)

L =

1 1 0 0 0 0 0 0
0 1 0 0 2 0 0 0
0 0 0 0 2 2 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 3 0
0 0 0 0 0 0 3 3
0 0 0 0 0 0 0 0

% assume there is a function to get the distance between label
% using chessboard method
L_dist = labelDistance(L,'chessboard')

L_dist =
1 2 3 r1 c1 r2 c2
2 1 3 r1 c1 r2 c2
3 2 3 r1 c1 r2 c2
% 1st col = ref label
% 2nd col = nearest label (1st col)
% 3rd col = distance (chessboard method)
% 4th col = row label 1
% 5th col = col label 1
% 4th col = row label 2 (nearest label)
% 5th col = col label 2 (nearest label)

thanks in advance.

Regards,
Darlis Herumurti
From: kinor on
"Darlis " <darlis(a)cs.its.ac.id> wrote in message <hijtct$ls8$1(a)fred.mathworks.com>...
> Dear Matlab Community,
>
> Please help me to find the fastest way to find the nearest distance between the labels/group in binary image.
> For example:
> L = bwlabel(BW)
>
> L =
>
> 1 1 0 0 0 0 0 0
> 0 1 0 0 2 0 0 0
> 0 0 0 0 2 2 0 0
> 0 0 0 0 0 0 0 0
> 0 0 0 0 0 0 0 0
> 0 0 0 0 0 0 3 0
> 0 0 0 0 0 0 3 3
> 0 0 0 0 0 0 0 0
>
> % assume there is a function to get the distance between label
> % using chessboard method
> L_dist = labelDistance(L,'chessboard')
>
> L_dist =
> 1 2 3 r1 c1 r2 c2
> 2 1 3 r1 c1 r2 c2
> 3 2 3 r1 c1 r2 c2
> % 1st col = ref label
> % 2nd col = nearest label (1st col)
> % 3rd col = distance (chessboard method)
> % 4th col = row label 1
> % 5th col = col label 1
> % 4th col = row label 2 (nearest label)
> % 5th col = col label 2 (nearest label)
>
> thanks in advance.
>
> Regards,
> Darlis Herumurti

Hi Darlis,

if you have the perimeters of the labels (by imregionprop or imerode and find) you could pairwise calculate all distances of all perimeter points of two labels. As last step you search for the minimum of those distances.

This is fast to implement but not fast running.

hth
kinor
From: Darlis on
thank for your suggestion, very helpfull.
I have tried a similar way :
- get centroid using regionprops for each label/group
- find distance using pdist
- calculate linkage

may be, there are another idea that run very fast

thanks in advance
Darlis

> Hi Darlis,
>
> if you have the perimeters of the labels (by imregionprop or imerode and find) you could pairwise calculate all distances of all perimeter points of two labels. As last step you search for the minimum of those distances.
>
> This is fast to implement but not fast running.
>
> hth
> kinor
From: ImageAnalyst on
Darlis:
Have you looked at the various options of the bwdist() function?
-ImageAnalyst
From: Darlis on
Dear Image Analist,
Thx, I think I have to make a bit code using bwdist().
so the idea is the label that I want to measure the distance between another label has to set to 0, and then use bwdist() to get the nearest label and the dist on the label pixel position.
this is a good idea, I will try it soon.
thanks in advance

Darlis

ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <149e92ba-7b44-4db2-b7d3-469a169452f4(a)f5g2000yqh.googlegroups.com>...
> Darlis:
> Have you looked at the various options of the bwdist() function?
> -ImageAnalyst