当前位置:文档之家› 图像噪声的空频域处理设计

图像噪声的空频域处理设计

界面的设计以中值滤波和低通滤波为例,界面设计如图,代码如下: function uipanel5_SelectionChangeFcn(hObject, eventdata, handles) %图像滤波 % hObject handle to uipanel5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) x=imread('hua.jpg','jpg'); subimage(x); title('原始图像'); j=imnoise(x,'salt & pepper',0.04); subimage(j); title('加入椒盐噪声'); p=medfilt2(j,[2 2]); subimage(p); title('2x2中值滤波'); a=medfilt2(j,[3 3]); subimage(a); title('3x3中值滤波'); b=medfilt2(j,[4 4]); subimage(b); title('4x4中值滤波'); d=medfilt2(j,[5 5]); subimage(d); title('5x5中值滤波');

% --- Executes on button press in pushbutton14. function pushbutton14_Callback(hObject, eventdata, handles) % hObject handle to pushbutton14 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

axes(handles.axes2); y1=handles.img; f=double(y1); % 数据类型转换,matlab不支持图像的无符号整型的计算 g=fft2(f); % 傅里叶变换 g=fftshift(g); % 转换数据矩阵 [M,N]=size(g); nn=2; %二阶巴特沃斯低通滤波器 d0=50; %截止频率50 m=fix(M/2); n=fix(N/2); for i=1:M for j=1:N d=sqrt((i-m)^2+(j-n)^2); h=1/(1+0.414*(d/d0)^(2*nn)); % 计算低通滤波器传递函数 result(i,j)=h*g(i,j); end end result=ifftshift(result); y2=ifft2(result); y3=uint8(real(y2)); imshow(y3); % 显示处理后的图像 1.给图像加噪 i=imread('hua.jpg','jpg'); subplot(311); subimage(i); title('原始图像'); j1=imnoise(i,'gaussian',0,0.04); subplot(312); subimage(j1); imwrite(j1,'高斯噪声.jpg') title('加入高斯噪声'); j2=imnoise(i,'salt & pepper',0.04); subplot(333); subimage(j2); imwrite(j1,'椒盐噪声.jpg') title('加入椒盐噪声');

2.加噪前后的频谱图 i=imread('hua.jpg','jpg'); j1=imnoise(i,'gaussian',0,0.04); j2=imnoise(i,'salt & pepper',0.04); F=fft2(i); F1=fftshift(F); subplot(311); imshow(log(abs(F1)),[8,10]); title('原始图像频谱'); F2=fft2(j1); F3=fftshift(F2); subplot(312); imshow(log(abs(F3)),[8,10]); title('加入高斯噪声频谱'); F4=fft2(j2); F5=fftshift(F4); subplot(313); imshow(log(abs(F5)),[8,10]); title('加入椒盐噪声频谱');

图像加噪 加噪前后频谱图 3.中值滤波 x=imread('hua.jpg','jpg'); subplot(2,3,1); subimage(x); title('原始图像'); j=imnoise(x,'salt & pepper',0.04); subplot(2,3,2); subimage(j); title('加入椒盐噪声'); p=medfilt2(j,[2 2]); subplot(2,3,3); subimage(p); title('2x2中值滤波'); a=medfilt2(j,[3 3]); subplot(2,3,4); subimage(a); title('3x3中值滤波'); b=medfilt2(j,[4 4]); subplot(2,3,5); subimage(b); title('4x4中值滤波'); d=medfilt2(j,[5 5]); subplot(2,3,6); subimage(d); title('5x5中值滤波')

4.中值滤波后频谱 x=imread('hua.jpg','jpg'); j=imnoise(x,'salt & pepper',0.04); a=medfilt2(j,[3 3]); F=fft2(x);F1=fftshift(F); subplot(131); imshow(log(abs(F1)),[8,10]); title('原始图像频谱'); F2=fft2(j);F3=fftshift(F2); subplot(132); imshow(log(abs(F3)),[8,10]); title('加入椒盐噪声频谱'); F4=fft2(a);F5=fftshift(F4); subplot(133); imshow(log(abs(F5)),[8,10]); title('3x3中值滤波频谱');

中值滤波 中值滤波频谱 5、低通滤波器滤波前后 x=imread('hua.jpg','jpg'); subplot(131); subimage(x); title('原始图像'); j1=imnoise(x,'salt & pepper',0.04); imwrite(j1,'jy.jpg') subplot(132); subimage(j1); title('加入椒盐噪声'); f=double(j1); % 数据类型转换,matlab不支持图像的无符号整型的计算 g=fft2(f); % 傅里叶变换 g=fftshift(g); % 转换数据矩阵 [M,N]=size(g); nn=2; %二阶巴特沃斯低通滤波器 d0=40; %截止频率50 m=fix(M/2); n=fix(N/2); for i=1:M for j=1:N d=sqrt((i-m)^2+(j-n)^2); h=1/(1+0.414*(d/d0)^(2*nn)); % 计算低通滤波器传递函数 result(i,j)=h*g(i,j); end end result=ifftshift(result); y2=ifft2(result); y3=uint8(real(y2));% 显示处理后的图像 imwrite(y3,'ditong.jpg') subplot(133); subimage(y3); title('低通滤波器滤波后图像');

6、低通滤波后频谱图 x=imread('hua.jpg','jpg'); j=imread('jy.jpg','jpg'); a=imread('ditong.jpg','jpg'); F=fft2(x); F1=fftshift(F); subplot(131); imshow(log(abs(F1)),[8,10]); title('原始图像频谱'); F2=fft2(j); F3=fftshift(F2); subplot(132); imshow(log(abs(F3)),[8,10]); title('加入椒盐噪声频谱'); F4=fft2(a); F5=fftshift(F4); subplot(133); imshow(log(abs(F5)),[8,10]); title('低通滤波频谱');

二阶巴特沃斯低通滤波 低通滤波频谱

相关主题