Intensity scaling in RGB image

19 views (last 30 days)
hamidreza mohafez
hamidreza mohafez on 2 Jul 2014
Edited: hamidreza mohafez on 4 Jul 2014
I'm going to compress the intensity scale of RGB image (unit8) to eliminate the extreme bright and extreme dark pixels through remapping the the unscaled intensity I, given by I=R+G+B, of range 0-765 to a narrower range 300-490. So, I think the following actions can be used:
  1. RGB--->Grayscale (calculating the Intensity)
  2. intensity adjustment (through imadjust)
  3. Gray---->RGB
as expalined above, I want to calculate the Intensity given by I=R+G+B; but I think the (rgb2gray) can not be used for the first action since it calculates the intensity by I=gray = 0.2989 * rgb(:,:,1) + 0.5870 * rgb(:,:,2) + 0.1140 * rgb(:,:,3); So, I really appreciate that guide me that my approach is correct or not? If it's wrong, please let me know the solution in Matlab.

Answers (1)

Image Analyst
Image Analyst on 2 Jul 2014
Why are you doing all that? Why can't you just do
RGBNew = double(rgbImage) / 765 * 190 + 300;
  11 Comments
Image Analyst
Image Analyst on 2 Jul 2014
Edited: Image Analyst on 2 Jul 2014
What I gave you didn't work because I thought that those were the gray values of the individual color channels, not the sum of all 3 color channels. Rather than give me some values that might only work for some specific image, why don't you give the formula that they recommend you use for images in general? For example some people use normalized RGB where they extract the individual color channels and then divide by the sum of (R+G+B).
redChannel = double(rgbImage(:, :, 1));
greenChannel = double(rgbImage(:, :, 2));
blueChannel = double(rgbImage(:, :, 3));
% Display the individual color channels.
subplot(2, 4, 2);
imshow(redChannel, []);
title('Red Channel of Original Image', 'FontSize', fontSize);
subplot(2, 4, 3);
imshow(greenChannel, []);
title('Green Channel of Original Image', 'FontSize', fontSize);
subplot(2, 4, 4);
imshow(blueChannel, []);
title('Blue Channel of Original Image', 'FontSize', fontSize);
magnitudeImage = sqrt(redChannel .^2 + greenChannel .^2 + blueChannel.^2);
subplot(2, 4, 5);
imshow(magnitudeImage, []);
title('Magnitude Image');
normRed = redChannel ./ magnitudeImage;
normGreen = greenChannel ./ magnitudeImage;
normBlue = blueChannel ./ magnitudeImage;
subplot(2, 4, 6);
imshow(normRed, []);
title('Normalized Red Image');
subplot(2, 4, 7);
imshow(normGreen, []);
title('Normalized Green Image');
subplot(2, 4, 8);
imshow(normBlue, []);
title('Normalized Blue Image');
hamidreza mohafez
hamidreza mohafez on 3 Jul 2014
Edited: hamidreza mohafez on 4 Jul 2014
Dear Sir, As I mentioned, I am going to implement a tested method for image segmentation though bin clustering of 3D RGB histogram which is proposed by Berris (attached pdf file). In the article (as I highlighted) they did not mention that how they come up with the values (300,490) and just said that "to eliminate the extreme white and extreme dark pixels" the intensity scale was compressed by remapping the unscaled intensity I=R+G+B which ranges 0-765 to a narrower range 300-490. it is just mentioned that the chosen values (300,490) were found empirically without more details. Anyway, as you mentioned the values will be different for different database( images) and as a result I should find the values for my images. Regarding your last proposed commands, would you please help me to find the answer of following questions: 1. you mentioned that one way is to divide normalized RGB by sum of(R+G+B);however why did you divide the normalized RGB by magnitude which is (magnitudeImage = sqrt(redChannel .^2 + greenChannel .^2 + blueChannel.^2);) and not by sum of (R+G+B)?
2.Again the color component of RGB (red,green, and blue plane) were normalized individually and not as whole. So, how we can make sure that the I=R+G+B was scaled? 3. at the end the of above commnands, should we use 'rgb_scaled=cat(3,normRed,normGreen,normBlue) to form the scaled RGB image? 4. If you have any idea to choose the values (same as done by Berris 300-490) for my images (e.g. dz1.jpg)systematically? 5. finally, is there any way to compress the intensity scale of the RGB image (as I asked) as a whole and not through individual normalization of color components? I am looking forward hearing from you soon Sir. Bests

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!