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

Thread Subject:
Converting a jpg image (RGB) into a 2-d array of numbers (2D)

Subject: Converting a jpg image (RGB) into a 2-d array of numbers (2D)

From: Terence Britton

Date: 4 May, 2011 14:24:04

Message: 1 of 3

I want to read in an image (a .jpg image) into MATLAB, but using the

Image = imread('image.jpg');

function converts the image into a 3-d or maybe 5-d array i.e. x,y,RGB or x,y,R,G,B. What I want is to be able to read the image into MATLAB as a 2-d array of numbers, so instead of each pixel having 3 numbers to define it's colour (i.e. R G B) it would have just one number to define colour. Then I want to use the

imagesc(Image);

function to view the 2-d array graphically.

Any help with this would be much appreciated.

Thanks,

Terry.

Subject: Converting a jpg image (RGB) into a 2-d array of numbers (2D)

From: Steven_Lord

Date: 4 May, 2011 14:35:27

Message: 2 of 3



"Terence Britton" <terence.britton@student.manchester.ac.uk> wrote in
message news:iprni4$jui$1@fred.mathworks.com...
> I want to read in an image (a .jpg image) into MATLAB, but using the
>
> Image = imread('image.jpg');
>
> function converts the image into a 3-d or maybe 5-d array i.e. x,y,RGB or
> x,y,R,G,B. What I want is to be able to read the image into MATLAB as a
> 2-d array of numbers, so instead of each pixel having 3 numbers to define
> it's colour (i.e. R G B) it would have just one number to define colour.
> Then I want to use the

Use RGB2IND.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Converting a jpg image (RGB) into a 2-d array of numbers (2D)

From: ImageAnalyst

Date: 4 May, 2011 16:55:28

Message: 3 of 3

Or use rgb2gray(), or do this:

% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);

By the way, it's a 3D array, not a 5D array - you only have 3 index
positions in the array, not 5.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us