DIP第三章习题解答

数字图像处理 第三章课后作业

下载地址:https://download.csdn.net/download/qq_44143405/1254953icon-default.png?t=M276https://download.csdn.net/download/qq_44143405/12549535

第一题

(3-7)假设对一幅数字图像进行直方图均衡处理,试证明(对直方图均衡后的图像)进行第二次直方图均衡处理的结果与第一次直方图均衡处理的结果相同。

注:附录 含 matlab 代码及结果显示!

第二题

(3-17)讨论用一个3×3低通空间滤波器反复对一幅数字图像处理的结果,可以不考虑边界的影响。应用5×5滤波器时何不同?

注:附录 含 matlab 代码及结果显示!

第三题

(3-19)(a)试给出求一个  领域的中值的步骤。

(b)试提出一种逐像素地移动邻域的中心来更新中值的技术。

第四题

(3-23)在给定应用中,一个均值模板被用于输入图像以减少噪声,然后再用一个拉普拉斯模板来增强图像中的细节。如果交换一下这两个步骤的顺序,结果是否会相同?

注:附录 含 matlab 代码及结果显示!

第五题

(3-6)试解释为什么离散直方图均衡技术一般不能得到平坦的直方图?

注:从第一题附录中图可清楚的看出来!

附录:

第一题

代码块:

Image=rgb2gray(imread('lotus.bmp'));

histgram =imhist(Image);%%统计图像直方图

[h,w]=size(Image);

NewImage1=zeros(h,w);

NewImage2=zeros(h,w);



NewImage1=histeq(Image,256);%%调用Matlab函数

NewImage2=histeq(NewImage1,256);



imwrite(Image,'lotus0.bmp')

imwrite(NewImage1,'lotus1.bmp')

imwrite(NewImage2,'lotus2.bmp')



figure('name','原图像');

subplot(2,1,1),imshow(Image);title('lotus灰度图像');

subplot(2,1,2),imhist(Image);title('lotus灰度图像的直方图');

axis tight;



figure('name','直方图均衡化');

subplot(2,1,1),imshow(NewImage1);title('全局直方图均衡化处理后图像');

subplot(2,1,2),imhist(NewImage1);title('全局直方图均衡化处理后图像的直方图');

axis tight;



figure('name','二次直方图均衡化');

subplot(2,1,1),imshow(NewImage2);title('二次全局直方图均衡化处理后图像');

subplot(2,1,2),imhist(NewImage2);title('二次全局直方图均衡化处理后图像的直方图');

axis tight;

(1-1)灰度图像及直方图

(1-2)直方图均衡化灰度图像及直方图

(1-3)二次直方图均衡化灰度图像及直方图

第二题

代码块:

Image=imread('Letters-a.jpg');

noiseI=imnoise(Image,'gaussian');                %添加高斯噪声

for i=2:51

result(:,:,1)=noiseI(1:5,1:5);

result(:,:,i)=filter2(fspecial('average',3),result(:,:,i-1));                %3×3均值滤波

end

figure(1);

subplot(221),imshow(uint8(result(:,:,1))),title('高斯噪声图像');

subplot(222),imshow(uint8(result(:,:,6))),title('五次3×3均值滤波图像');

subplot(223),imshow(uint8(result(:,:,11))),title('十次3×3均值滤波图像');

subplot(224),imshow(uint8(result(:,:,51))),title('五十次3×3均值滤波图像');

>> result(:,:,2)

ans =

  5×5 uint8 矩阵

    95   140   140   140    96

   151   219   219   219   151

   155   227   227   220   147

   152   222   217   216   146

    96   143   137   138    91

>> result(:,:,6)

ans =

  5×5 uint8 矩阵

    34    58    67    58    33

    58   100   115   100    58

    67   116   133   115    66

    58   100   115    99    58

34    58    67    58    33

Image=imread('Letters-a.jpg');

noiseI=imnoise(Image,'gaussian');                %添加高斯噪声



for i=2:51

result(:,:,1)=noiseI;

result(:,:,i)=filter2(fspecial('average',3),result(:,:,i-1));                %3×3均值滤波

end



figure(1);

subplot(221),imshow(uint8(result(:,:,1))),title('高斯噪声图像');

subplot(222),imshow(uint8(result(:,:,6))),title('五次3×3均值滤波图像');

subplot(223),imshow(uint8(result(:,:,11))),title('十次3×3均值滤波图像');

subplot(224),imshow(uint8(result(:,:,51))),title('五十次3×3均值滤波图像');



for i=2:51

result1(:,:,1)=noiseI;

result1(:,:,i)=filter2(fspecial('average',5),result(:,:,i-1));                %3×3均值滤波

end



figure(2);

subplot(221),imshow(uint8(result1(:,:,1))),title('高斯噪声图像');

subplot(222),imshow(uint8(result1(:,:,6))),title('五次5×5均值滤波图像');

subplot(223),imshow(uint8(result1(:,:,11))),title('十次5×5均值滤波图像');

subplot(224),imshow(uint8(result1(:,:,51))),title('五十次5×5均值滤波图像');

