bwconncomp with "labeled" input
1 次查看(过去 30 天)
显示 更早的评论
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]);
0 个评论
采纳的回答
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))
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!