Home > Net >  How can I randomise the magnitude spectrum of an image whilst keeping the phase unchanged?
How can I randomise the magnitude spectrum of an image whilst keeping the phase unchanged?

Time:12-23

I am trying to randomise the magnitude component of the spectrum of the following image. I was thinking of using numpy.random.rand() for the generation of random values however I am not sure how to go about it. Is someone able to explain how I can proceed? The following is the code to obtain the magnitude spectrum of the image attached.

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

img_tp = cv2.imread('testpattern.png', 0)
f_tp = np.fft.fft2(img_tp)
fshift_tp = np.fft.fftshift(f_tp)
mag_spectrum_tp = 20*np.log(np.abs(fshift_tp))
plt.imshow(mag_spectrum_tp)

CodePudding user response:

I don't see how that would be useful in any way. The phase information doesn't have any real meaning without the magnitude. Theoretically, you can combine unrelated magnitude and phase values by doing something like this:

f_mag = np.abs( fft_result1 )
f_phase = np.angle( fft_result2 )
combined = np.multiply(f_mag, np.exp(1j*f_phase))
img = np.fft.iff2(combined)

but the results are pretty much going to be garbage.

  • Related