# Can anyone please help me about histogram matching without using inbuilt functions like imhist? Because my system shows error for 'im' built-in functions.

19 views (last 30 days)
Awani on 17 Nov 2014
Answered: Bhumi Shah on 11 Feb 2020
Code using im functions is:
image1 = im2double(I1); % convert images to type double (range from from 0 to 1 instead of from 0 to 255) image2 = im2double(I2);
% Calculate the Normalized Histogram of Image 1 and Image 2 hn1 = imhist(image1)./numel(image1); hn2 = imhist(image2)./numel(image2);
subplot(2,2,1);plot(hn1); subplot(2,2,2);plot(hn2);
f = sum((hn1 - hn2).^2) % Calculate the histogram error

#### 1 Comment

Muhammad Barznji on 25 Dec 2019

Bhumi Shah on 11 Feb 2020
You can use histogram function with NumBins and BinLimits NV pair in place of imhist. Following steps might be helpful.
I1double = im2double(I1);
I2double = im2double(I2);
H1 = histogram(I1double, 'NumBins', 256, 'BinLimits', [0 1]);
H2 = histogram(I2double, 'NumBins', 256, 'BinLimits', [0 1]);
Count1 = H1.BinCounts';
Count2 = H2.BinCounts';