Image processing help. Regarding pixel values and not needing to click on diagram to select pixel.

2 visualizzazioni (ultimi 30 giorni)
From what I understand, matlab mostly requires us to click on an image and then it will display the resulting pixel RGB value. Is there a way to let the code run through, finding ALL pixel's individual values without having to click? I do not want to select because I want to iterate through the whole picture.
How do I use code to get just R,G and B respectively of a pixel? Like when a pixel is selected, what code will give only R portion of RGB. I wish to compile RGB together meaning adding R, G and B to get my resulting pixel value.
Please help. Thanks.

Risposta accettata

Image Analyst
Image Analyst il 26 Dic 2014
You can read in an image file with imread(). That will get you ALL the image pixel values without having to click on anything.
rgbImage = imread(fullFileName);
To split apart an RGB image into the individual color channels, you can do this:
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
To recombine them into an RGB image again, do this:
% Recombine separate color channels into a single, true color RGB image.
rgbImage = cat(3, redChannel, greenChannel, blueChannel);
  7 Commenti
Image Analyst
Image Analyst il 28 Dic 2014
Modificato: Image Analyst il 28 Dic 2014
They must be uint8. What does this reveal if you put it right before the second disp():
whos I
whos RED
whos GREEN
whos BLUE
whos total_value
whos array
Try casting to uint16 before summing.
total_Value = uint16(RED) + uint16(GREEN) + uint16(BLUE);
lim -
lim - il 29 Dic 2014
Oh it works now. The problem was that I did not cast it to uint16 before summing. Just adding the "total_Value = uint16(RED) + uint16(GREEN) + uint16(BLUE);" line and it works like I wanted. Thank you.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by