数字图像处理实验2

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Exercise 3

e picture “Fig0401.tif” to do the following questions:

①Read the picture, and write down the Fourier transform program of it. >> f=imread('Fig0401.tif');

>> g=fft2(f);

Warning: FFTN on values of class UINT8 is obsolete.

Use FFTN(DOUBLE(X)) or FFTN(SINGLE(X)) instead.

> In uint8.fftn at 10

In fft2 at 19

>> s=abs(g);

>> imshow(s,[])

②Use the function fftshift to center the spectrum.

>> fc=fftshift(g);

>> imshow(abs(fc),[])

③Use logarithmic transformation to enhance the centered spectrum. >> s2=log(1+abs(fc));

>> imshow(s2,[])

④Visualize the dealing results of step②and step③.

结果如上

2.Generate a filter function H

①Use function fspecial to generate a ‘laplacian’ spatial domain filter h

>> h=fspecial('laplacian',0.5)

h=

0.3333 0.3333 0.3333

0.3333 -2.6667 0.3333

0.3333 0.3333 0.3333

②Use function freqz2 to convert the spatial domain filter h to frequency domain filter H.

>>h= freqz2(h);

③Use function freqz2 to show a 3-D perspective plot of H and give the result. >> freqz2(h)

e function dftfilt to do the DFT Filtering with picture “lena.bmp”

①Obtain the padding parameters of the picture use function paddedsize.

> f=imread('lena.bmp');

>> imshow(f)

>> [m ,n]=size(f)

m =

256

n =

256

>> PQ=paddedsize(size(f))

PQ =

512 512

②Use function fspecial to generate a ‘unsharp’ spatial domain filter.

>> h=fspecial('unsharp',0.2)

h =

-0.1667 -0.6667 -0.1667

-0.6667 4.3333 -0.6667

-0.1667 -0.6667 -0.1667

③Use function freqz2 to convert the spatial domain filter h to frequency domain filter H of >> freqz2(h)

④Get the uncentered form of frequency domain filter H.

>>H=freqz2(h,PQ(1),PQ(2));

>>W=ifftshift(H);

>> imshow(abs(H),[])

>> imshow(abs(w),[])

⑤Use function dftfilt to do the DFT Filtering and give the final result. >> s=imfilter(double(f),h);

>> d=dftfilt(f,W);

Warning: FFTN on values of class UINT8 is obsolete.

Use FFTN(DOUBLE(X)) or FFTN(SINGLE(X)) instead. > In uint8.fftn at 10

In fft2 at 21

In dftfilt at 17

>> imshow(s,[])

>> imshow(d,[])

4.Try to compute the distance squared from every point in a rectangle of size 7×7 to

the origin of the rectangle with command dftuv and give the result.

>> [u,v]=dftuv(7,7);

>> d=u.^2+v.^2

d =

0 1 4 9 9 4 1

1 2 5 10 10 5 2

4 5 8 13 13 8 5

9 10 13 18 18 13 10

9 10 13 18 18 13 10

4 5 8 13 13 8 5

1 2 5 10 10 5 2

5.Assuming M=200,N=200,D0=20, use function lpfilter to do the following questions:

①Generate a ‘ideal’ lowpass filter.

②Generate a ‘btw’ lowpass filter.

③Show the centered result of the filters which were generated in ①and ②, and then tell the differences between them.

>> h=lpfilter('ideal',200,200,20);

>> p=fftshift(h);

>> iimshow(p)

>> f=lpfilter('btw',200,200,20);

>> k=fftshift(f);

>> imshow(k)

相关文档
最新文档