W2-图像增强

线性变换

imag = imread('sherlock.jpg');
gray = rgb2gray(imag);
figure; 
subplot(2,2,1);
imshow(gray);
title('原图');
subplot(2,2,2);
imhist(gray);
title('原图灰度直方图');
a1=20;
b1=255;
a=50;
b=155;
image1=a1+(b1-a1)/(b-a)*(gray-a);
subplot(2,2,3);
imshow(image1);
title('线性变换后图像');
subplot(2,2,4);
imhist(image1);
title('线性变换后灰度直方图');

对数变换

imag = imread('office_1.jpg');
gray = rgb2gray(imag);
figure;subplot(2,2,1);
imshow(gray);
title('原图');
subplot(2,2,2);
imhist(gray);
title('原图灰度直方图');
c=1.2;
k=1.25;
image2=c*log(k+im2double(gray));
subplot(2,2,3);
imshow(image2);
title('对数变换后的图像');
subplot(2,2,4);
imhist(image2);
title('对数变换后的直方图');

%改进对数变换
figure;
subplot(2,2,1);
imshow(gray);
title('原图');
subplot(2,2,2);
imhist(gray);
title('原图灰度直方图');
v=500;
r=mat2gray(double(gray));
image2=log(1+v*r)/(log(v+1));
subplot(2,2,3);
imshow(image2);
title('改进对数变换后的图像');
subplot(2,2,4);
imhist(image2);
title('改进对数变换后的直方图');

Gamma变换

imag = imread('sherlock.jpg');
gray = rgb2gray(imag);
figure;
subplot(3,2,1);
imshow(gray);
title('原图');
subplot(3,2,2);
imhist(gray);
title('原图灰度直方图');
image3=imadjust(gray,[],[],0.6);
subplot(3,2,3);
imshow(image3);
title('Gamma=0.6变换后图像');
subplot(3,2,4);
imhist(image3);
title('Gamma=0.6变换后灰度直方图');
image4=imadjust(gray,[],[],1.8);
subplot(3,2,5);
imshow(image4);
title('Gamma=1.8变换后图像');

直方图均衡化

imag = imread('foosballraw.tiff');
gray=imag;
figure;
subplot(2,2,1);
imshow(gray);
title('原图');
subplot(2,2,2);
imhist(gray);
title('原图灰度直方图');
image1=histeq(gray);
subplot(2,2,3);
imshow(image1);
title('均衡化图像');
subplot(2,2,4);
imhist(image1);
title('均衡化后灰度直方图');

邻域平均法

imag = imread('yellowlily.jpg');
gray=rgb2gray(imag);
figure;
subplot(5,2,1);
imshow(gray);
title('原图');
subplot(5,2,2);
imhist(gray);
title('原图灰度直方图');
gauss_imag=imnoise(gray,'gaussian');
sp_imag=imnoise(gray,'salt & pepper');
subplot(5,2,3);
imshow(gauss_imag);
title('添加高斯噪声');
subplot(5,2,4);
imhist(gauss_imag);
title('添加高斯噪声后直方图');
subplot(5,2,5);
imshow(sp_imag);
title('添加椒盐噪声');
subplot(5,2,6);
imhist(sp_imag);
title('添加高斯噪声后直方图');
h_a=fspecial('average');
imag1=imfilter(gauss_imag,h_a);
subplot(5,2,7);
imshow(imag1);
title('邻域平滑图像');
subplot(5,2,8);
imhist(imag1);
title('邻域平滑直方图');
imag2=imfilter(sp_imag,h_a);
subplot(5,2,9);
imshow(imag2);
title('邻域平滑图像');
subplot(5,2,10);
imhist(imag2);
title('邻域平滑直方图');

中值滤波

imag = imread('yellowlily.jpg');
gray=rgb2gray(imag);
figure;
subplot(3,2,1);
imshow(gray);
title('原图');
subplot(3,2,2);
imhist(gray);
title('原图灰度直方图');
gauss_imag=imnoise(gray,'gaussian');
sp_imag=imnoise(gray,'salt & pepper');
subplot(3,2,3);
imshow(gauss_imag);
title('添加高斯噪声');
subplot(3,2,4);
imhist(gauss_imag);
title('添加高斯噪声后直方图');
subplot(3,2,5);
imshow(sp_imag);
title('添加椒盐噪声');
subplot(3,2,6);
imhist(sp_imag);
title('添加高斯噪声后直方图');
figure;
imag1=medfilt2(gauss_imag);
subplot(2,2,1);
imshow(imag1);
title('高斯噪声经中值滤波后图像');
subplot(2,2,2);
imhist(imag1);
title('高斯噪声经中值滤波后直方图');
imag2=medfilt2(sp_imag);
subplot(2,2,3);
imshow(imag2);
title('椒盐噪声经中值滤波后图像');
subplot(2,2,4);
imhist(imag2);
title('椒盐噪声经中值滤波后直方图');

拉普拉斯算子锐化

figure;
imag = imread('football.jpg');
gray=rgb2gray(imag);
subplot(2,2,1);
imshow(gray);
title('原图');
subplot(2,2,2);
imhist(gray);
title('原图灰度直方图');
im=im2double(gray);
w=fspecial('laplacian');
I1=imfilter(im,w,'replicate');
I2=im-I1;
subplot(2,2,3);
imshow(I2);
title('锐化后图像');
subplot(2,2,4);
imhist(I2);
title('锐化后直方图');

同态滤波

figure;
imag = imread('riceblurred.png');
gray=imag;
subplot(2,2,1);
imshow(gray);
title('原图');
subplot(2,2,2);
imhist(gray);
title('原图灰度直方图');
I=im2double(gray);
[M,N]=size(I);  
rL=0.5;  
rH=5; 
c=2;  
d0=10;  
I1=log(I+1);
FI=fft2(I1);
n1=floor(M/2);  
n2=floor(N/2);  
for i=1:M  
    for j=1:N  
        D(i,j)=((i-n1).^2+(j-n2).^2);  
        H(i,j)=(rH-rL).*(exp(c*(-D(i,j)./(d0^2))))+rL;
    end  
end  
I2=ifft2(H.*FI)
I3=real(exp(I2));  
subplot(2,2,3);
imshow(I3,[]);
title('同态滤波后图像');  
subplot(2,2,4);
I4 = I3-1;
imhist(I4);
title('同态滤波后直方图')

猜你喜欢

转载自blog.csdn.net/dhejsb/article/details/120914381