2013-10-06 108 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 .. –