0
我正在研究Matlab 17.a程序的圖像處理。我的工作是關於直方圖均衡。代碼如下。但是當我運行代碼「未定義的函數或變量'cumulavite_hist'」。我收到一個錯誤。我該如何解決這個問題?感謝您的幫助。如何解決未定義的函數或變量錯誤?
輸出將是原始圖像旁邊的直方圖。下面將是變化的圖片和直方圖。感謝您的幫助。
>> img= imread ('C:\Users\emre.guzel\Desktop\homeworkimage.png');
if (size(img,3)>1)
img=rgb2gray(img);
end
max_r = size (img,1);
max_c =size (img,2);
histogram =zeros ([1 256]);
cumulative_hist = zeros ([1 256]);
for r=1:max_r
for c=1:max_c
for count =1:256
if(img(r,c) == count-1)
histogram (count) =histogram (count)+ 1;
break ;
end
end
end
end
%find cumulative histogram
current_value = 0;
for count=1:256
current_value = current_value + histogram (count);
cumulative_hist(count) = current_value;
end
%find h =(cdf-cdf(min)/(MN - cdf (min))) * 255
%this is the normalized cumulative histogram normalize dediğine bakma sen.
%histogram equalization formulu bu . aşağıda da bunu uygulamış.
normalized_hist = zeros ([1 256]);
cdf_min = min (cumulavite_hist) ;
for count = 1:256
normalized_hist(count) = cumulative_hist(count) - cdf_min;
normalized_hist(count) = normalized_hist (count)/((max_r*max_c)- cdf_min);
normalized_hist(count) = round (normalized_hist (count) * 255);
end
%replace the values with given equalized values
equalized_image = zeros ([max_r max_c]);
for r =1:max_r
for c=1:max_c
for count = 1:256
if(img(r,c) ==(count-1))
%
%
equlized_img(r,c) = normalized_hist(count);
break;
end
end
end
end
subplot(2,2,1)
imshow(img);
title('Orijinal Image');
subplot (2,2,2);
imhist(img) ;
title ('Hist of Orijinal Image');
subplot(2,2,3) ;
imhist (uint8(equalized_img));
title('Histogram Equalized Image');
H = uint (equalized_img);
subplot(2,2,4) ;
imhist(H) ;
title ('Histogram of Histogram Equalized Image');
a = histeq(img);
figure
imshow(a)