初始界面
导入图像
[fn,pn,~]=uigetfile('*.jpg','请选择要处理的图片');
I=imread([pn fn]);
imshow(I)
title('原图像');
handles.image = I;
guidata(hObject,handles)
图像旋转
J = imrotate(I,-45,'crop');%旋转图形
镜像图片
J = flipdim(I,2);%原图像的垂直镜像
边缘提取
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-1
for y = 2:N-1
BW4(x,y) = I(x+1,y) + I(x-1,y) + I(x,y+1) + I(x,y-1) - 4*I(x,y);
end;
end
对比度增强
X = 0.7;
image = im2double(image1);
image2 = (image .^ X);%进行幂律变换
灰度线性反转
img=-img+255; %图像反转线性变换
二值图像
gdata = rgb2gray(I);
j=imbinarize(gdata);
图像腐蚀
j=imbinarize(gdata);
se=eye(5);
bw=bwmorph(j,'erode');
索引图像
y=grayslice(gdata,16);
图像裁剪
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:N1
for 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>30
result2(i,j) = 0;
else
result2(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));
空间滤波