2014-06-25 88 views
1

我有一个逻辑图像。我想将黑色像素转换为其他颜色。将黑色像素转换为其他颜色

我可以将它们转换为黑绿色和蓝色,但我不知道我怎么可以把他们像橙,紫,粉红等色......

有什么办法,使这个?

我使用此代码

RGB = zeros(3072, 4080, 1); 
RGB(:, :, 3) = 1-BW; 
imshow(RGB); 

问候

回答

0

代码

BW = logical(round(rand(5,6))) %// random logical image as input for demo 
color1 = [129 52 168]; %// random color to be superimposed on the black pixels 

%// Create a 3D double array with zeros from BW replaced by color1 values 
%// and ones by zeros 
RGB1 = bsxfun(@times,double(~BW),permute(color1,[1 3 2])); 

%// Replace the zeros created from the previous step to 255s, as they 
%// denote ones in the input logical image 
RGB = uint8(RGB1+(RGB1==0).*255); %// desired output RGB image in UINT8 format 
imagesc(RGB),axis off %// display the RGB image for verification 

输出(上运行的代码)

BW = 
    1  0  1  1  0  1 
    0  0  1  0  0  1 
    0  1  1  1  1  0 
    0  0  1  1  1  1 
    0  1  0  0  0  0 

enter image description here

希望这会为你工作!让我知道。

+0

它完美的作品 – ffttyy

+0

@sigara真棒!很高兴它对你有效。 – Divakar

1

要得到非原色它们转换为蓝色,你需要编辑的颜色层的一个以上的值 - 每个像素由红色,绿色和蓝色子像素(即RGB)组成。基本上你需要找到强度的组合来使你的色彩更上一层楼。

如果你想设置颜色为亮黄色,下面应该工作:

RGB(:, :, 3) = blue_intensity; 
RGB(:, :, 2) = green_intensity; 

的黄色光从蓝色和绿色制造。如果你想要比其他颜色更多的颜色,只需要使一个亮度数字高于另一个。

如果您发布了您正在尝试实现的内容,我可以发布更清晰的答案。

此外,我相信你的拳头行应为RGB = zeros(3072, 4080, 3);,使得3D矢量,3深,只要适合于RGB图像

+0

我想将黑色像素转换为我自己的颜色,它是[R G B] = [129 52 168] – ffttyy

0

你可能想使用ind2rgb该转换索引(索引图像)的二维矩阵根据一个特定的颜色表

rgb是三个值(在范围[0..1]),表示新的颜色要分配到针对BWfalse然后像素的RGB图像

RGB = ind2rgb(BW, [ r, g, b; 1 1 1]); 

将全部黑色转换为[r,g,b],并将true像素保留为白色。


这里有一个例子:

BW = rand(10) < .5; 
RGB = ind2rgb(BW, [100/255 10/255 50/255; 1 1 1]); 
figure; 
imshow(RGB); 

而且结果应该是(高达BW随机性):
enter image description here

+0

嗨,当我运行你的代码时,它给了我一个白色的图像。 – ffttyy

+0

I = imread('1.jpg'); Ig = rgb2gray(I); BW = im2bw(1g,85/255); RGB = ind2rgb(uint8(BW)+ 1,[100,10,50; 111]); imshow(RGB); – ffttyy

+0

@sigara'r'' g'和'b'的值应该在** [0..1]范围内为** double **,在范围为[[0..255]的范围内为** not ** uint8) '!尝试颜色表'[100/255 10/255 50/255; 1 1 1]' – Shai

0

也许这FEX代码可能会帮助 - Color brewer。根据您在彩色啤酒机网页中选择的颜色,该功能将在MATLAB中显示。您所要做的就是使用这些数字来表示单个像素。

相关问题