Image Histogram Matching Using CDF

2 views (last 30 days)
YongHyun
YongHyun on 17 May 2016
Commented: Tejas on 19 May 2016
I wrote a code for image histogram matching using CDF (cumulative distribution function). However, the CDF of result image is differ from the reference image. Please, check the codes and inform me the problems. Note that image is not a 8 bit and has decimal places. Thanks.
reference % reference image
input % input image
re_k = unique(reference(:));
in_k = unique(input(:));
[x,y] = size(input);
[re_counts, re_bins] = hist(reference(:),re_k);
re_cdf = cumsum(re_counts) / sum(re_counts);
[in_counts, in_bins] = hist(input(:),in_k);
in_cdf = cumsum(in_counts) / sum(in_counts);
LU = interp1(re_cdf,re_bins,in_cdf);
test = interp1(re_bins, LU, in(:));
result = reshape(test,x,y);
  1 Comment
Tejas
Tejas on 19 May 2016
Hello YongHyun ,
There is a MATLAB function called ' imhistmatch ' which adjusts the histogram of an image to match N-bin histogram of a reference image. You can try to use this.
-Tejas

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!