自分でヒストグラム均等化をコーディングしようとしていますが、結果は matlab の組み込み関数とは異なりhisteq
ます。なぜこれが起こっているのですか?コードと結果を添付しました。
%% Histogram Equalization
close all
clear all
%%
I = imread('Iris_virginica.jpg');
grayI = rgb2gray(I);
[m,n] = size(grayI);
L = 256;
[counts,x] = imhist(grayI);
myCDF = cumsum(counts)/(m*n);
equalizedI = (L-1)*myCDF(double(grayI)+1);
equalizedI = uint8(equalizedI);
histMyOut = imhist(equalizedI);
builtInEqualizationI = histeq(grayI);
histBuiltInEqu = imhist(builtInEqualizationI);
%%
figure
subplot(1,3,1), stem(x,counts), title('Histogram');
subplot(1,3,2), stem(x,myCDF), title('Commulative Distribution');
subplot(1,3,3), stem(x,imhist(equalizedI)), title('Equalized');
figure
subplot(1,3,1),imshow(grayI), title('Input image');
subplot(1,3,2), imshow(equalizedI), title('Equalized image (mine)');
subplot(1,3,3), imshow(builtInEqualizationI), title('Equalized image (matlab)');
figure
subplot(1,3,1), stem(x,counts), title('Histogram');
subplot(1,3,2), stem(x,histMyOut), title('Equalized Histogram (mine)');
subplot(1,3,3), stem(x,histBuiltInEqu), title('Equalized Histogram (matlab)');
difference = abs(equalizedI-builtInEqualizationI);
figure, imshow(difference,[]);