【问题标题】:Histogram equalization function直方图均衡功能
【发布时间】:2014-10-25 06:55:37
【问题描述】:

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

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))

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

【问题讨论】:

    标签: matlab image-processing histogram


    【解决方案1】:

    我从你的代码中得到这个:

    怎么了?除非你的图片是rgb,否则代码可以工作(我使用了cameraman)。

    【讨论】:

    • 语法正确但 histeq 和我的代码不同
    • 现在我明白了!让我稍微改变一下问题。
    【解决方案2】:

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

    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');
    

    【讨论】:

    • 这段代码给出了与 histeq() 获得的相同的输出图像。但是为什么图像的直方图(由您的代码生成,另一个由 histeq() 生成)是不同的。 histeq() 给出的那个比你的更平坦。任何人都请帮忙。
    猜你喜欢
    • 1970-01-01
    • 2017-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-03
    • 2016-11-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多