I would like to give a different color for the same group of numbers.
Suppose I have an image 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]
here I have a group 1s 2 times and I would like to give two different colors for each group. but I cannot make them as two groups. I can just give one color for both groups.
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)
please help me...............
source
share