Add remove_period_patterns.py
This commit is contained in:
parent
db55fc6d0f
commit
038f5ffc00
54
datasets/raise/fft/remove_period_patterns.py
Normal file
54
datasets/raise/fft/remove_period_patterns.py
Normal file
@ -0,0 +1,54 @@
|
||||
import numpy as np
|
||||
from astropy.convolution import Gaussian2DKernel, interpolate_replace_nans
|
||||
from PIL import Image
|
||||
import os
|
||||
import sys
|
||||
from scipy import fftpack
|
||||
|
||||
sys.path.insert(0, '../')
|
||||
|
||||
from utils import Color, mergeSingleColorChannelImagesAccordingToBayerFilter
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
PREFIX = 'mean_rafael_230424_mean_'
|
||||
X_STDDEV = 2
|
||||
|
||||
def getImageByColor(color):
|
||||
filePath = PREFIX + f'{color}.npy'
|
||||
image = np.load(filePath)
|
||||
return image
|
||||
|
||||
singleColorChannelImages = {color: getImageByColor(color) for color in Color}
|
||||
multipleColorsImage = mergeSingleColorChannelImagesAccordingToBayerFilter(singleColorChannelImages)
|
||||
image = multipleColorsImage
|
||||
|
||||
fft1 = abs(fftpack.fft2(image))
|
||||
originalFft1 = fft1.copy()
|
||||
|
||||
# This example is intended to demonstrate how astropy.convolve and
|
||||
# scipy.convolve handle missing data, so we start by setting the brightest
|
||||
# pixels to NaN to simulate a "saturated" data set
|
||||
height, width = fft1.shape
|
||||
for x in range(width):
|
||||
fft1[height // 2, x] = np.nan
|
||||
|
||||
middleX = width // 2
|
||||
RANGE = 1
|
||||
for verticalLineX in [width // 4, width // 2, round(3 * width / 4)]:
|
||||
for y in range(height):
|
||||
for x in range(verticalLineX - RANGE, verticalLineX + RANGE + 1):
|
||||
fft1[y, x] = np.nan
|
||||
|
||||
# We smooth with a Gaussian kernel
|
||||
kernel = Gaussian2DKernel(x_stddev = X_STDDEV)
|
||||
|
||||
# create a "fixed" image with NaNs replaced by interpolated values
|
||||
fixedImage = interpolate_replace_nans(fft1, kernel)
|
||||
|
||||
figure, axes = plt.subplots(1, 2, sharex = True, sharey = True)
|
||||
|
||||
axes[0].imshow(np.log10(originalFft1))
|
||||
axes[1].imshow(np.log10(fixedImage))
|
||||
#plt.imshow(np.log10(fixedImage))
|
||||
plt.show()
|
||||
#plt.imsave('fft.png', np.log10(fixedImage))
|
Loading…
x
Reference in New Issue
Block a user