2013-10-06 105 views
0

我想在200 * 200像素的MATLAB中绘制彩色图像,在中间的i-e 76行和125列中输入RGB和绿色的正方形大小。使用Matlab生成彩色图像

enter image description here

然后我想提请红色,绿色,蓝色和黑色的20 * 20像素的正方形在同一图像的边角。我不知道如何在MATLAB中执行或绘制颜色框(RGB)。

enter image description here

我在二进制完成它,如下面的图:enter image description here

+0

在二维矩阵中标记区域,然后使用具有颜色映射的“ind2rgb”。 – Shai

回答

3

您需要定义3个组成部分,正如你所说:R,G,B。另外,如果你要使用颜色通道作为整数0..255,您需要将矩阵式转换为整数

img = ones(256,256,3) * 255; % 3 channels: R G B 
img = uint8(img);    % we are using integers 0 .. 255 
% top left square: 
img(1:20, 1:20, 1) = 255;  % set R component to maximum value 
img(1:20, 1:20, [2 3]) = 0;  % clear G and B components 
% top right square: 
img(1:20, 237:256, [1 3]) = 0; % clear R and B components 
img(1:20, 237:256, 2) = 255; % set G component to its maximum 
% bottom left square: 
img(237:256, 1:20, [1 2]) = 0; 
img(237:256, 1:20, 3) = 255; 
% bottom right square: 
img(237:256, 237:256, [1 2 3]) = 0; 

imshow(img); 

希望它可以帮助你明白我的意思。

+0

谢谢。我想知道什么“关键词”使用! –

+1

那么,ones(m,n,p)创建一个满足1的矩阵,其大小为m x n x p。你也可以使用零(),它也是一样的,但是用0填充矩阵。 – Ali

+0

Thank You Brother .. –