数字图像处理之作业2
2014-11-24 21:53
786 查看
%This script shows how to perform linear filtering directly in the Fourier domain. %By Li Jiechu 1252853, codes for homework 2 ,programming 1. %imread an image , use rgb2gray if it is necessary Image = imread('C:\Users\asus\Desktop\LIHYU作业\homework2\baby.jpg'); %Image = rgb2gray(Image); [rows,colums] = size(Image); %Choose test mode: % default:centered the image and surrounded it by a border of zeros mode = 1; % Image padding:the Image locates in the Top,Left Corner with a border of zeros surrounded % mode = 2; %Step1: image padding if(2 == mode) ImagePadded = padarray(Image,[rows,colums],0,'post'); %put the image on left,top corner else ImagePadded = padarray(Image,[rows/2,colums/2],0,'both');%put the image on center end figure(1); subplot(2,2,1),imshow(Image),title('Original Picture'); if(2 == mode) subplot(2,2,2),imshow(ImagePadded),title('Image Padded in Corner'); else subplot(2,2,2),imshow(ImagePadded),title('Image Padded in Center'); end [m,n]=size(ImagePadded); % Step 2: Multiply fp(x,y) by (-1)^(x+y) to center its transform % [m,n]=size(ImagePadded); % for i = 1:m % for j = 1:n % ImagePadded(i,j) = ImagePadded(i,j)*((-1)^(i+j)); % end % end % Step 3: Discrete Fourier Transform,DFT J=fftshift(fft2(ImagePadded)); subplot(2,2,3),imshow(log(abs(J)),[]),title('frequency spectrum'); % Step 4: construct a low-pass filter in the Fourier domain % Let D0 = 50,We can change it here,Ideal Low-Pass filter; D0=50; result = zeros(m,n); rows_center = fix(m/2); cols_center = fix(n/2); for i = 1:m for j = 1:n d = sqrt((i-rows_center)^2+(j-cols_center)^2); if(d<=D0 ) D = 1; else D = 0; end result(i,j) = J(i,j)* D; end end % Step 5: go back to the spatial domain result = ifftshift(result); J2 = ifft2(result); J3 = uint8(real(J2)); % Step 6: % for i = 1:m % for j = 1:n % J3(i,j) = J3(i,j)*((-1)^(i+j)); % end % end %extract the final processed result if(2 == mode) subplot(2,2,4),imshow(J3(1:rows,1:colums)),title('Final Result'); else subplot(2,2,4),imshow(J3(rows/2:3*rows/2,colums/2:3*colums/2)),title('Final Result'); end % ----------------------------------------------------------------------- % The following are some notes I take in this program. | % ----------------------------------------------------------------------- % ----------------------------------------------------------------------- % 1.About padarray | % ----------------------------------------------------------------------- % B = padarray(A,PADSIZE,PADVAL,DIRECTION) pads A in the direction; % String values for DIRECTION % 'pre' Pads before the first array element along each dimension . % % 'post' Pads after the last array element along each dimension. % % 'both' Pads before the first array element and after the % last array element along each dimension. % -------------------- 4000 --------------------------------------------------- % 2.My own padarray | % ----------------------------------------------------------------------- %I also write my personal padarray function and test it after. %Just see the mypadarray.m and TestMyPadaray.m including in my homework % -----------------------------------------------------------------------
相关文章推荐
- Matlab学习(一):数字图像处理大作业用到的函数
- BJUT数字图像处理作业
- BJUT数字图像处理作业
- 数字图像处理--大作业,
- 数字图像与视频处理 作业模板 Latex版
- BJUT数字图像处理作业
- 数字图像处理作业3
- 期末数字图像处理的作业
- BJUT数字图像处理作业
- 数字图像处理基础-第二章数字图像处理基础
- 数字图像处理界标准图像Lena后面的故事
- 关于数字图像处理中灰度化的问题
- 利用Visual C#处理数字图像
- C#做数字图像处理研究的感觉
- 数字图像处理编程入门—第1章 Windows位图和调色板
- vs+C#处理数字图像
- RenderMonkey在数字图像处理中的应用
- 利用Visual C#处理数字图像(2)
- 国外数字图像处理网站[转贴]
- 【源代码】数字图像处理部分源码