![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/529634/image.png)
Getting RGB values out of an image into a matrix where I can retrieve specific elements
조회 수: 35 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
KALYAN ACHARJYA
2021년 2월 24일
편집: KALYAN ACHARJYA
2021년 2월 24일
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?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/529634/image.png)
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Import, Export, and Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!