图像增强:直方图均衡和小波变换【matlab】

  直方图均衡:统计图像像素灰度的直方图分布。对其进行重新分配以使图像的直方图分布更加均衡。

       小波变换:图像轮廓主要体现在低频部分,可以通过对低频分解系数进行增强处理,对高频分解系数进行衰减处理,达到图像增强。

 

clc;
clear all;
img=imread('D:\文件及下载相关\图片\gray.jpg');
gray_img=rgb2gray(img);                      
[m,n]=size(gray_img);                          
pr=zeros(1,256);                        
for i=1:256
     pr(i)=length(find(gray_img==i-1))/(m*n);  
end
S=zeros(1,256);
for i=1:256
     for j=1:i
          S(i)=pr(j)+S(i);              
     end
end
S1=round((S*255)+0.5);                    
for i=1:256
     q(i)=sum(pr(find(S1==i)));         
end
res_img=gray_img;
for i=1:256
    res_img(find(gray_img==i-1))=S1(i);              
end
imshow(res_img);
title('均衡化后');

 

小波变换:

clc
I= imread('D:\文件及下载相关\图片\gray.jpg');
I1 = I(:,:,1);
[c,s]=wavedec2(I1,3,'sym4'); len=length(c);
w = prod(s(1,:));
for i =1:w  
    if(c( i )>250)  
      c( i )=1.3*c( i );  
    end  
end  
for i =w:len  
    if(c( i ) < 250)  
      c( i )=0.8*c( i );  
    end  
end  
nx1=waverec2(c,s,'sym4'); 
I2 = I(:,:,2);
[c,s]=wavedec2(I2,3,'sym4'); 
len=length(c);
w = prod(s(1,:));
for j =1:w  
    if(c( j )>250)  
      c( j )=1.3*c( j );  
    end  
end  
for j =w:len  
    if(c( j ) < 250)  
      c( j )=0.8*c( j );  
    end  
end  
nx2=waverec2(c,s,'sym4'); I3 = I(:,:,3);
[c,s]=wavedec2(I3,3,'sym4'); 
len=length(c);
w = prod(s(1,:));
for k =1:w  
    if(c( k )>250)  
      c( k )=1.3*c( k );  
    end  
end  
for k =w:len  
    if(c( k ) < 250)  
      c( k )=0.8*c( k );  
    end  
end  
nx3=waverec2(c,s,'sym4');
nx = cat(3,nx1,nx2,nx3);
figure(),imshow(nx/256)

 

posted @ 2018-01-12 18:45  ostartech  阅读(4360)  评论(0编辑  收藏  举报