图像Radon变换与傅里叶变换(matlab)

图像变化的介绍

图像变换是将图像从空间域变换到变换域。图像变换的目的是根据图像在变换域的某些性质对其处理。通常这些性质在空间域内很难获取。在变换域内处理结束后,将处理的结果进行反转变换到空间域。

我们所看到的图像是在空域上的,其信息具有很强的相关性,所以经常将图像信息通过某种数学方式变换到其他正交矢量空间上。一般称原始图像为空间域图像,称变换后的图像为变化域图像,变换域的图像可反变换为空间域图像。

变换后的图像,一方面能够有效的反映图像自身特征,另一方面也可使能量集中在少量数据上,有利于图像存储、传输及处理。数学角度来看,图像变换是把图像中的像素表达成“另一种形式”满足实际需求,大多数情况下需要对变换处理后的图像进行逆变换,从而获取处理以后的图像。

图像Radon变换

对给定的图像f(x,y),它在给定坐标系XOY中,沿着某一个投影方向,对每一条投影线计算断层平面f(x,y)的线性积分,就得到该射线上的投影值g(R,θ),其表达式:
在这里插入图片描述

Radon正变换的实现

R = radon(I,theta)
[R,xp] = radon(…)
theta:角度
xp:返回对应的坐标值
对图像进行0°和45°方向上的Radon变换:

>> I(50:150,50:150) = 1;
>> [R,xp] = radon(I,[0,45]);%Radon变换
>> figure,
>> subplot(131),imshow(I); 
>> subplot(132),plot(xp,R(:,1));%0°变换结果
>> subplot(133),plot(xp,R(:,2));%45°变换结果

在这里插入图片描述

计算多个角度的Radon变换,并将这些曲线绘制在一个坐标抽中,表示为一幅图像:

>> I = zeros(200,200);
>> I = ones(200,200);
>> I(50:150,50:150) = 0;
>> theta = 0:10:180;
>> [R,xp] = radon(I,theta);
>> figure,
>> subplot(121),imshow(I);
>> subplot(122),imagesc(theta,xp,R);%绘制各个角度的Radon变换结果
>> colormap(hot);%设置调色板
>> colorbar;%添加颜色条

在这里插入图片描述
通过Radon变换来检测直线:

>> I = imread('E:\persional\matlab\images\house.tif');
>> J = im2double(I);
>> BW = edge(J);%获取边缘
>> figure,
>> subplot(121),imshow(J);
>> subplot(122),imshow(BW);
>> theta = 0:179;%角度
>> [R,xp] = radon(BW,theta);%Radon变换
>> figure,
>> imagesc(theta,xp,R);%显示变换结果
>> colormap(hot);%添加调色板
>> colorbar;%添加颜色条
>> Rmax = max(max(R));%获取最大值
>> [row,column] = find(R>=Rmax);%获取行和列值
>> x = xp(row);%获取位置
>> angel = theta(column);获取角度
>> Rmax

Rmax =

   188

>> row

row =

   649

>> column

column =

     1

>> x

x =

   222

>> angel

angel =

     0

在这里插入图片描述
角度0°到179°每一度做Radon变换。颜色越亮,表示系数越大。该点对应得直线是原图像中最明显得直线。Radon变换结果得最大值为:188,angel:0,x=222。
在这里插入图片描述

Radon反变换的实现

I = iradon(R,theta)
R:Radon变换矩阵,theta为角度

通过Radon反变换来恢复图像:

>> I = imread('E:\persional\matlab\images\house.tif');
>> theta = 0:2:179;
>> [R,xp] = radon(I,theta);%Radon变换
>> J = iradon(R,theta);%Radon反变换
>> figure,
>> subplot(131),imshow(uint8(I));
>> subplot(132),imagesc(theta,xp,R);%变换结果
>> axis normal;
>> subplot(133),imshow(uint8(J));

在这里插入图片描述

投影角度得多少对Radon变换和反变换得影像:

>> I=phantom(256);
>> theta1 = 0:10:179;
>> theta2 = 0:5:179;
>> theta3 = 0:2:179;
>> [R1,xp] = radon(I,theta1);
>> [R2,xp] = radon(I,theta2);
>> [R3,xp] = radon(I,theta3);
>> figure,%显示不同角度得Radon变换
>> subplot(221),imshow(I);
>> subplot(222),imagesc(thetal,xp,R1);
>> subplot(223),imagesc(theta2,xp,R2);
>> subplot(224),imagesc(theta3,xp,R3);
>>> colormap hot;
>> colorbar;

在这里插入图片描述

>> J1 = iradon(R1,10);
>> J2 = iradon(R2,5);
>> J3 = iradon(R3,2);
>> figure,
>> subplot(131),imshow(J1);%显示图像进行Radon反变换
>> subplot(132),imshow(J2);
>> subplot(133),imshow(J3);

