2

How are you?

I've been trying to do the fourier transformed and the inverse fourier transformed but i have to do the following.

  1. delete all the negative values of the real part and show the result of the reverse transformation.

  2. Show an image of the transform, highlighting those points where the value of the magnitude is greater than 50,000.

Code:

import numpy as np
import cv2
from matplotlib import pyplot as plt

img = cv2.imread('testQ.png',0)

img_float32 = np.float32(img)

dft = cv2.dft(img_float32, flags = cv2.DFT_COMPLEX_OUTPUT)
dft_shift = np.fft.fftshift(dft)

rows, cols = img.shape
crow, ccol = rows/2 , cols/2     # center

# create a mask first, center square is 1, remaining all zeros
mask = np.zeros((rows, cols, 2), np.uint8)
mask[int(crow-30):int(crow+30), int(ccol-30):int(ccol+30)] = 1

# apply mask and inverse DFT
fshift = dft_shift*mask
f_ishift = np.fft.ifftshift(fshift)
img_back = cv2.idft(f_ishift)
img_back = cv2.magnitude(img_back[:,:,0],img_back[:,:,1])
plt.subplot(121),plt.imshow(img, cmap = 'gray')
plt.title('Input Image'), plt.xticks([]), plt.yticks([])
plt.subplot(122),plt.imshow(img_back, cmap = 'gray')
plt.title('Magnitude Spectrum'), plt.xticks([]), plt.yticks([])

plt.show()    

I tried to do the first point by doing this

img_back = img_back[img_back>=0]

but i got this error:

TypeError: Invalid dimensions for image data

Here is the image

this is the image

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
santiago
  • 31
  • 5

1 Answers1

0

Maybe what you are trying to do is:

img_back[img_back<0] = 0
double-beep
  • 5,031
  • 17
  • 33
  • 41