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

2 views (last 30 days)
Code using im functions is:
I1 = imread('image1.jpg'); I2 = imread('image2.png');
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
So can you please help me about replacing imhist function?

Answers (1)

Bhumi Shah
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.
I1 = imread(image1);
I1double = im2double(I1);
I2 = imread(image2);
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';
Refer to the following link for more information:

Products


Release

R2014b

Community Treasure Hunt

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

Start Hunting!