美文网首页
基于直方图修改的彩色图像增强

基于直方图修改的彩色图像增强

作者: amazingu | 来源:发表于2016-10-21 01:13 被阅读675次

    对上述图像进行增强、主要增强两方面,一方面是图像的亮度,另一方面就是图像的对比度。

    第一种方法:将RGB格式的图像转为HSV或者HSI格式,对于亮度值进行修改。主要是对V值直方图进行均衡化。

    clear all;

    close all;

    RGB=imread('test.jpeg');

    HSV=rgb2hsv(RGB);

    H=HSV(:,:,1);

    S=HSV(:,:,2);

    V=HSV(:,:,3);

    figure;

    subplot(1,3,1),imhist(H);

    subplot(1,3,2),imhist(S);

    subplot(1,3,3),imhist(V);

    V=histeq(V);

    figure,imhist(V);

    HSV(:,:,1)=H;

    HSV(:,:,2)=S;

    HSV(:,:,3)=V;

    RGB_1=hsv2rgb(HSV);

    figure;

    subplot(1,2,1),imshow(RGB);

    subplot(1,2,2),imshow(RGB_1);

    最后的效果如下图:

    白云、山脉、河流有了亮度和对比度提升。

    第二种方法就是对RGB三个通道直接进行直方图均衡化。

    clear all;

    close all;

    RGB=imread('test.jpeg');

    R=double((RGB(:,:,1)))/255;

    G=double((RGB(:,:,2)))/255;

    B=double((RGB(:,:,3)))/255;

    figure;

    subplot(1,3,1),imshow(R);

    subplot(1,3,2),imshow(G);

    subplot(1,3,3),imshow(B);

    R=histeq(R);

    G=histeq(G);

    B=histeq(B);

    RGB_1(:,:,1)=R;

    RGB_1(:,:,2)=G;

    RGB_1(:,:,3)=B;

    figure;

    subplot(1,2,1),imshow(RGB);

    subplot(1,2,2),imshow(RGB_1),brighten(0.6);

    figure;

    subplot(1,3,1),imhist(R);

    subplot(1,3,2),imhist(G);

    subplot(1,3,3),imhist(B);

    这个处理效果如下:

    由上图可以看出、图像的色调已经被修改、这也是RGB值修改的一个缺点。

    第三种方法就是目前我采用的,根据HE、BBHE、DSIHE、所采用的一种图像增强方法。其原理简单介绍如下:

    首先将RGB图像转为灰度图像、那么每个灰度图像像素的数值根据最大值法即:max(R,G,B)来确定,最大值法(图4)与加权平均(图2)、平均法处理(图3)的对比图如下所示:

    由上图可以看出、最大值处理的灰度图像较其余两幅图的亮度有较大的提升。

    接着处理灰度图像的直方图、找出该图像的平均值、将直方图划分为两部分、接着分别对两部分的直方图进行均衡化处理。

    在处理完成之后、对图像进行恢复、即将灰度图像转化成RGB图像,找出处理之后的图像与之前图像的数值比例关系、然后将其与图像想乘,即得到R、G、B三个分量的数值。最后的对比图如下:

    clear all;

    close all;

    clc;

    RGB=imread('test.jpeg');

    [row,column,n]=size(RGB);

    R=RGB(:,:,1);

    G=RGB(:,:,2);

    B=RGB(:,:,3);

    for i=1:row

    for j=1:column

    juzhen=[R(i,j),G(i,j),B(i,j)];

    intensity_1(i,j)=0.2989*R(i,j)+0.587*G(i,j)+0.114*B(i,j);

    intensity_2(i,j)=1/3*(R(i,j)+G(i,j)+B(i,j));

    intensity_3(i,j)=max(juzhen);

    end

    end

    figure,

    subplot(2,2,1),imshow(rgb2gray(RGB));

    subplot(2,2,2),imshow(intensity_1);

    subplot(2,2,3),imshow(intensity_2);

    subplot(2,2,4),imshow(intensity_3);

    Pre_image=intensity_3;

    figure;

    subplot(2,2,1),imshow(intensity_3);

    subplot(2,2,2),imhist(intensity_3);

    subplot(2,2,3),imshow(Pre_image);

    subplot(2,2,4),imhist(Pre_image);

    Pre_image=im2uint8(Pre_image);

    [height,width]=size(Pre_image);

    XT=round(mean(mean(Pre_image)));

    h = zeros(1,256);%统计各灰度数目,共256个灰度级

    for m = 1:height

    for n = 1: width

    h(Pre_image(m,n) + 1) = h(Pre_image(m,n) + 1) + 1;%对应灰度值像素点数量增加一

    end

    end

    SH1=0;

    SH2=0;

    for x=0:XT

    SH1=SH1+h(x+1);

    end

    for x=(XT+1):255

    SH2=SH2+h(x+1);

    end

    N=height*width;

    RSH1=SH1/N;

    RSH2=SH2/N;

    SEP_P=round(255*RSH1);

    DRH1_start=0;

    DRH1_end=SEP_P;

    DRH2_start=SEP_P+1;

    DRH2_end=255;

    sum1=0;

    CH1=zeros(1,256);

    for x_1=0:XT

    sum1=sum1+h(x_1+1);

    CH1(x_1+1)=sum1/SH1;

    end;

    sum2=0;

    CH2=zeros(1,256);

    for x_2=(XT+1):255

    sum2=sum2+h(x_2+1);

    CH2(x_2+1)=sum2/SH2;

    end

    for i=1:height

    for j=1:width

    if Pre_image(i,j)

    h(Pre_image(i,j)+1)=DRH1_start+(DRH1_end-DRH1_start)*CH1(Pre_image(i,j)+1);

    else

    h(Pre_image(i,j)+1)=DRH2_start+(DRH2_end-DRH2_start)*CH2(Pre_image(i,j)+1);

    end

    end

    end

    for i=1:height

    for j=1:width

    Aft_image(i,j)=h(Pre_image(i,j)+1);

    end

    end

    Aft_image=uint8(Aft_image);

    subplot(1,2,1),imhist(Aft_image);

    subplot(1,2,2),imshow(Aft_image);

    for i=1:height

    for j=1:width

    Alpha(i,j)=double(Aft_image(i,j))./double(intensity_3(i,j));

    end

    end

    intensity_R=Alpha.*double(R);

    intensity_G=Alpha.*double(G);

    intensity_B=Alpha.*double(B);

    RGB_1(:,:,1)=intensity_R;

    RGB_1(:,:,2)=intensity_G;

    RGB_1(:,:,3)=intensity_B;

    figure,

    subplot(1,2,2),imshow(uint8(RGB_1));

    subplot(1,2,1),imshow(RGB);

    这种方法对于图像增强的细节有较好的增强作用。

    接下来是通过HSI方面对图像进行增强。

    相关文章

      网友评论

          本文标题:基于直方图修改的彩色图像增强

          本文链接:https://www.haomeiwen.com/subject/pxmquttx.html