采用的角度越多(角度间隔越小),图像越清晰
在这里插入图片描述

图像傅里叶变换

傅里叶变换是一种常用得正交变换,可以进行图像分析、图像增强和图像压缩。

对于离散序列f(x),其一维离散傅里叶变换定义为:其中N为长度,μ=0,1,…,N-1
在这里插入图片描述
F(u)得一维离散傅里叶反转换定义为:
在这里插入图片描述
同连续傅里叶变换一样,对于离散函数f(x,y),其中x = 0,1,…,M-1;y = 0,1,…,N-1,二维离散傅里叶变换定义为:其中μ = 0,1,…,M-1;v = 0,1,…,N-1
在这里插入图片描述
F(u,v)的二维离散傅里叶反转变换定义为:其中x = 0,1,…,M-1;y = 0,1,…,N-1,u和v是频率变量
在这里插入图片描述
二维傅里叶变换的性质:可分性、线性、共轭对称性,位移性,尺度变换性,旋转不变性,卷机性和DC系数

傅立叶变换的实现

Y = fft2(X)
Y = fft2(X,m,n)
X:计算矩阵,与Y的大小相同
m,n:采用快递FFT算法,计算矩阵大小为m×n的二维离散傅里叶变换,如果矩阵小于m×n,则用0补全

矩阵的二维离散傅里叶变换

>> I1 = ones(4);
>> I2 = [2 2 2 2;1 1 1 1;3 3 0 0;0 0 0 0];
>> J1 = fft2(I1);%傅里叶变换
>> J2 = fft2(I2);
>> I1

I1 =

     1     1     1     1
     1     1     1     1
     1     1     1     1
     1     1     1     1

>> J1

J1 =

    16     0     0     0
     0     0     0     0
     0     0     0     0
     0     0     0     0

>> I2

I2 =

     2     2     2     2
     1     1     1     1
     3     3     0     0
     0     0     0     0

>> J2

J2 =12

  18.0000 + 0.0000i   3.0000 - 3.0000i
   2.0000 - 4.0000i  -3.0000 + 3.0000i
  10.0000 + 0.0000i   3.0000 - 3.0000i
   2.0000 + 4.0000i  -3.0000 + 3.0000i

  列 34

   0.0000 + 0.0000i   3.0000 + 3.0000i
   0.0000 + 0.0000i  -3.0000 - 3.0000i
   0.0000 + 0.0000i   3.0000 + 3.0000i
   0.0000 + 0.0000i  -3.0000 - 3.0000i

图像的二维离散傅里叶变换

>> I=imread('E:\persional\matlab\images\lena.bmp');
>> I=imread('E:\persional\matlab\images\house.tif');
>> I = im2double(I);
>> J = fft2(I);%傅里叶变换
>>> K = abs(J/256);
>> figure,
>> subplot(131),imshow(I);
>> subplot(132),imshow(J);
>> subplot(133),imshow(K);%频谱图

在这里插入图片描述
可以通过fft2shift将坐标原点移到频谱图窗口中央,坐标原点是低频,向外是高频
Y = fft2shift(X)
X:傅里叶变换后的结果
Y:纠正零频后的图像频谱分布
还可以通过iffshift()函数进行傅里叶反平移

通过函数ffshift()进行平移:

>> N=0:10;
>> X = fftshift(N);%平移
>> Y = fftshift(fftshift(N));%平移后在平移
>> Z = ifftshift(fftshift(N));%平移后再进行反平移
>> N

N =18

     0     1     2     3     4     5     6     7911

     8     9    10

>> X

X =18

     6     7     8     9    10     0     1     2911

     3     4     5

>> Y

Y =18

     1     2     3     4     5     6     7     8911

     9    10     0

>> Z

Z =18

     0     1     2     3     4     5     6     7911

     8     9    10

>> 

图像进行傅里叶变换和平移

>> I=imread('E:\persional\matlab\images\paopao.tif');
>> K = fft2(J);%傅里叶变换
>> K = fftshift(K);%平移
>> L = abs(K/256);
>> figure,
>> subplot(121),imshow(I);
>> subplot(122),imshow(L);

在这里插入图片描述
图像变亮进行傅里叶变换:

>> I=imread('E:\persional\matlab\images\paopao.tif');
>> J = I*1.5;%图像增强
>> J(find(J>255))=255;
>> K=fft2(J);%傅里叶变换
>> K=fftshift(K);%平移
>> L=abs(K/256);
>> figure,
>> subplot(121),imshow(J);
>> subplot(122),imshow(uint8(L));%显示频谱图

在这里插入图片描述
图像旋转后进行傅里叶变换:

