如何实现高原极限直方图均衡算法
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何实现高原极限直方图均衡算法相关的知识,希望对你有一定的参考价值。
我一直在尝试实现一种简单而又简短的算法。我将结果的直方图与原始结果的直方图进行比较,并且始终存在巨大差异。
我一次又一次地检查我的代码。但我看不出是什么问题。我发布了步骤和我的尝试。我的错误在哪里?
histogram_of_image = imhist(input_image);
modified_histogram = zeros(1,256);
modified_histogram(1:256) = (log(histogram_of_image(1:256)+(a))).^(beta);
these_elements_are_not_zero = modified_histogram~= 0;
sum2 = sum(modified_histogram(these_elements_are_not_zero));
cnt2 = size(these_elements_are_not_zero,2);
tcl = sum2/cnt2;
clipped_histogram = zeros(1,256);
for i=1:256
if((modified_histogram(i)) >= tcl)
clipped_histogram(i) = tcl;
else
clipped_histogram(i) = (modified_histogram(i));
end
end
PDa = zeros(1,256);
PDa = clipped_histogram / (sum(clipped_histogram));
CDa = zeros(1,256); %create CDa in formula
CDa(1) = PDa(1) ;
for i=2:256
CDa(i) = PDa(i) + CDa(i-1);
end
value_after_enhancement = zeros(1,256);
value_after_enhancement = (255 * CDa);
b=uint8(0);
output_image=zeros(width,height);
output_image = value_after_enhancement(input_image+1);
figure;imshow(uint8(output_image));
original_result=imread('testsonuc.bmp');
original_result=double(rgb2gray(original_result));
image_of_dif= zeros(width,height);
figure;imshow(uint8(original_result));
答案
除了对结果进行细微描述外,其他所有内容都是正确的,您应该将输出图像从double转换为无符号整数。output_image = uint8(output_image);
%value_after_enhancement = zeros(1,256);
value_after_enhancement = (255 * CDa)+1;
%b = uint8(0);
%output_image = zeros(width,height);
output_image = value_after_enhancement(input_image);
output_image = uint8(output_image);
%dif_image = output_image ./ input_image;
%===================================================================
figure('Name','Algorithm Result','NumberTitle','off');
subplot(211);
imshow(output_image);
subplot(212);
Out_Hist = imhist(output_image);
plot(Out_Hist);
以上是关于如何实现高原极限直方图均衡算法的主要内容,如果未能解决你的问题,请参考以下文章
(转)OpenCV图像增强算法实现(直方图均衡化拉普拉斯LogGamma)