(Digital Image Processing MATLAB+Python) Chapter 4 Image Orthogonal Transformation - Sections 4 and 5: Radon Transform and Wavelet Transform

One: Radon transform

Radon transform : is a mathematical tool used to transform images from the spatial domain to the projection domain. The basic idea is to project the gray value of each point in the image onto a set of straight lines, and then merge these projections together to form projection domain. Radon transform can be used for a variety of image processing tasks, including image reconstruction, feature extraction, image segmentation, etc.

(1) Radon transform principle

Radon transformation principle : given a function f ( x , y ) f(x, y)f(x,y ) , the Radon transformation projects it onto a set of lines to get a set of projection values​​p ( θ , s ) p(\theta, s)p ( θ ,s ) . θ \thetaθ represents the angle of the projection line,sss represents the distance of the projection line from the origin. Specifically, for each angleθ \thetaθ , the Radon transform will be on the linel θ , s l_{\theta,s}li , sThe pair function f ( x , y ) f(x, y)f(x,y ) , wherel θ , s l_{\theta,s}li , sis the distance ss from the origins , withxxThe x- axis becomesθ \thetaA straight line at an angle θ . Projection valuep ( θ , s ) p(\theta, s)p ( θ ,s ) is the integral result

insert image description here

The Radon transform can be thought of as a mapping from a two-dimensional function to a one-dimensional function, where each projection value p ( θ , s ) p(\theta, s)p ( θ ,s ) represents the projection linel θ , s l_{\theta,s}li , sOne-dimensional information on . Therefore, the Radon transform can be used to reconstruct the original function f ( x , y ) f(x, y) from a set of projected valuesf(x,y ) . This inverse transformation is known as the inverse Radon transform or backprojection

(2) Radon transform implementation

MATLAB implementation : the relevant functions are as follows, for detailed explanation, please refer to the MATLAB help manual

  • [R,xp]=radon(I,theta): Radon transform is a method for feature extraction in image processing, which can be used to detect straight line features in images
    • Ifor the input image
    • thetato transform the angle
    • Rfor the transformed result
    • xpfor the transformed coordinates

Procedure 1 : Perform Radon transformation on the image in the specified direction

  • First, the code reads the grayscale image named 'block.bmp' and performs Radon transformation on it at 0 degrees and 45 degrees respectively
  • Then, use the subplot function to display the original image and the two transformed images in the same image for easy comparison
  • Finally, the code shows the Radon transformation curves of the two transformed images, corresponding to the 0-degree and 45-degree orientations. These curves can be used to detect straight line features in images
clear,clc,close all;
Image=rgb2gray(imread('block.bmp'));
[R1,X1]=radon(Image,0);
[R2,X2]=radon(Image,45);
subplot(131),imshow(Image),title('原图');
subplot(132),plot(X1,R1),title('0度方向的radon变换曲线');
subplot(133),plot(X2,R2),title('45度方向的radon变换曲线');

insert image description here

Program 2 : Radon transform and inverse transform on the image

  • First, it reads an image called "block.bmp" and converts it to a grayscale image
  • It then computes the set of Radon transformation curves for the image in the direction of 0 to 180 degrees using the "radon" function and finds the maximum of these curve sets
  • It then inversely transforms these curves using the "iradon" function to reconstruct the original image
  • Finally, it uses the "subplot" function to display the original image, the set of Radon transformation curves, and the reconstructed image on the same plot
clear,clc,close all;
Image=rgb2gray(imread('block.bmp'));
theta=0:10:180;
[R,X]=radon(Image,theta);
C=max(R);
result=iradon(R,theta);
subplot(131),imshow(Image),title('原图');
subplot(132),imagesc(theta,X,R),title('0-180度方向的radon变换曲线集合');
subplot(133),image(result),title('重建图像');

insert image description here

Python implementation : use Python to achieve the same function as above

Procedure 1 : Perform Radon transformation on the image in the specified direction

import cv2
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']

# Load the image
Image = cv2.imread('block.bmp', cv2.IMREAD_GRAYSCALE)

# Perform Radon transform
theta = np.arange(0, 180, 1)
R = cv2.radon(Image, theta)

# Display the results
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(10, 5))
ax1.imshow(Image, cmap='gray')
ax1.set_title('Original Image')
ax2.plot(R[:, 0])
ax2.set_title('Radon Transform (0 degrees)')
ax3.plot(R[:, 45])
ax3.set_title('Radon Transform (45 degrees)')
plt.show()

Program 2 : Radon transform and inverse transform on the image

import cv2
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']

# Load the image
Image = cv2.imread('block.bmp', cv2.IMREAD_GRAYSCALE)

# Perform Radon transform
theta = np.arange(0, 181, 10)
R = cv2.radon(Image, theta)