>> I=imread('E:\persional\matlab\images\paopao.tif');
>> J = imrotate(I,45,'bilinear');%图像旋转
>> K = fft2(J);%傅里叶变换
>> K = fftshift(K);%平移
>> L = abs(K/256);
>> figure,
>> subplot(121),imshow(J);
>> subplot(122),imshow(uint8(L));%显示频谱图

在这里插入图片描述
图像添加高斯噪声后进行傅里叶变换:

>> I=imread('E:\persional\matlab\images\paopao.tif');
>> J = imnoise(I,'gaussian',0,0.01);%添加噪声
>> K = fft2(J);%傅里叶变换
>> K = fftshift(K);%平移
>> L = abs(K/256);
>> figure,
>> subplot(121),imshow(J);
>> subplot(122),imshow(uint8(L));%显示频谱图

在这里插入图片描述

二维快速傅里叶反转变换

Y = ifft2(X);
Y = ifft2(X,m,n)
该函数与fft2()互为反函数
X:计算矩阵,与Y的大小相同
m,n:采用快递FFT算法,计算矩阵大小为m×n的二维离散傅里叶变换,如果矩阵小于m×n,则用0补全

>> I=imread('E:\persional\matlab\images\paopao.tif');
>> K = fft2(I);%傅里叶变换
>> L = fftshift(K);%平移
>> M = ifft2(K);%傅里叶反转函数
>> figure,
>> subplot(121),imshow(uint8(abs(L)/256));%显示频谱图
>> subplot(122),imshow(uint8(M));%反转后得到的图像

在这里插入图片描述
灰度图像的幅值谱和相位谱:

>> I=imread('E:\persional\matlab\images\paopao.tif');
>> K = fft2(I);
>> L = fftshift(K);
>> fftr = real(L);%返回数组每个元素的实部
>> ffti = imag(L);%返回数组每个元素的虚部
>> A = sqrt(fftr.^2+ffti.^2);%幅值谱
>> A = (A-min(min(A)))/(max(max(A))-min(min(A)))*255;%归一化
>> B = angle(K);%相位谱
>> figure,
>> subplot(121),imshow(A);
>> subplot(122),imshow(real(B));

在这里插入图片描述

通过傅里叶变换识别图像中匹配的图像

>> I = imread('E:\persional\matlab\images\ba.tif');
>> a = imread('E:\persional\matlab\images\ball.png');
>> I = im2double(I);
>> a = rgb2gray(a);
>> a = im2double(a);
>> a = im2double(a);
>> c = real(ifft2(fft2(I).*fft2(rot90(a,2),600,600)));
>> figure,
>> subplot(121),imshow(c,[]);
>> max(c(:));
>> thresh = 1024;
>> subplot(122),imshow(c>thresh);

在这里插入图片描述

对图像进行巴特低通滤波器:
低通滤波:H(u,v) = 1/(1+[D(u,v)/D0]2n)
高通滤波:H(u,v) = 1/(1+[D0/D(u,v)]2n)

对图像进行巴特沃斯低通滤波:

>> I = imread('E:\persional\matlab\images\house.tif');
>> I = im2double(I);
>> J = fftshift(fft2(I));%傅里叶变换平移
>> [x,y] = meshgrid(-300:299,-300:299);%产生离散数据
>> z = sqrt(x.^2+y.^2);
>> D1 = 10;D2=30;%截至频率
>> n=6;%滤波器阶数
>> H1 = 1./(1+(z/D1).^(2*n));%滤波器
>> H2 = 1./(1+(z/D2).^(2*n));
>> K1 = J.*H1;%滤波
>> K2 = J.*H2;
>> L1=ifft2(ifftshift(K1));%傅里叶反变换
>> L2=ifft2(ifftshift(K2));
>> figure,
>> subplot(131),imshow(I);
>> subplot(132),imshow(real(L1));
>> subplot(133),imshow(real(L2));

在这里插入图片描述

对图像进行巴特沃斯高通滤波:

>> I = imread('E:\persional\matlab\images\house.tif');
>> I = im2double(I);
>> J = fftshift(fft2(I));
>> [x,y] = meshgrid(-300:299,-300:299);
>> z = sqrt(x.^2+y.^2);
>> D1 = 10;D2=30;
>> n1=2;n2=6;
>> H1 = 1./(1+(D1./z).^(2*n1));
>> H2 = 1./(1+(D2./z).^(2*n2));
>> K1 = J.*H1;
>> K2 = J.*H2;
>> L1=ifft2(ifftshift(K1));
>> L2=ifft2(ifftshift(K2));
>> figure,
>> subplot(131),imshow(I);
>> subplot(132),imshow(real(L1));
>> subplot(133),imshow(real(L2));

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_56260304/article/details/127628704