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

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

界面的设计以中值滤波和低通滤波为例,界面设计如图,代码如下:

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中值滤波频谱');

中值滤波

中值滤波频谱

相关文档
最新文档