How can i change the color of an image with another image?

1 view (last 30 days)
I have two images. The first is the image that i want to show, and the other is the backgroud. I want to project an image that an operation with the output image and the backgroud image makes the input image. Any idea? Thanks!
  6 Comments
David Young
David Young on 1 Dec 2014
Thank you for posting the images.
Sorry, but no, I still don't understand "project" or "combination", and I can't figure out what the output image should look like.
Maybe I'm failing to grasp something obvious. Does anyone else have more insight into this problem?

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 1 Dec 2014
If you want to do histogram matching, this is the best algorithm out there that I know of: http://www.eyemaginary.com/Portfolio/ColorHistogramWarp.html
Otherwise you may simply want to convert to hsv color space and just replace the h and s channels
hsv1 = rgb2hsv(rggImage1);
h1 = hsv1(:,:,1);
s1 = hsv1(:,:,2);
v1 = hsv1(:,:,3);
hsv2 = rgb2hsv(rggImage2);
h2 = hsv2(:,:,1);
s2 = hsv2(:,:,2);
v2 = hsv2(:,:,3);
newHSVImage = cat(3, h2, s2, v1);
newRGB = uint8(hsv2rgb(newHSVImage));
  3 Comments
David Young
David Young on 1 Dec 2014
Wow! I'm impressed that you understood that this is about histogram matching!
Thorsten
Thorsten on 1 Dec 2014
Edited: Thorsten on 1 Dec 2014
In the example above rggImage1 is the gray background. You need not to transform it to HSV but can use it directly as the V.
First ensure that both images have the same size
I = imread('colorful-triangles.jpg');
B = imread('graybackground.jpg');
B = imresize(B, size(I,1)/size(B,1)); B = B(:, 1:size(I, 2));
Then create new RGB image by replacing the V plane of the color image with the gray scale image, as Image Analyst suggested
hsv = rgb2hsv(I);
hsv(:,:,3) = B;
newRGB = uint8(hsv2rgb(hsv));
An alternative approach would be to multiply the images
newRGBalt = im2double(I)*repmat(im2double(B), [1 1 3]);

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!