MatLab 数字图像处理实验 图像增强

实验内容

(1)对曝光不足的图像采用灰度线性变换对图像每一个像素灰度做线性拉伸。

close all
clear all
I = im2double(imread('D:\figure51.jpg'));
a = 1.2;
b = -150;
I2 = a.*I+b/255;
figure;
subplot(1,2,1);imshow(I);xlabel('原图');
subplot(1,2,2);imshow(I2);xlabel('a=1.2 b=-150 增强图');

在这里插入图片描述

(2)利用空间域平滑滤波器对图像进行平滑。

close all
clear all
I = imread('D:\lena.jpg');
I_noise = double(imnoise(I,'gaussian',0.05));
I_smoothed3 = imfilter(I_noise,fspecial('average',3));
I_smoothed5 = imfilter(I_noise,fspecial('average',5));
I_smoothed7 = imfilter(I_noise,fspecial('average',7));

subplot(2,3,1);imshow(I);xlabel('原图');
subplot(2,3,2);imshow(I_noise,[]);xlabel('加入高斯噪声');
subplot(2,3,3);imshow(I_smoothed3,[]);xlabel('3x3邻域平滑');
subplot(2,3,4);imshow(I_smoothed5,[]);xlabel('5x5邻域平滑');
subplot(2,3,5);imshow(I_smoothed7,[]);xlabel('7x7邻域平滑');

在这里插入图片描述

(3)利用Prewitt、Sobel对图像进行锐化。

close all
clear all
I = imread('D:\lena.jpg');
I2 = imfilter(I,fspecial('Prewitt'));
I3 = imfilter(I,fspecial('Sobel'));

subplot(1,3,1);imshow(I);xlabel('原图');
subplot(1,3,2);imshow(I2);xlabel('Prewitt锐化后的图像');
subplot(1,3,3);imshow(I2);xlabel('Sobel锐化后的图像');

在这里插入图片描述

(4)利用高斯低通滤波对图像进行平滑。

I = imread('D:/lena.jpg');

IO1 = G(I,10);
IO2 = G(I,20);
IO3 = G(I,40);
subplot(2,2,1);imshow(I);xlabel('初始图像');
subplot(2,2,2);imshow(IO1,[]);xlabel('sig^2=100');
subplot(2,2,3);imshow(IO2,[]);xlabel('sig^2=400');
subplot(2,2,4);imshow(IO3,[]);xlabel('sig^2=1600');

function[I3]=G(I,sig)
I1 = fftshift(fft2(I));
[M,N] = size(I1);
n=2;
n1=floor(M/2);n2=floor(N/2);
for i=1:M
    for j=1:N
        d=sqrt((i-n1)^2+(j-n2)^2);
        H=exp(-((d^2/(2*sig^2))));
        I2(i,j)=H*I1(i,j);
    end
end
I2=ifftshift(I2);
I3=real(ifft2(I2));
end

在这里插入图片描述

参考:https://blog.csdn.net/uchihalyn/article/details/104593878

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值