本文介绍了直方图均衡功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用此代码实现直方图均衡:

I'm trying to implement the histogram equalization using this code:

clc
A=input('please enter image adress','s');
Iimg=imread(A);
Iimg1=double(Iimg);
histi=imhist(Iimg);
mmax=max(Iimg1(:));
h=histi/numel(Iimg1)
cdf=cumsum(h)
cdf=cdf*double(mmax);
c=uint8(cdf);
subplot(1,3,1)
bar(c)
subplot(1,3,2)
imhist(Iimg)
subplot(1,3,3)
imhist(histeq(Iimg))

我的代码错了吗?
我没有得到预期的结果。

Is my code wrong?I don't get expected results.

推荐答案

我找到了正确的代码并在这里写给其他人

i find correct code for this and write here for others

clc
A=input('please enter image adress: ','s');
GIm=imread(A);
[x, y ,m]=size(GIm);
if m==3
    GIm=rgb2gray(GIm);
end
inf=whos('GIm');
Isize=0;
if inf.class=='uint8'
    Isize=256;
    else if inf.class=='uint68'
        Isize=65565;
        end
end
HIm=uint8(zeros(size(GIm,1),size(GIm,2)));
freq=zeros(256,1);
probf=zeros(256,1);
probc=zeros(256,1);
cum=zeros(256,1);
output=zeros(256,1);
freq=imhist(GIm);%histogram
sum=0;
no_bins=255;
probc=cumsum(freq)/numel(GIm);
output=round(probc*no_bins);
HIm(:)=output(GIm(:)+1);
%show
figure
subplot(2,2,1)
imshow(GIm);
title('original image');
subplot(2,2,2)
imshow(HIm);
title('Image equalization');
subplot(2,2,3)
imhist(GIm);
title('origina');
subplot(2,2,4)
imhist(HIm);
title('histogram equalization');
figure
subplot(2,2,1)
imshow(histeq(GIm));
title('matlab equalization');
subplot(2,2,2)
imshow(HIm);
title('my code equalization');
subplot(2,2,3)
imhist(histeq(GIm));
title('hist matlab eq');
subplot(2,2,4)
imhist(HIm);
title('hist my code eq');
figure
subplot(2,2,1)
imshow(GIm);
title('origina');
subplot(2,2,2)
imshow(HIm);
title('Image equalization');
x=(1:Isize);
subplot(2,2,3)
plot(x,output);
title('transform function');
subplot(2,2,4)
plot(x,freq);
title('transform function');

这篇关于直方图均衡功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 04:02