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

时间:2013-11-14 18:06:05

标签: arrays image matlab 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]

这里我有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)

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

1 个答案:

答案 0 :(得分:5)

在矩阵上使用bwlabel来做到这一点。

A=bwlabel(I)