how to make yellowish image

7 views (last 30 days)
Joseph on 14 Dec 2021
Edited: DGM on 22 Apr 2022
A = im2double(imread('fruit.png'));
B = 1-((1-A).*(1-permute([0 0 1],[1 3 2])));
this is the code to make the blueish image. I would like to change this image into yellowish image. How can I do that?

Answers (2)

Image Analyst
Image Analyst on 14 Dec 2021
Try this:
rgbImage = imread('peppers.png');
[rows, columns, numberOfColorChannels] = size(rgbImage);
subplot(2, 1, 1);
% Go to HSV color space so we can change hue.
hsvImage = rgb2hsv(rgbImage);
[hImage, sImage, vImage] = imsplit(hsvImage);
% Make the hue of every pixel yellow.
hImage = 0.165 * ones(rows, columns);
hsvImage = cat(3, hImage, sImage, vImage);
% Convert back to RGB space.
rgbImage2 = hsv2rgb(hsvImage);
subplot(2, 1, 2);

DGM on 22 Apr 2022
Edited: DGM on 22 Apr 2022
What's being performed here is a 'screen' type blend between the image and a color overlay. I'm sure there's an unspoken problem here that's caused by a misunderstanding of what should be expected of this blend operation. Let's repeat the original:
% read the image
A = imread('peppers.png');
% do a simple screen blend with a given tuple
A = im2double(A); % image is unit-scale
B = 1-((1-A).*(1-permute([0 0 1],[1 3 2])));
That works well enough, so why can't we just change [0 0 1] with [1 1 0]?
% read the image
A = imread('peppers.png');
% do a simple screen blend with a given tuple
A = im2double(A); % image is unit-scale
B = 1-((1-A).*(1-permute([1 1 0],[1 3 2])));
This should be expected. A 'screen' operation is the complement of multiplication; it strictly lightens the background. The contour map of the result looks like this:
Notice that whenever either image is maximized, the result cannot be influenced by the other image. In the case of a blue foreground, the entire blue channel of the result is pegged at 1. This doesn't really swamp the image for two reasons: 1) the perceived brightness of blue is low, and 2) there is very little object content in the blue channel; it's mostly in red and green. When the foreground is yellow, the R and G channels get slammed to a solid 1. Most of the original object content is lost.
You can moderate the effect by toning down the foreground:
% read the image
A = imread('peppers.png');
% do a simple screen blend with a given tuple
A = im2double(A); % image is unit-scale
B = 1-((1-A).*(1-permute([1 1 0]*0.4,[1 3 2])));
Of course, the question is about making a yellow image. Is a 'screen' blend the best or only way? No, but what's best depends on what the intent is. Image Analyst's example of HSV colorization is one way, and similar can be done with other colorspace conversion tools. I'm going to use MIMT tools to show a few other options.
The same sort of blending approach can be done using any number of blend operations. It all depends on what "yellowish" means and what the object polarity of the image is.
% read the image
A = imread('peppers.png');
% create a solid color field (this could also be any sort of gradient,etc)
cpict = colorpict(imsize(A,3),[255 255 0],'uint8');
% provide examples of various blends
C = imblend(cpict,A,0.5,'normal'); % normal at half-opacity
D = imblend(cpict,A,0.5,'screen'); % screen at half-opacity
E = imblend(cpict,A,1,'multiply');
F = imblend(cpict,A,1,'mean shadow');
G = imblend(cpict,A,1,'color'); % luma-corrected HSL
H = imblend(cpict,A,0.5,'color'); % at reduced opacity
normal at half opacity screen at half opacity
multiply meanshadow
HSL-Y color blend HSL-Y color blend at half opacity
Simple colorization can also be done directly. This performs colorization in HSL with some degree of luma compensation. It's not as flexible as a color or luma blending approach like the above examples, but it is simple to use and doesn't require the creation of a colored foreground image.
% do simple HSL colorization
I = gcolorize(A,[60 70 -10]);
There are other ways, such as shifting the color balance away from blue:
% change color balance
J = colorbalance(A,[0 0 -0.5; 0 0 -0.4; 0 0 -0.3],'nopreserve');
You might also be able to do something crazy by scaling and recentering the hue distribution:
This is a similar question about image colorization:


Community Treasure Hunt

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

Start Hunting!