如何找到相同数量和颜色的组在MATLAB中给出不同的颜色?

use*_*283 4 arrays matlab image image-processing matrix

我想为同一个号码组提供不同的颜色.

假设我有一个图像矩阵.

I = [0     0     0     0     0     0     0     0     0     0
     0     0     1     0     0     0     0     0     0     0
     0     1     1     0     0     0     0     1     0     0
     0     1     1     1     0     0     1     1     0     0
     0     1     1     0     0     0     1     1     1     0
     0     0     1     1     0     0     1     1     0     0
     0     0     1     1     0     0     0     1     0     0
     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0]
Run Code Online (Sandbox Code Playgroud)

在这里,我有2次1组,我想为每组给两种不同的颜色.但我不能把他们当作两个小组.我可以为这两组提供单一颜色.

sz=size(I);
color=(1,3)

    red(I == 1) = color(1, 1);
    green(I == 1) = color(1, 2);
    blue(I == 1) = color(1, 3);
    for i = 1:sz(1)
        for j = 1:sz(2)            
            if L(i, j) == 1
                red(i, j) = color(1, 1);
                green(i, j) = color(1, 2);
                blue(i, j) = color(1, 3);
            end
        end
    end
end
im = cat(3, red, green, blue);
figure, imshow(im)
Run Code Online (Sandbox Code Playgroud)

请帮我...............

bla*_*bla 5

bwlabel在你的矩阵上使用它来做到这一点.

A=bwlabel(I)
Run Code Online (Sandbox Code Playgroud)