# map two RGB images in Matlab

I wonder is there any algorithm or method that I can map two RGB images together in Matlab. I mean assume I have following images

Is there any way I find what number I should multiply each channel of one them to get the other one, or any other method.

I have tried something like: looking at destination image and see what color is dominating then adjust the other image by multiplying by different value using brute force method but that is very inefficient and tedious.

• Once I encountered similar problem tackled with Python. Approach is very simple and somewhat similar to what you described. Is there better one? You can try with histograms for each of the channels.
– jojek
Aug 27 '14 at 8:35
• Can you elaborate by saying try for histogram of different channel, assume I have a histogram of different channel for both images what should I do with them? Aug 27 '14 at 8:39
• Can you elaborate on what you mean by "map two RGB images together"? Aug 28 '14 at 12:48
• Yes. I mean assume I am given one of those above images. How to change value of different RGB channel to get the other image? Aug 29 '14 at 9:10

It is easier to do this in HSV color space than RGB color space.
Assume the first image(the pinky one) is imported into matlab workplace as variable A,and the second(the yellowish one) as variable B.
First, I removed the white margin of both A and B with a same Rect:

Rect=[82.51 32.51 511.98 509.98]; % I found this with [~,Rect]=imcrop(A);
A_c=imcrop(A,Rect);
B_c=imcrop(B,Rect);


I am going to find a simple way to transform image A_c to B_c in HSV color space;

A_c_hsv=rgb2hsv(A_c);
B_c_hsv=rgb2hsv(B_c);


Read the wikipedia page of HSV.. you will find that most different parts between the two images must be in the Hue parts,i.e, between A_c_hsv(:,:,1) & B_c_hsv(:,:,1) ;

And the average difference between their hues is:

ave_dif_in_hue=mean(mean(B_c_hsv(:,:,1)-A_c_hsv(:,:,1)));


I just used the hue parts in my transform:

A_c_hsv_transformed=A_c_hsv; % make a copy of A_c_hsv
A_c_hsv_transformed(:,:,1)=A_c_hsv_transformed(:,:,1)+ave_dif_in_hue; % change the hue parts only


let's check our transform:

figure;
subplot(1,3,1);imshow(A_c);title('original A_c');
subplot(1,3,2);imshow(B_c);title('original B_c');
subplot(1,3,3);imshow(hsv2rgb(A_c_hsv_transformed));title('transformed from A_c');


here is the result:

you can optimize the transform further, with dealing with the other two channel in HSV color space..
Or.Maybe something more needed.