0
votes

I want to draw a color image in MATLAB of size 200*200 pixel ,type RGB and a square size of Green color in the middle i-e 76 row and 125 column.

enter image description here

Then i want to draw 20*20 Pixels square of RED, Green, Blue and Black in the corner's of the same image. I don't know how to do or draw color boxes (RGB) in MATLAB.

enter image description here

I have done it in Binary as shown in the following Fig:enter image description here

1
label the regions in a 2D matrix and then use ind2rgb with a color map.Shai

1 Answers

3
votes

You need to define 3 components as you mentioned: R, G, B. Also if you want to work with color channels as integers 0..255, you need to convert the matrix type to integer:

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);

Hope it helps you to get the idea.