Wavelet Threshold Denoising Algorithm Based on Python

Wavelet image denoising principle

The image and noise have different statistical characteristics after wavelet transform: the energy of the image itself corresponds to the wavelet coefficient with larger amplitude, mainly concentrated in the low frequency (LL) part; the noise energy corresponds to the wavelet coefficient with smaller amplitude. And scattered in all the coefficients after the wavelet transform. Based on this, an appropriate threshold threshold can be set, and the main component of the wavelet coefficient larger than the threshold is considered to be a useful signal, which is reserved after being contracted; the wavelet coefficient smaller than the threshold is mainly composed of noise, and is set to zero; then the threshold is passed. The function map obtains the estimated coefficients; finally, the inverse transform of the estimated coefficients can achieve denoising and reconstruction. When denoising, it is generally considered that the low-pass coefficient contains a large amount of image energy, and generally no processing is performed, and only the remaining three high-pass portions are processed. A threshold denoising does not completely remove the noise. It is also necessary to perform wavelet decomposition and threshold denoising again on the unprocessed low frequency part (LL) until the deviation of the actual image from the estimated image reaches a minimum. However, as the number of decomposition and denoising increases, the noise energy in the wavelet coefficients becomes smaller and smaller, and tends to be dispersed, and the effect of denoising will gradually decrease. In general, 3-4 layers of wavelet decomposition and denoising can achieve satisfactory denoising effects.

Wavelet threshold denoising step

(1) Wavelet decomposition of two-dimensional signals. Select a wavelet (sym8) and the wavelet decomposition level N(3), and then calculate the decomposition of the signal S to the Nth layer.

(2) Threshold quantization of the high frequency coefficients, for each layer from one to N, a threshold is selected, and the high frequency coefficients of this layer are soft thresholded.

(3) Reconstruction of two-dimensional wavelet, wavelet reconstruction of two-dimensional signal is calculated according to the low-frequency coefficient of the N-th layer of wavelet decomposition and the modified high-frequency coefficient from the first layer to the N-th layer.

Python implements wavelet threshold denoising program

Import numpy as np

Import pywt

Data = np.linspace(1, 4, 7)

# pywt.threshold method to explain:

# pywt.threshold(data,value,mode ='soft',subsTItute = 0 )

# data: data set, value: threshold, mode: comparison mode default soft, subsTItute: substitute value, default 0, float type

#data: [ 1. 1.5 2. 2.5 3. 3.5 4. ]

#output:[ 6. 6. 0. 0.5 1. 1.5 2. ]

#soft Because data is less than 2, it is replaced by 6 because the second 1.5 in data is also replaced by 2, 2 is not less than 2, so use the current value minus 2, 2.5 is greater than 2, so 2.5-2=0.5 . . . ..

Print "---------------------soft: absolute value----------------------- --"

Print pywt.threshold(data, 2, 'soft',6)

Print "---------------------hard: absolute value ----------------------- --"

#data: [ 1. 1.5 2. 2.5 3. 3.5 4. ]

In #hard data, the absolute value is less than the threshold 2 and the replacement is 6, and the greater than 2 is not replaced.

Print pywt.threshold(data, 2, 'hard',6)

Print "---------------------greater-------------------------"

#data: [ 1. 1.5 2. 2.5 3. 3.5 4. ]

The replacement of the value in #data is less than the threshold, and the replacement is 6 or not.

Print pywt.threshold(data, 2, 'greater',6)

Print "---------------------less-------------------------"

Print data

#data: [ 1. 1.5 2. 2.5 3. 3.5 4. ]

If the value in #data is greater than the threshold, replace it with 6

Print pywt.threshold(data, 2, 'less',6)

Disposable Vape

Vape Pen Disposable E Cigarette,Disposable Vape Pen Stick,Disposable Vape Puff Bar,Electronic Cigarette Vape Puff Bar

Shenzhen Kate Technology Co., Ltd. , https://www.katevape.com