how to change pixel with the same RGB values
Show older comments
I'm writing a white balance algorithm in matlab. I have to change the RGB values of a pixel in (1,1,1) if it has the same RGB values as my RGB vector. I copied the RGB values of my vector in a matrix with the same size like my picture( x * y * 3(RGB)), because i think it's easier to compare. Now i compare the values with this statement:
input = picture;
tmp = ... % RGB value matrix
input( input(1:end,1:end,1) == tmp(1:end,1:end,1) & input(1:end,1:end,2) == tmp(1:end,1:end,2) & input(1:end,1:end,3) == tmp(1:end,1:end,3) ) = 1;
I think my comparison is wrong, because it's just comparing the Red value with the Red value, the green with the green.... and doesn't test R = R and G = G and B = B then --> R = 1, G = 1, B = 1
Sry for my bad english but some help would be awesome!
Accepted Answer
More Answers (1)
Jan
on 25 Mar 2013
Currently your code is equivalent to:
in = picture; % avoid to use builtin function name "input" as variable
in(in == tmp) = 1;
When tmp is a [1x3] RGB vector, this would be the code:
in(in(:, :, 1) = tmp(1) & in(:, :, 2) = tmp(2) & in(:, :, 3) = tmp(3)) = 1;
Now all pixels of in, whose color equals the value of tmp, gets white. Why do yout think, that this is not the wanted result?
5 Comments
Image Analyst
on 25 Mar 2013
Then he's doing color replacement, not "white balancing" by the usual definition: White Balancing. Further explanation from John could help us figure out what he really wants to do.
Jan
on 25 Mar 2013
Exactly, Image Analyst. My code is only a simplified version of the original code.
John
on 25 Mar 2013
Image Analyst
on 25 Mar 2013
You can use code like this:
originalMinValue = 0
originalMaxValue = % Whatever pixel value you clicked on.
originalRange = originalMaxValue - originalMinValue;
% Get a double image in the range 0 to +1
desiredMin = 0;
desiredMax = 1.0;
desiredRange = desiredMax - desiredMin;
dblImage = desiredRange * (double(grayImage) - originalMinValue) / originalRange + desiredMin;
Do that for every color channel image. So grayImage would be redChannel, greenChannel, and blueChannel, each in turn.
John
on 25 Mar 2013
Categories
Find more on Display 2-D Images in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!