Advertisement
Guest User

Untitled

a guest
Jul 16th, 2020
533
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from numpy.fft import fft2, fftfreq, fftshift
  4. import scipy.fftpack as sfft
  5. from scipy import ndimage
  6.  
  7. fname = '_113403077_picture1_convert.png'
  8.  
  9. img = plt.imread(fname)
  10. s0, s1 = img.shape[:2]
  11. deg_per_pixel = 0.04 # This map of the CMB covers a section of the sky 50 times the Moon's width
  12. pixel_per_deg = 1. / deg_per_pixel
  13. print(img.shape)
  14. r, g, b = np.moveaxis(img, 2, 0)
  15. diff = r - b
  16. f = fftshift(fft2(diff))
  17. P = np.abs(f)**2
  18. logP = np.log10(P)
  19.  
  20. FreqCompRows = np.fft.fftfreq(f.shape[0], d=2)
  21. FreqCompCols = np.fft.fftfreq(f.shape[1], d=2)
  22. FreqCompRows = np.fft.fftshift(FreqCompRows) # per pixel (vertical)
  23. FreqCompCols = np.fft.fftshift(FreqCompCols) # per pixel (horizontal)
  24. # https://dsp.stackexchange.com/a/50245/25659
  25. extent = [0, s1 * deg_per_pixel, 0, s0 * deg_per_pixel]
  26.  
  27. extent_ft = [FreqCompCols.min() * pixel_per_deg, FreqCompCols.max() * pixel_per_deg,
  28.              FreqCompRows.min() * pixel_per_deg, FreqCompRows.max() * pixel_per_deg]
  29. if True:
  30.     plt.figure()
  31.     plt.imshow(logP[65:184, 163:462], cmap='gray', extent=extent_ft, vmin=3, vmax=7)
  32.     plt.show()
  33.  
  34. if True:
  35.     plt.figure()
  36.     plt.subplot(2, 1, 1)
  37.     # plt.imshow(diff, cmap='gray', extent=extent)
  38.     plt.imshow(img,extent=extent)
  39.     plt.xlabel('degrees')
  40.     plt.ylabel('degrees')
  41.     plt.subplot(2, 1, 2)
  42.     plt.title('log10(abs(FT)^2)')
  43.     plt.xlabel('inverse degrees')
  44.     plt.ylabel('inverse degrees')
  45.     plt.imshow(logP, cmap='gray', extent=extent_ft, vmin=3, vmax=7)
  46.     plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement