bwconncomp with "labeled" input

1 vue (au cours des 30 derniers jours)
RuiQi
RuiQi le 19 Juin 2017
Commenté : RuiQi le 19 Juin 2017
I want to pass my segmented image into an algorithm and it requires that the array has all the values in it up till the max value in the array. For example, I will get an error if I pass in the array below because there are no elements with the values [2, 3, 4, 5, 6, 7, 8, 11 to 19]. Is there a function that will reassign the value of each element such that
1 -> 1
9 -> 2
10 -> 3
20 -> 4
It does not have to be ordered. I tried using bwconncomp but it still connects pixels that do not have the same value as long as they are not zero.
BW = logical ([10 10 10 20 9 9 9 9
10 10 10 20 1 1 1 9
10 10 10 20 1 1 1 9
10 10 10 20 20 20 1 9
10 10 10 20 20 20 1 9
10 10 10 20 20 20 9 9]);

Réponse acceptée

Guillaume
Guillaume le 19 Juin 2017
You don't need anything like bwconncomp for such a simple operation:
A = [10 10 10 20 9 9 9 9
10 10 10 20 1 1 1 9
10 10 10 20 1 1 1 9
10 10 10 20 20 20 1 9
10 10 10 20 20 20 1 9
10 10 10 20 20 20 9 9]
[~, ~, loc] = unique(A);
reshape(loc, size(A))
  1 commentaire
RuiQi
RuiQi le 19 Juin 2017
that is so cool !

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by