How can i get a RGB values from a picture?

278 visualizaciones (últimos 30 días)
caner kaya
caner kaya el 10 de Oct. de 2017
Comentada: DGM el 2 de Dic. de 2022
Hi,
My goal is to get the RGB values of the image taken with the webcam and I need the matlab code to accomplish this purpose. I am a new matlab user, please help me.
Best regards.

Respuesta aceptada

Walter Roberson
Walter Roberson el 10 de Oct. de 2017
Once you have done the snapshot(), then just index into the resulting array to get the RGB values. For example,
img(183, 17, :)
would extract the R, G, and B components (in that order) of row 183 column 17 of the image.
  13 comentarios
Image Analyst
Image Analyst el 27 de En. de 2021
Editada: Image Analyst el 27 de En. de 2021
What do you want represented along each axis? LIke R along , G along Y and B along Z?
Like this:
rgbImage = double(imread('peppers.png'));
[r, g, b] = imsplit(rgbImage);
xyz = [r(:), g(:), b(:)];
ptCloud = pointCloud(xyz);
pcshow(ptCloud)
Looks pretty much like what you get from colorcloud():
Walter Roberson
Walter Roberson el 28 de En. de 2021
Your color data can be either 2D or 3D
numFaces = 600;
[x,y,z] = sphere(numFaces);
xyz2d = [x(:), y(:), z(:)];
xyz3d = cat(3,x,y,z);
img = imresize(imread('flamingos.jpg'), [numFaces+1, numFaces+1]);
color_matrix_2d = reshape(img, [], 3);
color_matrix_3d = img;
pcshow(xyz2d, color_matrix_2d); title('data arranged as 2d')
pcshow(xyz3d, color_matrix_3d); title('data arranged as 3d')

Iniciar sesión para comentar.

Más respuestas (3)

Chad Greene
Chad Greene el 10 de Oct. de 2017
Hi Caner,
The imread function will read any image and give you the RGB values like this:
A = imread('myimage.jpg');
Then the red layer is the first slice of A, blue is the second slice, and green is the third:
R = A(:,:,1);
G = A(:,:,2);
B = A(:,:,3);
If you need the RGB values of a specific pixel, say, row 22, column 50, it would be:
[R(22,50) G(22,50) B(22,50)]
If you're not sure what the row and column numbers are of the pixel you want, display the image with the image function, then use ginput to click around and get the coordinates you want:
image(A)
[col,row] = ginput
  3 comentarios
Shri.s
Shri.s el 2 de Dic. de 2022
This solution does not shows the RGB values?
DGM
DGM el 2 de Dic. de 2022
This does show the RGB values at a specific pixel.
% an image
A = imread('peppers.png');
% split the channels
R = A(:,:,1);
G = A(:,:,2);
B = A(:,:,3);
% address each channel to find the color at (22,50)
[R(22,50) G(22,50) B(22,50)]
ans = 1×3
61 35 65
% of course, this is the same as
permute(A(22,50,:),[1 3 2])
ans = 1×3
61 35 65

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 11 de Oct. de 2017
To build on what the others said, you should look at impixelinfo() which is a function that puts a status bar on your figure that gives you the (x,y) location and RGB values as you mouse over the displayed image.
There is also a function called impixel() that gives you the RGB value but I never use it.
  6 comentarios
caner kaya
caner kaya el 11 de Oct. de 2017
I need to find R G B values between 0 and 255 for a picture for example if the picture pure red then R=255, G=0, B=0, I should get these values
caner kaya
caner kaya el 11 de Oct. de 2017
Editada: caner kaya el 11 de Oct. de 2017
I also have a problem, the RGB values I get are not affected by the environment. I mean I should get the * same* values even if I'm in the dark or the bright environment with the using the webcam

Iniciar sesión para comentar.


Bryan Benedict Ordas
Bryan Benedict Ordas el 19 de Dic. de 2019
Hello Guys!
I am also in need of help on getting the RGB values in a multiple images. I was able to know also that you can pick a certain coordinates using your mouse to select the pixel you wanted to obtain the RGB Values. What if I wanted to use this function for multiple pictures? is there a way on looping this activity? (selecting pixels and getting the RGB Values of Multiple Pictures).
My purpose was to gather data of a certain object for neural networks.
Thanks!!!
  2 comentarios
Bryan Benedict Ordas
Bryan Benedict Ordas el 19 de Dic. de 2019
I'm new on using Matlab so please be easy on me... hehe, thanks!
Image Analyst
Image Analyst el 19 de Dic. de 2019
See the FAQ for code samples on how to read in multiple images and get their RGB values.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by