3

I need to write a function which will match the histogram of image2 to the image that will be remapped, let's call it image1. But I am not allowed to use histeq. Could you please help me with the code?

ps: Also I am wondering how would I do that operation if I were allowed to use histeq? What should I do after extracting red-green and blue channels? (I could not use histeq(R2,R1)?)

image1 = imread('color1.jpeg');
image2 = imread('color2.jpeg');

R1 = image1(:, :, 1);
G1 = image1(:, :, 2);
B1 = image1(:, :, 3);

R2 = image2(:, :, 1);
G2 = image2(:, :, 2);
B2 = image2(:, :, 3); 

Regards, Amadeus

Ahmad Azwar Anas
  • 1,289
  • 13
  • 22
Xentius
  • 459
  • 1
  • 10
  • 21

2 Answers2

0

I don't think the question is specific enough. One way to solve this is to convert the three channels to a grayscale image (rgb2gray), compute the two histograms (hist) and then find a desired mapping between the histograms and apply it to each channel of the original image.

The conversion to grayscale is not necessary, you can perform this algorithm on each channel and then join the channels together later.

Check this question, which uses histq.

Community
  • 1
  • 1
BorisM
  • 103
  • 5
0

Histogram Matching algorithm consist of 3 stage: 1-compute Normalize CDF of first image(T(r)). 2-compute Normalize CDF of second image(G(z)). 3-calculate G^-1(T(r)) and transform intensity value of first image to desired one.

Ehsan
  • 144
  • 3