How do I add "color" to an image?

5 views (last 30 days)
Roger Breton
Roger Breton on 2 May 2022
Edited: DGM on 3 May 2022
I'm looking for ways to better understand color mixing theory. Suppose I start of an RGB image? Suppose I want to color the whole image using a certain "color"? I don't suppose there are already existing functions within the Image Toolbox that already to something similar? I looked at the imfliter() function but the documentation leads me to believe I better look elsewhere...
"Before" is the original RGB image. "After" is the image onto which I added "100 Yellow" in Photoshop... Before I try to reverse-engineer (humbly) Adobe's color mixing process manually, I'm interested whether there are already ready-made stuff I could use, or do I have to start from scratch?

Answers (1)

DGM
DGM on 3 May 2022
Edited: DGM on 3 May 2022
There really isn't anything in base MATLAB or IPT for doing color adjustment.
I'm not familiar with Photoshop, and don't have it myself, so figuring out what the tools do (even just subjective analysis) is difficult.
MIMT has a number of color adjustment tools that may be of use. Of particular interest may be tools such as colorbalance() (which replicates GIMP's color balance tool) and tonecmyk() which replicates the G'MIC CMYK tone adjustment tool.
If you give me a bit, I might try making an example.
EDIT:.
Well that was anticlimactic. It's just an opacity blend.
inpict = imread('greenbird.png');
refpict = imread('greenbirdref.png');
cpict = colorpict(size(inpict),[255 255 0],'uint8');
outpict = imblend(cpict,inpict,0.34,'normal'); % selected to minimize error
% show the error
imshow(imabsdiff(refpict,outpict))
immse(refpict(100:end,:,:),outpict(100:end,:,:))
ans =
23.1169
It's not as convenient, but this could be done without MIMT fairly easily.
inpict = imread('greenbird.png');
sz = size(inpict);
alpha = 0.34;
cpict = repmat(permute([255 255 0],[1 3 2]),sz(1:2));
outpict = uint8(cpict.*alpha + double(inpict).*(1-alpha));
I had assumed that you were using some sort of color/tone adjustment tool. If you were instead trying to replicate the effect of layered composition (creating a yellow layer and changing opacity), then that's what imblend() does. It should support all options that PS has available (as far as I know).
That said, I assumed PS did its composting in linear RGB, but either it doesn't in this case, or you were indeed using some adjustment tool instead of doing layered composition. For what it's worth, imblend() can optionally do blending and/or compositing in either sRGB or linear RGB.

Categories

Find more on Images in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!