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

조회 수: 2 (최근 30일)
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.

채택된 답변

Image Analyst
Image Analyst 2014년 12월 26일
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
Image Analyst
Image Analyst 2014년 12월 28일
편집: Image Analyst 2014년 12월 28일
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 - 2014년 12월 29일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by