# Get the maximum value of the Radon transform
C = np.max(R)

# Perform inverse Radon transform
result = cv2.remap(R, theta, None, cv2.INTER_LINEAR)

# Display the images using matplotlib
fig, axs = plt.subplots(1, 3, figsize=(10, 10))
axs[0].imshow(Image, cmap='gray')
axs[0].set_title('Original Image')
axs[1].imshow(R, cmap='gray', extent=(0, 180, 0, R.shape[0]), aspect='auto')
axs[1].set_title('Radon Transform')
axs[2].imshow(result, cmap='gray')
axs[2].set_title('Reconstructed Image')
plt.show()

(3) Radon transform properties

Linear : The Radon transform is linear. That is, for any constant a , ba,ba,b and functionsf , gf , gf,g , the following equation holds

R { a f + b g } = a R { f } + b R { g } \mathcal{R}\{a f+b g\}=a \mathcal{R}\{f\}+b \mathcal{R}\{g\} R { a f+bg}=aR{ f}+bR{ g}

where R ⋅ \mathcal{R}{\cdot}R represents the Radon transform. This property means that the Radon transform of the original functions can be computed by performing a linear combination of

Translation : Radon transform is translation invariant. That is, for a function f ( x , y ) f(x,y)f(x,y ) and distance vectord = ( dx , dy ) d=(d_x,d_y)d=(dx,dy) , the following equation holds

R { f ( x − dx , y − dy ) } ( θ , s ) = R { f ( x , y ) } ( θ , s − dx cos ⁡ θ − dy sin ⁡ θ ) \mathcal{R}\left \{f\left(x-d_{x}, y-d_{y}\right)\right\}(\theta,s)=\mathcal{R}\{f(x,y)\}\left (\theta, s-d_{x}\cos \theta-d_{y}\sin\theta\right)R{ f(xdx,ydy)}( i ,s)=R{ f(x,y)}( i ,sdxcosidysini )

This property means that the Radon transform at different positions can be calculated by translating the original function

Similarity : Radon transformation is invariant to similar transformation. That is, for a function f ( x , y ) f(x,y)f(x,y ) and scaling factoraaa , the following equation holds

R { f ( a x , a y ) } ( θ , s ) = 1 ∣ a ∣ R { f ( x , y ) } ( θ , s ∣ a ∣ ) \mathcal{R}\{f(a x, a y)\}(\theta, s)=\frac{1}{|a|} \mathcal{R}\{f(x, y)\}\left(\theta, \frac{s}{|a|}\right) R{ f(ax,a y )} ( θ ,s)=a1R{ f(x,y)}( i ,as)

Differential : The Radon transform has differential properties. That is, for a function f ( x , y ) f(x,y)f(x,y ) , the following equation holds

∂ ∂ s R { f ( x , y ) } ( θ , s ) = − ∫ − ∞ ∞ ∂ ∂ y f ( x , y ) cos ⁡ θ − ∂ ∂ x f ( x , y ) sin ⁡ θ d x \frac{\partial}{\partial s} \mathcal{R}\{f(x, y)\}(\theta, s)=-\int_{-\infty}^{\infty} \frac{\partial}{\partial y} f(x, y) \cos \theta-\frac{\partial}{\partial x} f(x, y) \sin \theta d x sR{ f(x,y )} ( i ,s)=yf(x,y)cosixf(x,y)sinθdx

This property means that the derivative of the original function can be computed by differentiating the Radon transform

(4) Radon transform application

Radon transform application :

  • CT image reconstruction : Computed tomography (CT) is a medical imaging technique that uses X-ray scans of the human body to obtain three-dimensional images of its internal structures. CT images can be reconstructed by Radon transform, which converts projection data from CT scans into image data. This is due to the fact that a CT scan is a series of projection images acquired in different directions, and the Radon transform can convert these projection data into image data
  • Edge Detection : Edges are one of the most important features in an image because they can provide information about the outline and shape of objects in the image. The Radon transform can be used to detect edges because edges exhibit distinct features in the projected domain. Edge positions in the original image can be determined by detecting peaks in the Radon transformed image
  • Feature extraction : The Radon transform can also be used to extract other features in images such as texture and shape. By calculating the angle distribution function of Radon transform, the information of texture and shape in the image can be obtained
  • Image Segmentation : Image segmentation is the process of dividing an image into several non-overlapping regions. Radon transform can be used for image segmentation because the projection data of different regions exhibit different characteristics in the projection domain. By analyzing the Radon transformed image, the position of different regions in the original image can be determined

Two: wavelet transform

