Image Radon transform and Fourier transform (matlab)

Introduction to image changes

Image transformation is to transform an image from the spatial domain to the transform domain. The purpose of image transformation is to process the image according to some properties in the transform domain. Usually these properties are difficult to obtain in the spatial domain. After the processing in the transform domain is completed, the result of the processing is inverted and transformed into the space domain.

The image we see is in the air domain, and its information has a strong correlation, so the image information is often transformed into other orthogonal vector spaces by some mathematical method. Generally, the original image is called a space domain image, and the transformed image is called a change domain image, and an image in the transform domain can be inversely transformed into a space domain image.

The transformed image, on the one hand, can effectively reflect the characteristics of the image itself, on the other hand, it can also concentrate energy on a small amount of data, which is beneficial to image storage, transmission and processing. From a mathematical point of view, image transformation is to express the pixels in the image into "another form" to meet actual needs. In most cases, it is necessary to inversely transform the transformed image to obtain the processed image.

Image Radon transform

For a given image f(x,y), it calculates the linear integral of the tomographic plane f(x,y) for each projection line along a certain projection direction in a given coordinate system XOY, and the ray is obtained On the projected value g(R, θ), its expression:
insert image description here

Realization of Radon forward transformation

R = radon(I,theta)
[R,xp] = radon(...)
theta: angle
xp: returns the corresponding coordinate value
to perform Radon transformation on the image in the direction of 0° and 45°:

>> 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°变换结果

insert image description here

Compute the Radon transform for multiple angles and plot these curves in a coordinate pump, represented as an image:

>> 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;%添加颜色条

insert image description here
Detect straight lines by Radon transform:

>> 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

insert image description here
Radon transformation is performed for each degree of angle 0° to 179°. Brighter colors indicate larger coefficients. The straight line corresponding to this point is the most obvious straight line in the original image. The maximum value of the Radon transformation result is: 188, angel: 0, x=222.
insert image description here

Realization of Radon Inverse Transformation

I = iradon(R,theta)
R: Radon transformation matrix, theta is the angle

Restore the image by inverse Radon transform:

>> 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));

insert image description here

How much is the projection angle for Radon transform and inverse transform images:

>> 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;

insert image description here

>> 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);

The more angles used (smaller angle intervals), the sharper the image
insert image description here

Image Fourier transform

Fourier transform is a commonly used orthogonal transform for image analysis, image enhancement and image compression.

For a discrete sequence f(x), its one-dimensional discrete Fourier transform is defined as: where N is the length, μ=0,1,...,N-1 F(u) and the one-dimensional discrete
insert image description here
Fourier inverse transform is defined as :
insert image description here
Same as continuous Fourier transform, for discrete function f(x,y), where x = 0,1,…,M-1; y = 0,1,…,N-1, two-dimensional discrete Fourier transform The transformation is defined as: where μ = 0,1,…,M-1; v = 0,1,…,N-1 The
insert image description here
two-dimensional inverse discrete Fourier transform of F(u,v) is defined as: where x = 0,1,...,M-1; y = 0,1,...,N-1, u and v are the properties of the frequency variable two-dimensional
insert image description here
Fourier transform: separability, linearity, conjugate symmetry, displacement , scale transformability, rotation invariance, winding and DC coefficient

Implementation of the Fourier Transform

Y = fft2(X)
Y = fft2(X,m,n)
X: Calculation matrix, the same size as Y
m,n: Express FFT algorithm is used to calculate the two-dimensional discrete Fourier transform of the matrix size m×n , if the matrix is ​​smaller than m×n, fill it with 0

2D discrete Fourier transform of a matrix

>> 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

2D discrete Fourier transform of an image

>> 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);%频谱图

insert image description here
You can use fft2shift to move the coordinate origin to the center of the spectrogram window. The coordinate origin is low frequency and outward is high frequency
Y = fft2shift(X)
X: The result after Fourier transform
Y: The image spectrum distribution after correcting zero frequency
is OK Fourier inverse translation by iffshift() function

Translate through the function 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

>> 

Images are Fourier transformed and translated

>> 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);

insert image description here
The image is brightened and Fourier transformed:

>> 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));%显示频谱图

insert image description here
Perform Fourier transform after image rotation:

>> 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));%显示频谱图

insert image description here
The image is Fourier transformed after adding Gaussian noise:

>> 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));%显示频谱图

insert image description here

2D Inverse Fast Fourier Transform

Y = ifft2(X);
Y = ifft2(X,m,n)
This function is the inverse function of fft2()
X: Calculation matrix, the same size as Y
m,n: Using express FFT algorithm, the size of the calculation matrix is Two-dimensional discrete Fourier transform of m×n, if the matrix is ​​smaller than m×n, it is filled with 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));%反转后得到的图像

insert image description here
Magnitude and phase spectra of a grayscale image:

>> 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));

insert image description here

Identify matching images in images by Fourier transform

>> 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);

insert image description here

Apply a Barth low-pass filter to the image:
Low-pass filter: H(u,v) = 1/(1+[D(u,v)/D 0 ] 2n )
High-pass filter: H(u,v) = 1/ (1+[D 0 /D(u,v)] 2n )

Apply Butterworth low-pass filtering to an image:

>> 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));

insert image description here

Apply Butterworth high-pass filtering to an image:

>> 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));

insert image description here

Guess you like

Origin blog.csdn.net/weixin_56260304/article/details/127628704