Skip to content Skip to sidebar Skip to footer

How To Get Information About Sharpness Of Image With Fourier Transformation?

i am rookie with Matplotlib, Python, FFT. My Task is to get information about sharpness of a Image with FFT, but how do i get this done? What i have done so far: #getImage: imgArr

Solution 1:

As the comments pointed out, you are looking for high frequencies (frequencies away from the center of your 2D Fourier plot). I'm giving a synthetic example. I added some noise to make it more similar to a real image. In the 3rd line I'm showing a lowpass filter in the middle, multiply the FFT spectrum to the right with it and inverse transform to get the filtered image on the left. So I suppressed the low frequencies in the image and only the sharp portions stand out now. Try with your image.

import numpy as np
import matplotlib.pyplot as p
%matplotlib inline

n=200
x=np.linspace(0,1,n)
y=np.linspace(0,1,n)
X,Y=np.meshgrid(x,y)
z=np.zeros((n,n))
z1= np.sin(2*np.pi*X*5)* np.cos(2*np.pi*Y*20)  +1/20*np.random.random(np.shape(z))

z2=np.copy(z1)
for i in range(30):
    z2[ i*10: 3+i*10, 100+i*3:103+i*3]=2

#Fast Fourier Transformation:
def f(z):
    return np.fft.fftshift(np.fft.fft2(z))



highpass=1-np.exp(- ((X-0.5)**2+(Y-0.5)**2)*5)
print(np.shape(highpass))
f2=f(z2)*highpass
z3= np.absolute( np.fft.ifft2(f2)) 


#Shows Result of FFT:
p.figure(figsize=(15,12))
p.subplot(331)
p.imshow( z1)
p.colorbar()
p.title('soft features only')
p.subplot(333)
p.imshow(np.abs( np.log10(f(z1)) ), cmap='gray')
p.title('see the spatial frequencies +/-5 from center in x, +/-20 in y')
p.colorbar()

p.subplot(334)
p.imshow( z2)
p.colorbar()
p.title('add some sharp feature')
p.subplot(336)
p.imshow(np.abs(np.log10(f(z2))), cmap='gray')
p.title('higher frequencies appear ()')
p.colorbar()

p.subplot(337)
p.imshow(z3)
p.title('only high frequency content survived')
p.colorbar()
p.subplot(338)
p.imshow( highpass)
p.title('highpass, suppresses \n low frequencies')
p.colorbar()
p.subplot(339)
p.imshow( np.log10(np.abs(f(z2)*highpass)), cmap='gray')
p.title('FFT*highpass')
p.colorbar()

enter image description here

Post a Comment for "How To Get Information About Sharpness Of Image With Fourier Transformation?"