Wavelet transform : is a mathematical tool used to decompose a signal into its different frequency components . Similar to spectral analysis, but wavelet transform can capture time and frequency information in transient signals. In simple terms, it can divide a signal into multiple sub-signals of different time lengths and frequency ranges to better understand and process the original signal

(1) Wavelet

A: Definition

Wavelet : The "wavelet" in wavelet transform refers to a basic function that can be used to decompose a signal into its different frequency components. These wavelet functions have compact supports and variable frequency and time resolutions, making them convertible between time and frequency domains and better capturing local features in signals. Mathematically, a wavelet is a local finite energy function that can satisfy certain conditions, and is usually defined as a linear combination of a wave function and a scale function with a mean value of zero . By performing the inner product operation on the signal and the wavelet function of different scales and positions, the decomposition coefficients of the signal at different frequencies can be obtained, and then the wavelet transform can be realized. Let the function ψ ( t ) \psi(t)ψ(t)满足 ∫ R ψ ( t ) d t = 0 \int_{R} \psi(t) d t=0 Rψ(t)dt=0 , translate and stretch it to generate a family of functions:ψ a , b ( t ) = 1 a ψ ( t − ba ) , a , b ∈ R , a ≠ 0 \psi_{a, b}(t)= \frac{1}{\sqrt{a}} \psi\left(\frac{tb}{a}\right),a,b\in R,a\not=0pa,b(t)=a 1p(atb),a,bR,a=0ψ ( t ) \psi(t)ψ ( t ) is called base wavelet or mother wavelet,α \alphaα is the scaling factor,bbb is the translation factor,ψ a , b ( t ) \psi_{a,b}(t)pa,b( t )ψ ( t ) \psi(t)ψ ( t ) generated continuous wavelet. Wavelets have the following characteristics

  • Tight support : the wavelet function fluctuates in a small range, and the energy is limited. When it exceeds a certain range, the fluctuation amplitude decays rapidly and has the property of rapid drop
  • Variability : The wavelet function changes with the scale factor
  • K K K阶消失矩 ∫ R t k Ψ ( t ) d t = 0 , k = 0 , 1 , ⋯   , K − 1 \begin{array}{l}\int_{R} t^{k} \Psi(t) d t=0 ,\quad k=0,1, \cdots, K-1\end{array} RtkΨ(t)dt=0,k=0,1,,K1

B: Example

Haar wavelet : The figure below shows the Harr wavelet and its spectrum

