Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Image filtering in frequency domain

Hi everybody,

I am new in programming and I would like to apply a filter on an image in frequency domain. actually, its from a paper and i want to re implement it. its the formula: im_out= (1+ 5*((1-e^-f)/f)) * im_in and here are my codes:

im = cv2.imread('lena.jpg',0) x=im.shape[0] y=im.shape[1] fft= np.fft.fft2(im) fshift= np.fft.fftshift(fft) freqx = np.fft.fftfreq(fft.shape[0]) freqy = np.fft.fftfreq(fft.shape[1]) zr = freqx==0 freqx[zr]=0.000000001 for i in xrange(x): for j in xrange(y): filter = 1+(5(1-np.e(-1(np.sqrt((freqx)2 + (freqy)2))))/(np.sqrt((freqx)2 + (freqy)**2)))

fim= fshift* filter fishift= np.fft.ifftshift(fim) imback=np.fft.ifft2(fishift) imback=np.uint8(np.real(imback)) plt.subplot(221) plt.imshow(im,cmap='gray') plt.subplot(222) plt.imshow(imback,cmap='gray') plt.show()

but i get the image without any visible changes, it should be kind of low pass filter. now I am wondering if its correct to use np.fft.fftfreq to find "spatial frequency in the image plane". or I should use distance from center as "f"?!!! in the paper they said "f" is spatial frequency of the image plane!!!!

could anybody help me plz !!!

Image filtering in frequency domain

Hi everybody,

I am new in programming and I would like to apply a filter on an image in frequency domain. actually, its from a paper and i want to re implement it. its the formula: im_out= (1+ 5*((1-e^-f)/f)) * im_in and here are my codes:

im = cv2.imread('lena.jpg',0) x=im.shape[0] y=im.shape[1] cv2.imread('lena.jpg',0)

x=im.shape[0]

y=im.shape[1]

fft= np.fft.fft2(im) np.fft.fft2(im)

fshift= np.fft.fftshift(fft) np.fft.fftshift(fft)

freqx = np.fft.fftfreq(fft.shape[0]) np.fft.fftfreq(fft.shape[0])

freqy = np.fft.fftfreq(fft.shape[1]) np.fft.fftfreq(fft.shape[1])

zr = freqx==0 freqx[zr]=0.000000001 freqx==0

freqx[zr]=0.000000001

for i in xrange(x): xrange(x):

for j in xrange(y):
      filter = 1+(5(1-np.e(-1(np.sqrt((freqx)2 1+(5*(1-np.e**(-1*(np.sqrt((freqx)**2 + (freqy)2))))/(np.sqrt((freqx)2 (freqy)**2))))/(np.sqrt((freqx)**2 + (freqy)**2)))

(freqy)**2)))

fim= fshift* filter filter

fishift= np.fft.ifftshift(fim) imback=np.fft.ifft2(fishift) imback=np.uint8(np.real(imback)) plt.subplot(221) plt.imshow(im,cmap='gray') plt.subplot(222) plt.imshow(imback,cmap='gray') np.fft.ifftshift(fim)

imback=np.fft.ifft2(fishift)

imback=np.uint8(np.real(imback))

plt.subplot(221)

plt.imshow(im,cmap='gray')

plt.subplot(222)

plt.imshow(imback,cmap='gray')

plt.show()

but i get the image without any visible changes, it should be kind of low pass filter. now I am wondering if its correct to use np.fft.fftfreq to find "spatial frequency in the image plane". or I should use distance from center as "f"?!!! in the paper they said "f" is spatial frequency of the image plane!!!!

could anybody help me plz !!!

Image filtering in frequency domain

Hi everybody,

I am new in programming and I would like to apply a filter on an image in frequency domain. actually, its from a paper and i want to re implement it. its the formula: im_out= (1+ 5*((1-e^-f)/f)) * im_in and here are my codes:

im = cv2.imread('lena.jpg',0)

x=im.shape[0]

y=im.shape[1]

cv2.imread('lena.jpg',0) x=im.shape[0] y=im.shape[1] fft= np.fft.fft2(im)

np.fft.fft2(im) fshift= np.fft.fftshift(fft)

np.fft.fftshift(fft) freqx = np.fft.fftfreq(fft.shape[0])

np.fft.fftfreq(fft.shape[0]) freqy = np.fft.fftfreq(fft.shape[1])

