傅里叶变换之低通滤波、sobel边缘检测之matlab实现
滤波是傅里叶变换的一个主要应用,因为在频域中可以更好的理解图像以及了解如何对它进行处理。
以下是低通滤波的:
function output = low_filter(image,value)
%Retain centred transform components inside circle of radius
%
% Usage: new image = low_filter(image,number)
%
% Parameters: image - array of points
% value - radius of filter
%get dimensions
[rows,cols]=size(image);
%filter the transform
for x = 1:cols %address all columns
for y = 1:rows %address all rows
if (((y-(rows/2))^2)+((x-(cols/2))^2)-(value^2))>0
output(y,x)=0; %discard components outside the circle
else
output(y,x)=image(y,x); %and keep the ones inside
end
end
end
计算哈特利变换
输出真实的图像作为结果:
function trans = Hartley(image)
% Usage: [new image] = Hartley(image)
%
% Parameters: image - array of points
%get dimensions
[rows,cols]=size(image);
trans(1:rows,1:cols)=0;
%compute transform
for u = 1:cols %address all columns
for v = 1:rows %address all rows
sum=0;
for x = 1:cols %address all columns
for y = 1:rows %address all rows
%Eq. 2.41
mux=2*pi*(u-1)*(x-1)/cols;
nvy=2*pi*(v-1)*(y-1)/rows;
sum=sum+(image(y,x)*(cos(nvy)+sin(nvy))*(cos(mux)+sin(mux)));
end
end
trans(v,u)=sum/sqrt(rows*cols);
end
end
sobel 边缘检测
function edge = Sobel_edges(image)
% Gives Sobel for Canny operator
%
% Usage: [new image] = Sobel_edges(image)
%
% Parameters: image - array of points
%get dimensions
[rows,cols]=size(image);
%set the output image to black (0)
edge(1:rows,1:cols,3)=0;
%then form the difference
for x = 2:cols-1 %address all columns except border
for y = 2:rows-1 %address all rows except border
Sobel_y=image(y+1,x+1)+2*image(y+1,x)+image(y+1,x-1)-...
image(y-1,x+1)-2*image(y-1,x)-image(y-1,x-1);
Sobel_x=image(y-1,x+1)+2*image(y,x+1)+image(y+1,x+1)-...
image(y-1,x-1)-2*image(y,x-1)-image(y+1,x-1);
edge(y,x,1)=Sobel_x;
edge(y,x,2)=Sobel_y;
edge(y,x,3)=floor(sqrt(Sobel_x*Sobel_x+Sobel_y*Sobel_y));
end
end
参考资料:计算机视觉特征提取与图像处理 Mark S.Mixon