Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

How to generate image matrix Red Green Blue Yellow Green

Asked by Jjet Jumbo on 19 Nov 2012

Generate the following image by defining image matrix:

Red Green Blue Yellow Green.

B(1:100,1:100,1:100,1:00,1:3)=0;
 imshow (B)
B(1:50,1:50,1) =1;
B(51:100,51:100,2)=1;
imshow(B)

I am trying to get a 3x3 with the specified colors; Red Green Blue Yellow Green. It's not working, it gives error.

0 Comments

Jjet Jumbo

Products

No products are associated with this question.

2 Answers

Answer by Walter Roberson on 19 Nov 2012

B(1:100,1:100,1:100,1:00,1:3)=0 tries to define a 5 dimensional array in which the fourth dimension is empty. 1:00 is empty. Perhaps you meant 1:100 .

RGB matrices are 3 dimensional.

You may wish to use zeros() to initialize the matrix.

0 Comments

Walter Roberson
Answer by Image Analyst on 19 Nov 2012

Is this what you're looking for:

redChannel = zeros(100, 100, 'uint8');
greenChannel = zeros(100, 100, 'uint8');
blueChannel = zeros(100, 100, 'uint8');
redChannel(1:50,:) = 255;
greenChannel(:, 1:50) = 255;
blueChannel(51:100, 51:100) = 255;
coloredImage = cat(3, redChannel, greenChannel, blueChannel);
imshow(coloredImage)

6 Comments

Walter Roberson on 20 Nov 2012

If you are going to use 0, 1, 2, then use a 2 dimensional matrix rather than a 3D matrix, and fill each location with a number indicating the color number that should go there (like paint-by-numbers.) Then after imshow(), use colormap() to put in place a colormap you created that maps between the color number and the RGB value that should be associated with that color.

Cesar on 2 Feb 2013

Can you please complete it to create the 3 X 3 image:

Red		Yellow
	Green	
Green		Blue
Image Analyst on 2 Feb 2013

Cesar, you can see my solution and the modifications to it to do what you want should be straightforward. Just change the row and column ranges.

Image Analyst

Contact us