np.fft.fftfreq(fft.shape[1]) zr = freqx==0

freqx[zr]=0.000000001

freqx==0 freqx[zr]=0.000000001 for i in xrange(x):

xrange(x):
for j in xrange(y):
filter = 1+(5*(1-np.e**(-1*(np.sqrt((freqx)**2 + (freqy)**2))))/(np.sqrt((freqx)**2 + (freqy)**2)))

fim= fshift* filter
fishift= np.fft.ifftshift(fim)
imback=np.fft.ifft2(fishift)
imback=np.uint8(np.real(imback))
plt.subplot(221)
plt.imshow(im,cmap='gray')
plt.subplot(222)
plt.imshow(imback,cmap='gray')
plt.show()

fim= fshift* filter

fishift= np.fft.ifftshift(fim)

imback=np.fft.ifft2(fishift)

imback=np.uint8(np.real(imback))

plt.subplot(221)

plt.imshow(im,cmap='gray')

plt.subplot(222)

plt.imshow(imback,cmap='gray')

plt.show()

but i get the image without any visible changes, it should be kind of low pass filter. now I am wondering if its correct to use np.fft.fftfreq to find "spatial frequency in the image plane". or I should use distance from center as "f"?!!! in the paper they said "f" is spatial frequency of the image plane!!!!

could anybody help me plz !!!

click to hide/show revision 4
retagged

updated 2015-05-21 03:35:21 -0600

berak gravatar image

Image filtering in frequency domain

Hi everybody,

I am new in programming and I would like to apply a filter on an image in frequency domain. actually, its from a paper and i want to re implement it. its the formula: im_out= (1+ 5*((1-e^-f)/f)) * im_in and here are my codes:

im = cv2.imread('lena.jpg',0)

x=im.shape[0]

y=im.shape[1]

fft= np.fft.fft2(im)

fshift= np.fft.fftshift(fft)

freqx = np.fft.fftfreq(fft.shape[0])

freqy = np.fft.fftfreq(fft.shape[1])

zr = freqx==0

freqx[zr]=0.000000001

for i in xrange(x):

  for j in xrange(y):

    filter = 1+(5*(1-np.e**(-1*(np.sqrt((freqx)**2 + (freqy)**2))))/(np.sqrt((freqx)**2 + (freqy)**2)))

fim= fshift* filter

fishift= np.fft.ifftshift(fim)

imback=np.fft.ifft2(fishift)

imback=np.uint8(np.real(imback))

plt.subplot(221)

plt.imshow(im,cmap='gray')

plt.subplot(222)

plt.imshow(imback,cmap='gray')

plt.show()

but i get the image without any visible changes, it should be kind of low pass filter. now I am wondering if its correct to use np.fft.fftfreq to find "spatial frequency in the image plane". or I should use distance from center as "f"?!!! in the paper they said "f" is spatial frequency of the image plane!!!!

could anybody help me plz !!!

Image filtering in frequency domaindomain python

Hi everybody,

I am new in programming and I would like to apply a filter on an image in frequency domain. actually, its from a paper and i want to re implement it. its the formula: im_out= (1+ 5*((1-e^-f)/f)) * im_in and here are my codes:

im = cv2.imread('lena.jpg',0)

x=im.shape[0]

y=im.shape[1]

fft= np.fft.fft2(im)

fshift= np.fft.fftshift(fft)

freqx = np.fft.fftfreq(fft.shape[0])

freqy = np.fft.fftfreq(fft.shape[1])

zr = freqx==0

freqx[zr]=0.000000001

for i in xrange(x):

  for j in xrange(y):

    filter = 1+(5*(1-np.e**(-1*(np.sqrt((freqx)**2 + (freqy)**2))))/(np.sqrt((freqx)**2 + (freqy)**2)))

fim= fshift* filter

fishift= np.fft.ifftshift(fim)

imback=np.fft.ifft2(fishift)

imback=np.uint8(np.real(imback))

plt.subplot(221)

plt.imshow(im,cmap='gray')

plt.subplot(222)

plt.imshow(imback,cmap='gray')

plt.show()

but i get the image without any visible changes, it should be kind of low pass filter. now I am wondering if its correct to use np.fft.fftfreq to find "spatial frequency in the image plane". or I should use distance from center as "f"?!!! in the paper they said "f" is spatial frequency of the image plane!!!!

could anybody help me plz !!!