How to generate Reddish, Greenish, Blueish, and whiteish images using color images. I'm using this function. If its wrong please change it.
2 views (last 30 days)
Show older comments
a=imread('fruit.png');
b=a;
a(:,:,2)=0;
a(:,:,3)=0;
subplot(2,2,1)
imshow(a)
1 Comment
DGM
on 9 Dec 2021
Does the code do what you want it to do?
That's certainly one way to create a "reddish" version of an image, but I can imagine many other ways that would produce different "reddish" images. It all depends what you want.
Answers (1)
DGM
on 9 Dec 2021
Edited: DGM
on 22 Apr 2022
There might be many ways to make a "reddish" version of an image. Consider the examples:
% i'm doing this in double for simplicity.
A = im2double(imread('peppers.png'));
% equivalent to 'multiply' (same as what you're doing)
B = A.*permute([1 0 0],[1 3 2]);
imshow(B)
% equivalent to 'screen'
C = 1-((1-A).*(1-permute([1 0 0],[1 3 2])));
figure; imshow(C)
% simple weighted opacity blend
kalph = 0.5;
D = kalph.*A + (1-kalph).*permute([1 0 0],[1 3 2]);
figure; imshow(D)
% simple hue substitution
E = rgb2hsv(A);
E(:,:,1) = 0;
E = hsv2rgb(E);
imshow(E)
% combine luma with red overlay
F = repmat(rgb2gray(A),[1 1 3]).*permute([1 0 0],[1 3 2]);
imshow(F)
These examples are simplified and use implicit array expansion (requires R2016b or newer). To change the color to green or blue (or any other color), simply change the [1 0 0] color tuple to something else. In the case of the hue substitution example, use 0.33 for green or 0.67 for blue.
This is a related question about creating a colorized version of an image:
3 Comments
DGM
on 9 Dec 2021
I don't know what "whiteish" would mean in the case of 'multiply' or 'hue' blending. You never really clarified what you were after.
A = im2double(imread('peppers.png'));
% simple weighted opacity blend
kalph = 0.5;
D = kalph.*A + (1-kalph).*permute([1 1 1],[1 3 2]);
figure; imshow(D)
% simple saturation swap
% hsv is pretty terrible for S adjustments
E = rgb2hsv(A);
E(:,:,2) = 0;
E = hsv2rgb(E);
imshow(E)
% combine luma with white overlay
F = repmat(rgb2gray(A),[1 1 3]).*permute([1 0 0],[1 3 2]);
% which simplifies in this case to:
F = repmat(rgb2gray(A),[1 1 3]);
imshow(F)
See Also
Categories
Find more on Red in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!