bwconncomp with "labeled" input

조회 수: 1 (최근 30일)
RuiQi
RuiQi 2017년 6월 19일
댓글: RuiQi 2017년 6월 19일
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]);

채택된 답변

Guillaume
Guillaume 2017년 6월 19일
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
RuiQi
RuiQi 2017년 6월 19일
that is so cool !

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by