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

enter image description here

enter image description here

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.

  • $\begingroup$ 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. $\endgroup$
    – jojeck
    Aug 27, 2014 at 8:35
  • $\begingroup$ 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? $\endgroup$
    – stack
    Aug 27, 2014 at 8:39
  • 1
    $\begingroup$ Can you elaborate on what you mean by "map two RGB images together"? $\endgroup$
    – PAK-9
    Aug 28, 2014 at 12:48
  • $\begingroup$ 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? $\endgroup$
    – stack
    Aug 29, 2014 at 9:10

1 Answer 1


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);

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


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:


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:

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:
enter image description here
you can optimize the transform further, with dealing with the other two channel in HSV color space..
Or.Maybe something more needed.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.