bwconncomp with "labeled" input

1 visualizzazione (ultimi 30 giorni)
RuiQi
RuiQi il 19 Giu 2017
Commentato: RuiQi il 19 Giu 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]);

Risposta accettata

Guillaume
Guillaume il 19 Giu 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))

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by