{ Ψ H ( t ) = { 1 0 ≤ t < 1 / 2 − 1 1 / 2 ≤ t < 1 0  其他  Ψ H ( ω ) = 1 − 2 e i ω 2 + e − i ω ω i \left\{\begin{array}{l}\Psi_{H}(t)=\left\{\begin{array}{cc}1 & 0 \leq t<1 / 2 \\-1 & 1 / 2 \leq t<1 \\0 & \text { 其他 }\end{array}\right. \\\Psi_{H}(\omega)=\frac{1-2 e^{\frac{i \omega}{2}}+e^{-i \omega}}{\omega i}\end{array}\right. PsH(t)= 1100t<1/21/2t<1  OtherPsH( oh )=ωi1 2 e2+e

insert image description here

Morlet wavelet : The figure below shows the Morlet wavelet and its spectrum

{ Ψ ( t ) = π − 1 / 4 ( e − i ω 0 t − e − ω ​​0 2 / 2 ) e − t 2 / 2 Ψ ( ω ) = π − 1 / 4 [ e − ( ω − ω 0 ) 2 / 2 − e − ω ​​0 2 / 2 e − ω ​​2 / 2 ] \left\{\begin{array}{l}\Psi(t)=\pi^{-1/4}\left( e^{-i \omega_{0} t}-e^{-\omega_{0}^{2}/2}\right) e^{-t^{2}/2} \\\Psi(\ omega)=\pi^{-1/4}\left[e^{-\left(\omega-\omega_{0}\right)^{2}/2}-e^{-\omega_{0} ^{2}/2} e^{-\omega^{2}/2}\right]\end{array}\right. Ψ ( t )=Pi1/4(ei ω0te- Oh02/2)et2/2Ψ ( ω )=Pi1/4[e( ω ω0)2/2e- Oh02/ 2e- Oh2/2]

insert image description here

Mexico straw hat wavelet : The figure below shows the Mexico straw hat wavelet and its spectrum

Ψ ( t ) = ( 2 3 π − 1 / 4 ) ( 1 − t 2 ) e − t 2 / 2 \Psi(t)=\left(\frac{2}{\sqrt{3}} \pi^{-1 / 4}\right)\left(1-t^{2}\right) e^{-t^{2} / 2} Ψ ( t )=(3 2Pi1/4)(1t2)et2/2

insert image description here

(2) One-dimensional wavelet transform

A: Continuous wavelet transform

Continuous Wavelet Transform (CWT) : Given an original signal f ( t ) f(t)f ( t ) , and a wavelet functionψ ( t ) \psi(t)ψ ( t ) , CWT willf ( t ) f(t)f ( t ) ψ( t ) \psi(t)ψ ( t ) performs a series of scaling and translation operations to obtain a set of wavelet coefficientsC ψ ( a , b ) C_{\psi}(a,b)Cp(a,b ) , of whichaaa andbbb denote scale (scaling factor) and displacement (translation factor), respectively. CWT can be expressed by the following formula

  • ψ ( t ) \psi_(t)p(t ) represents the complex conjugate of the wavelet function
  • ψ ∗ ( t ) \psi^*(t)p (t)represents the complex conjugate operation, that is, the wavelet functionψ ( t ) \psi(t)The real part in ψ ( t ) becomes negative

C ψ ( a , b ) = 1 a ∫ − ∞ + ∞ f ( t ) ψ ∗ ( t − b a ) d t C_{\psi}(a, b)=\frac{1}{\sqrt{a}} \int_{-\infty}^{+\infty} f(t) \psi^{*}\left(\frac{t-b}{a}\right) d t Cp(a,b)=a 1+f ( t ) p(atb)dt

The physical meaning of CWT is to convert the signal f ( t ) f(t)f ( t ) is split into a series of wavelets of different scales and frequencies, so that the local characteristics of the signal can be better analyzed

B: Time-Frequency Characteristics

Time-frequency characteristics : refers to the time and frequency information that wavelet transform can provide . Unlike the Fourier transform, which only provides frequency information, the wavelet transform provides useful information in both the time and frequency domains

  • In the time domain, wavelet transform provides the local time information of the signal : wavelet functions of different scales can capture different frequency components of the signal, and wavelet functions of different positions can capture the local characteristics of the signal in different time periods. Therefore, the wavelet coefficients can reveal the short-term characteristics of the signal, and can be used to analyze the time-domain local characteristics of the signal
  • In the frequency domain, wavelet transform provides local frequency information of the signal : wavelet functions of different scales can capture signal components in different frequency ranges. Among wavelet coefficients, higher frequency wavelet coefficients are generally associated with high frequency components of a signal, and lower frequency wavelet coefficients are generally associated with low frequency components of a signal. Therefore, wavelet coefficients can be used to analyze the local characteristics of the frequency domain of the signal

Analysis wavelet ψ a , b ( t ) \psi_{a,b}(t)pa,b( t ) time, frequency window center and time, frequency window radius, we can get

  • Time window center : t ∗ = at ψ ∗ + bt^{*}=at^{*}_{\psi}+bt=atp+b
  • 时窗 radiusΔ t = a Δ t ψ \Delta t=a \Delta t_{\psi}Δt=aΔtp
  • Frequency window center : w ∗ = 1 aw ψ ∗ w^{*}=\frac{1}{a}w^{*}_{\psi}w=a1wp
  • 长窗radiusΔ w = 1 a Δ w ψ \Delta w=\frac{1}{a}\Delta w_{\psi}Δw=a1Δwp

t ψ ∗ , Δ t ψ , w ψ ∗ , Δ w ψ t^{*}_{\psi},\Delta t_{\psi},w^{*}_{\psi},\Delta w_{\psi psi}tp,Δtp,wp,Δwpis the base wavelet ψ ( t ) \psi(t)Time, frequency window center, radius of ψ ( t )

2 Δ t ⋅ 2 Δ ω = 4 a Δ t ψ ⋅ 1 a Δ ω ψ = 4 Δ t ψ ⋅ Δ ω ψ 2 \Delta t \cdot 2 \Delta \omega=4 a \Delta t_{\psi} \ cdot \frac{1}{a} \Delta \omega_{\psi}=4 \Delta t_{\psi} \cdot \Delta \omega_{\psi}t2D o=4aΔtpa1D op=tpD op

for fixed bbb,当 a > 1 a>1 a>1 o'clock, withaaAs a increases, the time window widens and the frequency window narrows, but the window area remains the same

Wavelet Transform Analyzes Signals with Adaptive Time-Frequency Window

  • Detect high-frequency components, scale parameter a > 0 a>0a>0 becomes smaller, the time window narrows, the frequency window increases, and the main frequencyω ∗ ω^{*}oh becomes larger
  • Detect low frequency features, scale parameter a > 0 a>0a>0 increases, the time window becomes wider, the frequency window decreases, and the main frequencyω ∗ ω^{*}oh smaller

insert image description here

C: Discrete Wavelet Transform

Discrete Wavelet Transform (DWT) : Given a length NNN discrete signalx [ n ] x[n]x [ n ] , and a wavelet functionψ [ n ] \psi[n]ψ [ n ],DWT 将x [ n ] x[n]x [ n ]ψ [ n ] \psi[n]ψ [ n ] performs a series of scaling and translation operations to obtain a set of wavelet coefficientscj , k c_{j,k}cj,kand a set of approximate coefficients dj d_jdj. Among them, jjj represents the scale (scaling factor),kkk represents displacement (translation factor). DWT can be expressed by the following formula

  • ψ j , k [ n ] \psi_{j,k}[n]pj,k[ n ]ϕ j , k [ n ] \phi_{j,k}[n]ϕj,k[ n ] respectively represent the discrete scaling and translation versions of the wavelet function and the scaling function, which can be discretized by selecting appropriate scales and displacements in the continuous version

cj , k = ⟨ x [ n ] , ψ j , k [ n ] ⟩ = ∑ n = 0 N − 1 x [ n ] ψ j , k [ n ] dj [ k ] = ⟨ x [ n ] , ϕ j , k [ n ] ⟩ = ∑ n = 0 N − 1 x [ n ] ϕ j , k [ n ] \begin{array}{l}c_{j, k}=\left\angle x[n], \ psi_{j, k}[n]\right\angle=\sum_{n=0}^{N-1} x[n] \psi_{j, k}[n] \\d_{j}[k] =\left\angle x[n], \phi_{j, k}[n]\right\angle=\sum_{n=0}^{N-1} x[n] \phi_{j, k}[ n]\end{array}cj,k=x[n],pj,k[n]=n=0N1x [ n ] psj,k[n]dj[k]=x[n],ϕj,k[n]=n=0N1x [ n ] ϕj,k[n]

The physical meaning of DWT is similar to CWT, which is to convert the signal x [ n ] x[n]x [ n ] is split into a set of wavelet coefficients and approximation coefficients of different scales and different positions (or frequencies), so that the local characteristics of the signal can be better analyzed. Unlike CWT, DWT is calculated using discrete signals and discrete wavelet functions, so it can be efficiently implemented on a computer

D: Orthogonal wavelet

Orthogonal Wavelet Transform (OWT) : Given a length NNN discrete signalx [ n ] x[n]x [ n ] , and a set of orthogonal wavelet functionsψ j , k [ n ] , ϕ j , k [ n ] {\psi_{j,k}[n],\phi_{j,k}[n]}pj,k[n],ϕj,k[n],OWT 将 x [ n ] x[n] Carry out inner product calculation between x [ n ] and wavelet base to get a set of wavelet coefficientscj , k c_{j,k}cj,kand a set of approximate coefficients dj d_jdj. Among them, jjj represents the scale (scaling factor),kkk represents displacement (translation factor). OWT can be expressed by the following formula

cj , k = ⟨ x [ n ] , ψ j , k [ n ] ⟩ = ∑ n = 0 N − 1 x [ n ] ψ j , k [ n ] dj [ k ] = ⟨ x [ n ] , ϕ j , k [ n ] ⟩ = ∑ n = 0 N − 1 x [ n ] ϕ j , k [ n ] \begin{array}{l}c_{j, k}=\left\angle x[n], \ psi_{j, k}[n]\right\angle=\sum_{n=0}^{N-1} x[n] \psi_{j, k}[n] \\d_{j}[k] =\left\angle x[n], \phi_{j, k}[n]\right\angle=\sum_{n=0}^{N-1} x[n] \phi_{j, k}[ n]\end{array}cj,k=x[n],pj,k[n]=n=0N1x [ n ] psj,k[n]dj[k]=x[n],ϕj,k[n]=n=0N1x [ n ] ϕj,k[n]

where, ψ j , k [ n ] \psi_{j,k}[n]pj,k[ n ]ϕ j , k [ n ] \phi_{j,k}[n]ϕj,k[ n ] is an orthogonal wavelet function that satisfies the following orthogonal conditions

  • δ i , j \delta_{i,j} di,j i = j i=j i=It is 1 when j , otherwise it is 0. These orthogonal conditions guarantee the orthogonality and normality of the orthogonal wavelet base

⟨ ψ j , k [ n ] , ψ j ′ , k ′ [ n ] ⟩ = δ j , j ′ δ k , k ′ ⟨ ϕ j , k [ n ] , ϕ j ′ , k ′ [ n ] ⟩ = δ j , j ′ δ k , k ′ \begin{array}{l}\left\langle\psi_{j, k}[n], \psi_{j^{\prime}, k^{\prime}} [n]\right\rangle=\delta_{j, j^{\prime}} \delta_{k, k^{\prime}} \\\left\langle\phi_{j, k}[n], \ phi_{j^{\prime}, k^{\prime}}[n]\right\rangle=\delta_{j, j^{\prime}} \delta_{k, k^{\prime}}\end {array}pj,k[n],pj,k[n]=dd , ddk,kϕj,k[n],ϕj,k[n]=dd , ddk,k

Orthogonal wavelet bases have polynomial properties and can be constructed by recursive algorithms (such as Daubechies algorithm). This wavelet basis is generally easier to implement and compute than those of CWT and other wavelet transforms, and is widely used in compression and signal processing applications

(3) Two-dimensional wavelet transform

A: Definition

Two-Dimensional Wavelet Transform (2DWT) : It is a wavelet transform that decomposes a two-dimensional image or signal into frequency components of different scales and directions. It can be a M × NM\times NM×Two-dimensional signal f of N ( x , y ) f(x,y)f(x,y ) is decomposed into wavelet coefficients wjin multiple scales and directionswj,k(x,y ) and approximation coefficienta J ( x , y ) a_{J}(x,y)aJ(x,y ) , wherejjj represents scale,kkk means position,JJJ is the coarsest scale. The wavelet coefficients and approximation coefficients can be calculated with the following formula

wj , k ( x , y ) = ⟨ f ( x , y ) , ψ j , k ( x , y ) ⟩ = ∬ − ∞ ∞ f ( x , y ) ψ j , k ∗ ( x , y ) dxdya J ( x , y ) = ⟨ f ( x , y ) , ϕ J ( x , y ) ⟩ = ∬ − ∞ ∞ f ( x , y ) ϕ J ∗ ( x , y ) dxdy \begin{array}{l} w_{j, k}(x, y)=\left\langle f(x, y), \psi_{j, k}(x, y)\right\rangle=\iint_{-\infty}^{\ infty} f(x, y) \psi_{j, k}^{*}(x, y) dxdy \\a_{J}(x, y)=\left\langle f(x, y), \phi_ {J}(x, y)\right\rangle=\iint_{-\infty}^{\infty} f(x, y) \phi_{J}^{*}(x, y) dxdy\end{array }wj,k(x,y)=f(x,y),pj,k(x,y)=f(x,y ) pj,k(x,y)dxdyaJ(x,y)=f(x,y),ϕJ(x,y)=f(x,y ) ϕJ(x,y)dxdy

份位,ψ j , k ( x , y ) \psi_{j,k}(x,y)pj,k(x,y )ϕ J ( x , y ) \phi_{J}(x,y)ϕJ(x,y ) is a two-dimensional wavelet basis function, which satisfies the conditions of orthogonality and normalization:

⟨ ψ j , k ( x , y ) , ψ j ′ , k ′ ( x , y ) ⟩ = δ j , j ′ δ k , k ′ ⟨ ϕ J ( x , y ) , ϕ J ( x , y ) ⟩ = 1 \begin{array}{l}\left\langle\psi_{j, k}(x, y), \psi_{j^{\prime}, k^{\prime}}(x, y) \right\rangle=\delta_{j, j^{\prime}} \delta_{k, k^{\prime}} \\\left\langle\phi_{J}(x, y), \phi_{J }(x, y)\right\rangle=1\end{array}pj,k(x,y),pj,k(x,y)=dd , ddk,kϕJ(x,y),ϕJ(x,y)=1

The two-dimensional wavelet basis function can be obtained by taking the tensor product of the one-dimensional wavelet basis function in two directions. Algorithms such as Fast Wavelet Transform (FWT) can be used to calculate the two-dimensional wavelet transform

The two-dimensional small inverse transform recombines the wavelet coefficients and approximate coefficients into the original signal f ( x , y ) f(x,y)f(x,y ) , its formula is:

f ( x , y ) = ∑ j = 0 J ∑ k w j , k ( x , y ) + a J ( x , y ) f(x, y)=\sum_{j=0}^{J} \sum_{k} w_{j, k}(x, y)+a_{J}(x, y) f(x,y)=j=0Jkwj,k(x,y)+aJ(x,y)

B: Image wavelet decomposition

Image wavelet decomposition : It is the process of performing wavelet transformation on a two-dimensional image to obtain its wavelet coefficients and approximate coefficients in different scales and directions. This decomposition provides a way to analyze images at multiple resolutions and identify local changes. Image wavelet decomposition can be implemented using two-dimensional wavelet transforms such as two-dimensional discrete wavelet transform or two-dimensional redundant wavelet transform. In general, the 2D discrete wavelet transform is faster and requires less storage, while the 2D redundant wavelet transform provides a more flexible representation and can achieve better compression performance. Image wavelet decomposition includes the following steps

  • Perform two-dimensional wavelet transform on the image to obtain wavelet coefficients and approximation coefficients in each scale and direction
  • Threshold the wavelet coefficients to remove noise or other unwanted high frequency components. Various thresholding methods can be used such as hard thresholding, soft thresholding or adaptive thresholding
  • Reconstruct image using wavelet coefficients and approximation coefficients

C: program

MATLAB implementation : the relevant functions are as follows, for detailed explanation, please refer to the MATLAB help manual

  • p[CA,CH,CV,CD]=dwt2(X,’wname’) Or [CA,CH,CV,CD]=dwt2(X, Lo_D, Hi_D): one-level two-dimensional discrete wavelet transform
  • X=idwt2(CA,CH,CV,CD,’wname’)Or X=idwt2(CA,CH,CV,CD, Lo_D, Hi_D): one-level two-dimensional discrete wavelet inverse transform
  • [C,S] = wavedec2(X,N,'wname') Or [C,S] = wavedec2(X,N,Lo_D,Hi_D): multilevel 2D wavelet decomposition
  • X = waverec2(C,S,'wname')Or X = waverec2(C,S,Lo_R,Hi_R): multilevel 2D wavelet reconstruction
  • A = appcoef2(C,S,'wname',N)Or A = appcoef2(C,S,Lo_R,Hi_R,N): extract low frequency coefficients of 2D wavelet decomposition
  • D = detcoef2(O,C,S,N) Or [H,V,D] = detcoef2('all',C,S,N): extract high frequency coefficients of 2D wavelet decomposition

①: First-level decomposition and reconstruction

MATLAB

Image=imread('cameraman.jpg');     
subplot(1,3,1),imshow(Image),title('原图');                  
grayI=rgb2gray(Image);           
[ca1,ch1,cv1,cd1]=dwt2(grayI,'db4');  
DWTI1=[wcodemat(ca1,256),wcodemat(ch1,256);wcodemat(cv1,256),wcodemat(cd1,256)];
subplot(1,3,2),imshow(DWTI1/256),title('一级分解');    
% imwrite(DWTI2/256,'dwt1.jpg');
result=idwt2(ca1,ch1,cv1,cd1,'db4');
subplot(1,3,3),imshow(result,[]),title('一级重构');
% imwrite(result/256,'redwt1.jpg');

insert image description here

Python

import cv2
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['font.sans-serif'] = ['SimHei']

# 读入图像
Image = cv2.imread('cameraman.jpg')

# 显示原图
plt.subplot(1, 3, 1)
plt.imshow(cv2.cvtColor(Image, cv2.COLOR_BGR2RGB))
plt.title('原图')

# 灰度化
grayI = cv2.cvtColor(Image, cv2.COLOR_BGR2GRAY)

# 一级小波分解
coeffs = pywt.dwt2(grayI, 'db4')
ca1, (ch1, cv1, cd1) = coeffs

# 拼接小波系数矩阵
DWTI1 = np.vstack((np.hstack((ca1, ch1)), np.hstack((cv1, cd1))))

# 显示一级分解结果
plt.subplot(1, 3, 2)
plt.imshow(DWTI1 / 256)
plt.title('一级分解')

# 一级小波重构
result = pywt.idwt2(coeffs, 'db4')

# 显示一级重构结果
plt.subplot(1, 3, 3)
plt.imshow(result, cmap='gray')
plt.title('一级重构')

# 显示图像
plt.show()

②: Secondary decomposition and reconstruction

MATLAB

close all,clear,clc;
Image=imread('cameraman.jpg');     
subplot(1,3,1),imshow(Image);                  
grayI=rgb2gray(Image);           
[ca1,ch1,cv1,cd1]=dwt2(grayI,'db4');  
DWTI2=[wcodemat(ca1,256),wcodemat(ch1,256);wcodemat(cv1,256),wcodemat(cd1,256)];
subplot(1,3,2),imshow(DWTI2/256);    
imwrite(DWTI2/256,'dwt1.jpg');
result=idwt2(ca1,ch1,cv1,cd1,'db4');
subplot(1,3,3),imshow(result,[]);

Image=imread('cameraman.jpg');     
grayI=rgb2gray(Image);           
[c,s]=wavedec2(grayI,2,'db4');
ca2=appcoef2(c,s,'db4',2);
[ch2,cv2,cd2] = detcoef2('all',c,s,2);
[ch1,cv1,cd1] = detcoef2('all',c,s,1);
ca1=[wcodemat(ca2,256),wcodemat(ch2,256);wcodemat(cv2,256),wcodemat(cd2,256)];
k=s(2,1)*2-s(3,1);
ch1=padarray(ch1,[k k],1,'pre');
cv1=padarray(cv1,[k k],1,'pre');
cd1=padarray(cd1,[k k],1,'pre');
DWTI2=[ca1,wcodemat(ch1,256);wcodemat(cv1,256),wcodemat(cd1,256)];
subplot(1,2,1),imshow(DWTI2/256),title('二级分解');    
% imwrite(DWTI2/256,'dwt2.jpg');
result= waverec2(c,s,'db4');
subplot(1,2,2),imshow(result,[]),title('二级重构');
% imwrite(result/256,'redwt2.jpg');

insert image description here

import cv2
import matplotlib.pyplot as plt
import numpy as np
import pywt

# 读入图像
Image = cv2.imread('cameraman.jpg')

# 显示原图
plt.subplot(1, 3, 1)
plt.imshow(cv2.cvtColor(Image, cv2.COLOR_BGR2RGB))
plt.title('原图')

# 灰度化
grayI = cv2.cvtColor(Image, cv2.COLOR_BGR2GRAY)

# 一级小波分解
coeffs1 = pywt.dwt2(grayI, 'db4')
ca1, (ch1, cv1, cd1) = coeffs1

# 拼接小波系数矩阵
DWTI1 = np.vstack((np.hstack((ca1, ch1)), np.hstack((cv1, cd1))))

# 显示一级分解结果
plt.subplot(1, 3, 2)
plt.imshow(DWTI1 / 256)
plt.title('一级分解')

# 保存一级分解结果
cv2.imwrite('dwt1.jpg', DWTI1 / 256)

# 一级小波重构
result1 = pywt.idwt2(coeffs1, 'db4')

# 显示一级重构结果
plt.subplot(1, 3, 3)
plt.imshow(result1, cmap='gray')
plt.title('一级重构')

# 显示图像
plt.show()

# 读入图像
Image = cv2.imread('cameraman.jpg')

# 灰度化
grayI = cv2.cvtColor(Image, cv2.COLOR_BGR2GRAY)

# 二级小波分解
coeffs2 = pywt.wavedec2(grayI, 'db4', level=2)
ca2 = coeffs2[0]
ch2, cv2, cd2 = coeffs2[1:]

# 一级小波分解
coeffs1 = pywt.wavedec2(grayI, 'db4', level=1)
ch1, cv1, cd1 = coeffs1[1:]

# 根据系数大小调整子带尺寸
k = coeffs2[2][0] * 2 - coeffs2[3][0]
ch1 = np.pad(ch1, ((k, 0), (k, 0)), mode='constant', constant_values=1)
cv1 = np.pad(cv1, ((k, 0), (k, 0)), mode='constant', constant_values=1)
cd1 = np.pad(cd1, ((k, 0), (k, 0)), mode='constant', constant_values=1)

# 拼接小波系数矩阵
ca1 = np.vstack((np.hstack((ca2, ch2)), np.hstack((cv2, cd2))))
DWTI2 = np.vstack((np.hstack((ca1, ch1)), np.hstack((cv1, cd1))))

# 显示二级分解结果
plt.subplot(1, 2, 1)
plt.imshow(DWTI2 / 256)
plt.title('二级分解')

# 二级小波重构
result2 = pywt.waverec2(coeffs2, 'db4')

# 显示二级重构结果
plt.subplot(1, 2, 2)
plt.imshow(result2, cmap='gray')
plt.title

(4) Application of wavelet transform in image processing

Application of wavelet transform in image processing :

  • Filtering and noise removal : The wavelet transform can decompose the signal into frequency components of different scales, so the image can be filtered in the frequency domain by selecting different wavelet basis functions. In addition, wavelet transform can also separate noise from signal, so soft or hard thresholding in wavelet domain can be used to remove noise
  • Edge detection : Since wavelet transform can provide frequency information of different scales and directions, edge detection can be realized by detecting changes in wavelet coefficients. For example, edge information can be enhanced by choosing wavelet basis functions with high direction selectivity
  • Compression coding : Wavelet transform can decompose a signal into subbands, some of which may have lower energy. Therefore, in compression coding, these low-energy sub-bands can be selectively discarded, thereby achieving compression coding. In addition, wavelet transform can also decompose the image into sub-bands of different resolutions, so that different resolution sub-bands can be selected for encoding according to needs
  • Image Enhancement : Wavelet transform can realize image enhancement by increasing or decreasing wavelet coefficients. For example, the details of the image can be enhanced by increasing the value of the high-frequency wavelet coefficient, or the blurriness of the image can be reduced by reducing the value of the low-frequency wavelet coefficient
  • Image fusion : Wavelet transform can decompose multiple images into different frequency subbands, so different subbands from different images can be fused. For example, the high-frequency subbands of two images with different frequency characteristics can be fused for better detail preservation

Guess you like

Origin blog.csdn.net/qq_39183034/article/details/130146956
Recommended