BW1=edge(I,'Roberts');%Roberts算子
BW2=edge(I,'Prewitt');%Prewitt算子
BW3=edge(I,'Sobel');%Sobel算子
[M,N]=size(I);%拉普拉斯算子
BW4=zeros(size(I));for x =2:M-1for y =2:N-1BW4(x,y)=I(x+1,y)+I(x-1,y)+I(x,y+1)+I(x,y-1)-4*I(x,y);
end;
end
waitforbuttonpress;
clf;I= handles.image;I2=imcrop(I);
close
添加椒盐噪声
J=imnoise(I,'salt & pepper',number);
添加高斯噪声
J=imnoise(I,'gaussian',number);%添加高斯噪声
频率滤波
f =double(I2);
g =fft2(f);
g =fftshift(g);[N1,N2]=size(g);
n =2;
d0 =50;
n1 =fix(N1/2);
n2 =fix(N2/2);for i =1:N1for j =1:N2
d =sqrt((i - n1)^2+(j - n2)^2);% Buttetworth低通滤波
h =1/(1+(d/d0)^(2*n));result1(i,j)= h*g(i,j);% 理想低通滤波
if d>30result2(i,j)=0;elseresult2(i,j)=g(i,j);
end
end
end
result1 =ifftshift(result1);
result2 =ifftshift(result2);X2=ifft2(result1);X3=uint8(real(X2));X4=ifft2(result2);X5=uint8(real(X4));