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

4 ビュー (過去 30 日間)
Walter Roberta
Walter Roberta 2012 年 12 月 1 日
コメント済み: Image Analyst 2020 年 2 月 1 日
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.

採用された回答

Image Analyst
Image Analyst 2012 年 12 月 1 日
編集済み: Image Analyst 2012 年 12 月 1 日
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 件のコメント
BHANU SRINIVASA
BHANU SRINIVASA 2020 年 2 月 1 日
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 2020 年 2 月 1 日
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));

サインインしてコメントする。

その他の回答 (1 件)

Bloti Teh
Bloti Teh 2018 年 11 月 24 日
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);
  1 件のコメント
Image Analyst
Image Analyst 2018 年 11 月 24 日
Not sure why you're reposting my 6 years old answer.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by