how to enhance blue color alone of an image?

15 views (last 30 days)
how to enhance blue color alone of an image?
  2 Comments
Jan
Jan on 13 Sep 2012
What exactly does "enhance" mean?
Dorothy Lopez
Dorothy Lopez on 2 Aug 2016
I think he want to tone pictures to blue color images, adding more blue hues on the photos. From my knowledge, many tools can do it, famous one are Gimp, On1, PS, LR.....

Sign in to comment.

Accepted Answer

David Lieberman
David Lieberman on 13 Sep 2012
This question is vague, but I'll try to help. First off, don't just modify the blue sepearation. That will shift everything toward blue, including gray pixels, and I don't think that's your intent, so ignore Jan's suggestion above.
Color images are often rgb, that is img(:,:,1) is the red, img(:,:,2) is green, and img(:,:,3) is blue. By 'blue color alone', I imagine you are wanting to adjust pixels that are predominantly blue to become 'more so'.
Note: crudly, r+g+b = the gray component, cyan = g+b, magenta=r+b, and yellow=red+green
% get components r=img(:,:,1); g=img(:,:,2); b= img(:,:,3);
% When there is more blue than anything else, find out by how much extra_blue = max(b-max(r,g),0);
Now, you can try to add additional blueish component, as long as you stay in the valid range.
b_mod = min(b + k*extra_blue),1); % k is a scale of the amount of extra blue to add, say 0.1 for example
Alternatively, you can add the extra blue and scale down the non-blue components. Reduce r, g, and (b-extra_blue) by the exact same scale factor (say 0.9), that will maintain gray and all hue angles, then add a multiple of the excess blue (say 1.1) to the b channel.
There are much better ways, but then I'd have to ask you about hue angle, saturation, and it gets complicated quickly... I've said enough. I hope this helps.

More Answers (2)

Image Analyst
Image Analyst on 13 Sep 2012
Edited: Image Analyst on 13 Sep 2012
I think you'll find this demo illustrates it very well:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
format longg;
format compact;
fontSize = 20;
% Read in a standard MATLAB color demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'football.jpg';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows columns numberOfColorBands] = size(rgbImage);
% Display the original color image.
subplot(2, 2, 1);
imshow(rgbImage, []);
title('Original Color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Convert to hsv color space.
hsv = rgb2hsv(rgbImage);
% Display the color channels.
hueImage = hsv(:, :, 1);
saturationImage = hsv(:, :, 2);
valueImage = hsv(:, :, 3);
subplot(2, 2, 2);
imshow(hueImage, []);
title('Hue Channel', 'FontSize', fontSize);
subplot(2, 2, 3);
imshow(saturationImage, []);
title('Saturation Channel', 'FontSize', fontSize);
subplot(2, 2, 4);
imshow(valueImage, [])
title('Value Channel', 'FontSize', fontSize);
% Look at the histogram of the hue channel
% so we can see where the blue is
[pixelCounts values] = hist(hueImage, 500);
figure;
subplot(2, 2, 1);
bar(values, pixelCounts);
title('Histogram of Hue Channel', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Blue looks like it's in the 0.4 to 0.7 region.
% Amplify that by increasing saturation for those pixels.
% Find blue pixels. They have to have the right hue but not be too bright.
bluePixels = hueImage > 0.4 & hueImage < 0.7 & valueImage < 0.8;
subplot(2, 2, 2);
imshow(bluePixels);
title('Map of Blue Pixels', 'FontSize', fontSize);
% Multiply the saturation channel by 1.5 for those pixels.
saturationImage(bluePixels) = saturationImage(bluePixels) * 3.5;
subplot(2, 2, 3);
imshow(saturationImage);
title('New Saturation Channel', 'FontSize', fontSize);
% Combine back to form new hsv image
hsvImage = cat(3, hueImage, saturationImage, valueImage);
% Convert back to RGB color space.
rgbImage = hsv2rgb(hsvImage);
subplot(2, 2, 4);
imshow(rgbImage);
title('RGB Image with Enhanced Blue', 'FontSize', fontSize);
  6 Comments
PhD Problems
PhD Problems on 31 Jul 2019
Thank you, that makes sense, but in your code you relied on the above graph and histogram to choose the region of 0.4 to 0.7. I just dont understand how?
As I need to enhance the yellow colour in my sample and based on your profile avatar I can see that that if I want to target yellow, it will be around 0 degrees, right? But how does that transfer to the graph/histogram above?
Thanks
Image Analyst
Image Analyst on 1 Aug 2019
Well I knew that blue was in that range. Yellow is straight up, around 90 degrees. So you can choose a range of about 45 to 135 degrees or so. Divide by 360 to get values in the range 0-1.
men-woman-colors-chart.jpg

Sign in to comment.


Jan
Jan on 13 Sep 2012
RGB = rand(200, 100, 3);
Blue = RGB(:, :, 3);
enhancedBlue = max(Blue + 0.1, 1.0); % Or whatever
RGB(:, :, 3) = enhancedBlue;

Community Treasure Hunt

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

Start Hunting!