2-13×3均值滤波图像

(2-2)5×5均值滤波图像

第三题

  1. 代码块:
function m = median(x, n)

%%子函知数,计算x邻域的中值,n为邻域x的长度

x = sort(x);

if rem(n, 2) == 1

    m = x((n+1)/2);

else

    m = (x(n/2)+x(n/2+1))/2;

end %%end if

end %%end function

验证

Input:

A = [3 2 4; 6 2 4; 8 1 9];

[M,N] = size(A);

n = M*N;

B = reshape(A,1,n);

median(B,n)

Ouput:

ans =

     4

  1. 代码块:

Input:

Image1=(rgb2gray(imread('couple.bmp')));

Image=Image1(1:9,1:9);

[height,width]=size(Image);

%%声明新变量

result2=zeros(height,width);

n = 1;%%邻域模板半径

hh=height+2*n;

ww=width+2*n;

ff=zeros(hh,ww);%%图像对外边缘扩充ff;补零

%%赋值

ff(n+1:hh-n,n+1:ww-n)=Image;

ff(1:n,n+1:ww-n)=0;

ff(hh-n+1:hh,n+1:ww-n)=0;

ff(:,1:n)=0;

ff(:,ww-n+1:ww)=0;

ff=uint8(ff);

%%逐个取16*16邻域中值,先从第一行开始,列逐取中值

for i=n+1:hh-n

    for j=n+1:ww-n  

        lwc=ff(i-n:i+n,j-n:j+n);%%计算子块的局部直方图均衡化

        [M,N] = size(lwc);

        nn = M*N;

        B = reshape(lwc,1,nn);

        result2(i-n,j-n)=median(B,nn);

    end

end

figure('name','邻域中值处理图像');imshow(uint8(result2));title('邻域中值处理图像');

imwrite(uint8(result2),'LHE.bmp');

Ouput:

原图像灰度值(9*9)

   28   22   15   13   15   16   17   16   14

   29   22   14   12   15   17   16   18   14

   29   24   14   14   15   16   15   16   14

   27   23   14   12   15   15   15   16   14

   29   25   14   14   14   16   15   17   15

   27   23   15   15   14   14   15   16   14

   29   25   14   13   13   16   16   17   15

   27   25   15   13   13   15   16   16   13

   28   22   15   14   15   15   15   15   14

邻域补零后图像灰度值(11*11)

    0    0    0    0    0    0    0    0    0    0      0

    0   28   22   15   13   15   16   17   16   14    0

    0   29   22   14   12   15   17   16   18   14    0

    0   29   24   14   14   15   16   15   16   14    0

    0   27   23   14   12   15   15   15   16   14    0

    0   29   25   14   14   14   16   15   17   15    0

    0   27   23   15   15   14   14   15   16   14    0

    0   29   25   14   13   13   16   16   17   15    0

    0   27   25   15   13   13   15   16   16   13    0

    0   28   22   15   14   15   15   15   15   14    0

    0    0    0    0    0    0    0    0    0     0     0

3*3掩膜后的图像灰度值

     0    15    13    13    13    15    16    14     0

    22    22    14    14    15    16    16    16    14

    23    23    14    14    15    15    16    15    14

    24    24    14    14    15    15    16    15    14

    23    23    15    14    14    15    15    15    14

    25    25    15    14    14    15    16    15    15

    25    25    15    14    14    15    16    16    14

    25    25    15    14    14    15    16    15    14

     0    15    14    13    13    15    15    14     0

第四题

代码块:

% 先均值模板再用一个拉普拉斯模板处理的代码块

Image=imread('Letters-a.jpg');

noiseI=imnoise(Image,'gaussian');



figure(1);

subplot(221),imshow(Image),title('原图');

subplot(222),imshow(noiseI),title('高斯噪声图像');



noiseI=im2double(noiseI);



result1=filter2(fspecial('average',3),noiseI);%%3×3均值滤波

subplot(223),imshow(result1),title('3×3均值滤波');



% % result1=im2double(result1);



H1=[0 -1 0;-1 5 -1;0 -1 0];

sharpImage=imfilter(result1,H1);

subplot(224),imshow(sharpImage),title('Laplacian锐化图像');



% 先用一个拉普拉斯模板再用均值模板处理的代码块

Image=imread('Letters-a.jpg');

noiseI=imnoise(Image,'gaussian');  



figure(2),subplot(221),imshow(Image),title('原图');

subplot(222),imshow(noiseI),title('高斯噪声图像');



noiseI=im2double(noiseI);

H1=[0 -1 0;-1 5 -1;0 -1 0];

sharpImage=imfilter(noiseI,H1);

subplot(223),imshow(sharpImage),title('Laplacian锐化图像');



% % sharpImage=uint8(sharpImage);

result1=filter2(fspecial('average',3),sharpImage);     %%3×3均值滤波

subplot(224),imshow(result1),title('3×3均值滤波');

(4-1)先均值模板再拉普拉斯模板

(4-2)先拉普拉斯模板再均值模板

  • 2
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qq-120

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值