How to extract RGB values of each pixel from an image?

3 views (last 30 days)
I need to extract the RGB values of each pixel of a given image in a serial data format like R1:G1:B1, R2:G2:B2, R3:G3:B3... and so on.

Accepted Answer

Image Analyst
Image Analyst on 23 Nov 2017
Try this:
rgbImage = permute(rgbImage, [3,1,2])
serialValues = rgbImage(:)'
This will give you [r1,g1,b1, r2,g2,b2, r3,g3,b3, r4,g4,b4, ...] which is a row vector taken from the original RGB image in column major order.
  3 Comments
Walter Roberson
Walter Roberson on 24 Nov 2017
rgbImage = permute(rgbImage, [3,2,1]);
serialValues = rgbImage(:)';

Sign in to comment.

More Answers (2)

Adam
Adam on 22 Nov 2017
r = im(:,:,1);
g = im(:,:,2);
b = im(:,:,3);
assuming img is an RGB image of n*m*3 size, for any n, m

Image Analyst
Image Analyst on 22 Nov 2017
You can use impixel() to get the [r, g, b] values in a 1-by-3 array, if that's what you meant by "serial":
row = 5; % Whatever.
column = 10
rgbPixelValue = impixel(rgbImage, column, row)
Otherwise explain in detail, with an example, exactly what "serial data format" means to you.

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!