MATLAB Answers

Getting RGB values out of an image into a matrix where I can retrieve specific elements

33 views (last 30 days)
Hello, I have tried many ways to find the RGB values from an image and put them into a matrix to retrieve it.
============
I = imread('yellowdot.jpg');
imshow(I)
A = imread('yellowdot.jpg');
Red = A(:,:,1);
Red(250,190)
===========
This code grabs the image and displays the picture and then saves the red values into the matrix "Red". When I retrieve the value no matter the x,y values i put into that last line it outputs "120". When I look into the saved matrix at (250,190) from accessing it from that right hand menu of MatLab it read "254" for that same value which is what it should be.
It's saved as "288 X 384 uint"
I dont really know what uint means but that might be why its having a hard time reading it.
Any help is much appreciated, I'm new to matLab so keeping it simple would be great :)
Zach

Accepted Answer

KALYAN ACHARJYA
KALYAN ACHARJYA on 24 Feb 2021
Edited: KALYAN ACHARJYA on 24 Feb 2021
I = imread('yellowdot.jpg');
imshow(I)
A = imread('yellowdot.jpg');
Red = A(:,:,1);
Till here you are doing it correctly.
Here "Red" is a red plane of the A rgb Image, its a 2D array with datatype uint8 (Unsigned interger 8 Bits). When the data type with uint8, its have maximum value 2^8=256, if Pixels considertion satrt from 0, hence maximum pixel value is 255 in any plane for uint8 data type.
If you check the details of A, it may be shown as
A>> "288 X 384X3 uint8" for 3 channels (3D Array), once the extraction of first planes from the 3rd dimentions, it represents the red plane. Hence it may shows
Red>>"288 X 384 uint8"
2nd Section:
"When I retrieve the value no matter the x,y values i put into that last line it outputs "120"
Red(250,190) represent the pixel value/Matrix value at the incices rows 250 and column 190. May be the given image have same color irrespective of any indices location, please do confirm?
More: If you wish to check the pixel value in differrent positions of the image, you can use the following code (by moving the Mouse cursor)
A = imread('yellowdot.jpg');
Red = A(:,:,1);
imshow(Red)
impixelinfo;
:)
  4 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by