Filtering2
Filtering in Frequency Domain¶
We can use the following serveral steps to implment the algorithm:
1. Calculate the suitable size for the image which is suppose to be powers 2 and then padding zeros for both the origin image and the filter simply puting them at the letf top conrner. (Because in frequency domain, it does not matter where you put the image, but will have some side effect for the image’s edge).
Resize function:
def calculate_pow2(x): res = 2 while res < x: res = res << 1 return res
2. Apply Fourier transform for both the images. Centerlize them respetively and then apply fft2d in question2(because it’s fast than using fft2d).
FFT_filter = FFT.centralize(FFT_filter) adjust_img = FFT.centralize(adjust_img) FFT_filter = FFT.fft2d(FFT_filter, 1) FFT_image = FFT.fft2d(adjust_img, 1)
3. Using Convolution theorem:
Let the two matrix to do array multiplication. And get the result image.
Result = FFT_image * FFT_filter Result = FFT.fft2d(Result, -1).real
4. Apply Inverse Fourier transform for the image, and get the real part as well as apply centerlize again.
5. Return the iamge and then do scaling for display.
Deatils:
- For laplacian filtering, the formula should be applied like that in project 2.: Result[x, y] = 5 * img[x, y] - Result[x, y]
- The output image will become brighter. In this way, I apply histogram equlization in project 2. This time I use gama correction.
- Log scaling is more better than linear:
Origin Image:¶
Smooth Result:¶
Sharpen Result:¶
Prove Convolution Theory¶
prov.