MATLAB: How to generate the following color Image: Yellow, Green, and Red

color patternimage matrixImage Processing Toolbox

Please how to generate the following color image:Yellow, Green,and Red by defining image Matrix And Showing me the colors of the image on the screen. The outer image size is 200 x 200 pixels, center image is 150 x 150 pixels, and the innermost image size is 100 x 100 pixels.

Best Answer

Try this:
redChannel = 255 * ones(200, 200, 'uint8');
greenChannel = 255 * ones(200, 200, 'uint8');
blueChannel = 255 * zeros(200, 200, 'uint8');
% Blacken the inner most 150x150 for red
% so that it will be only Green.
redChannel(25:174, 25:174) = 0;
% Set the inner most 100x100 for red and
% Clears the inner most 100 x 100 for green
% so that it will be only red.
redChannel(50:149, 50:149) = 255;
greenChannel(50:149, 50:149) = 0;
rgbImage = cat(3, redChannel, greenChannel, blueChannel);
imshow(rgbImage);