【问题标题】:how to find the groups of same number and color gives the different color in MATLAB?如何在MATLAB中找到相同数量和颜色的组给出不同的颜色?
【发布时间】:2013-11-27 21:36:39
【问题描述】:

我想为同一个号码组赋予不同的颜色。

假设我有一个图像矩阵。

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]

在这里,我有 1 组 2 次,我想为每组提供两种不同的颜色。但我无法将它们分成两组。我可以只为两个组提供一种颜色。

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)

请帮帮我……

【问题讨论】:

  • 你的意思是,你想为以下模式赋予不同的颜色:[0,0,...,1,0,...0][0,0,...,1,1,...0][0,0,...,1,1,1,0,...0]
  • 亲爱的 Parag 我只想要 1 的值。因为我有 1 个值的 2 个组。
  • 哦,你的意思是这样的:)

标签: arrays image matlab image-processing matrix


【解决方案1】:

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

A=bwlabel(I)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-22
    • 1970-01-01
    • 2011-10-10
    • 1970-01-01
    • 2013-10-08
    • 2019-12-27
    • 2016-10-19
    相关资源
    最近更新 更多