How to apply distance transform on labelled matrix

I have got a labelled matrix and want to apply distance tranform on the diffent different labels in the matrix. How can it be done in matlab?
Thanks

4 Comments

When you apply the distance transform, are the regions labeled with other labels to be considered unpassable or passable? Or, for example, are regions with a numerically greater label number to be unpassable while regions with numerically lower label number are to be considered passable ?
Do all of the results need to somehow be synthesized into one matrix, or can there be one output for each distinct label?
Dear Roberson,
I think you got my question correctly, I need the results into one matrix.
I am attaching my code and flowchart here for clearity.
CC = bwconncomp(B,8);
L = labelmatrix(CC);
num = max(L(:));
D = zeros(size(B));
for iter = 1:Inf % loop for new regions
for j= 1:num
[r,c] = find(L==j);
for k = 1:size(r,1)
D = my_dist(B(r(k,1),c(k,1)));
end
L = watershed(D);
num1(j) = max(L(:));
end
num = sum(num1);
if abs(num(iter+1)-num(iter)) == 0
break
end
end
is this https://ieeexplore.ieee.org/document/885672

Sign in to comment.

Answers (1)

Hi Rizwan,
I am assuming the matrix as binary. You can refer to Distance Transform of a Binary Image.
Regrds,
Anmol Dhiman

3 Comments

The user specifically talks about a label matrix. Those are not binary (logical): they are numeric matrices in which each unique value defines a different region (except that 0 is always background.)
That's why it doesn't make sense. Why on earth would you even want to try to do a distance transform on a labeled image? What would even be the formula for distance in that case? And what would he do with the result? I think this is a case of a user thinking he wants something, but he really doesn't want that, he just doesn't know it yet.
Dear Image Analyst,
This is the flowchart which i need to implement in matalb.
CC = bwconncomp(B,8);
L = labelmatrix(CC);
num = max(L(:));
D = zeros(size(B));
for iter = 1:Inf % loop for new regions
for j= 1:num
[r,c] = find(L==j);
for k = 1:size(r,1)
D = my_dist(B(r(k,1),c(k,1)));
end
L = watershed(D);
num1(j) = max(L(:));
end
num = sum(num1);
if abs(num(iter+1)-num(iter)) == 0
break
end
end

Sign in to comment.

Asked:

on 17 Jul 2020

Commented:

on 21 Jul 2020

Community Treasure Hunt

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

Start Hunting!