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

18 views (last 30 days)
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.

Accepted Answer

Image Analyst
Image Analyst on 1 Dec 2012
Edited: Image Analyst on 1 Dec 2012
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);
  2 Comments
BHANU SRINIVASA
BHANU SRINIVASA on 1 Feb 2020
hey ,
how can we display a [mxnx3] matrix as an image
i have the matrix and im not able to display the image
Image Analyst
Image Analyst on 1 Feb 2020
Why not? imshow() should work
imshow(yourImage);
yourImage should be either:
  1. a uint8 image with integer values in the range 0-255
  2. a uint16 image with integer values in the range 0-65535
  3. a double image with double values in the range 0-1
If you have anything else, like an RGB image with double values in the range 0-255, you'll have to cast it to one of the above types with functions like mat2gray(), rescale(), im2double(), im2uint8, etc. For examples:
rgbImage = uint8(rgbImage);
rgbImage = mat2gray(rgbImage);
rgbImage = uint8(rescale(rgbImage, 0, 255));

Sign in to comment.

More Answers (1)

Bloti Teh
Bloti Teh on 24 Nov 2018
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);

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!