Update remove_period_patterns.py
				
					
				
			This commit is contained in:
		@@ -24,35 +24,43 @@ image = multipleColorsImage
 | 
			
		||||
 | 
			
		||||
fft1 = fftpack.fftshift(fftpack.fft2(image))
 | 
			
		||||
originalFft1 = fft1.copy()
 | 
			
		||||
fft1 = abs(fft1)
 | 
			
		||||
 | 
			
		||||
# 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
 | 
			
		||||
def removePeriodicPatterns(fft1Part):
 | 
			
		||||
    # 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 = fft1Part.shape
 | 
			
		||||
    for x in range(width):
 | 
			
		||||
        fft1Part[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
 | 
			
		||||
    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):
 | 
			
		||||
                fft1Part[y, x] = np.nan
 | 
			
		||||
 | 
			
		||||
# We smooth with a Gaussian kernel
 | 
			
		||||
kernel = Gaussian2DKernel(x_stddev = X_STDDEV)
 | 
			
		||||
    # 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)
 | 
			
		||||
    # create a "fixed" image with NaNs replaced by interpolated values
 | 
			
		||||
    fixedImage = interpolate_replace_nans(fft1Part, kernel)
 | 
			
		||||
    return fixedImage
 | 
			
		||||
 | 
			
		||||
realFixedImage = removePeriodicPatterns(np.real(fft1).copy())
 | 
			
		||||
imaginaryFixedImage = removePeriodicPatterns(np.imag(fft1).copy())
 | 
			
		||||
fixedImage = realFixedImage + 1j * imaginaryFixedImage
 | 
			
		||||
#fixedImage = realFixedImage
 | 
			
		||||
 | 
			
		||||
figure, axes = plt.subplots(1, 2, sharex = True, sharey = True)
 | 
			
		||||
 | 
			
		||||
plt.suptitle('Attenuating FFT significant lines')
 | 
			
		||||
axes[0].set_title('Original FFT')
 | 
			
		||||
#originalFft1Abs = abs(originalFft1)
 | 
			
		||||
#minValue = np.min()
 | 
			
		||||
axes[0].imshow(np.log10(abs(originalFft1)))
 | 
			
		||||
axes[1].set_title('FFT with significant lines attenuated')
 | 
			
		||||
axes[1].imshow(np.log10(fixedImage))
 | 
			
		||||
axes[1].imshow(np.log10(abs(fixedImage)))
 | 
			
		||||
plt.tight_layout()
 | 
			
		||||
plt.show()
 | 
			
		||||
#plt.imsave('fft.png', np.log10(fixedImage))
 | 
			
		||||
@@ -66,8 +74,9 @@ def inverseFft(fft):
 | 
			
		||||
 | 
			
		||||
plt.suptitle('Rafael 23/04/24 PRNU mean denoiser with periodic patterns attenuated')
 | 
			
		||||
axes[0].set_title('Original PRNU')
 | 
			
		||||
axes[0].imshow(inverseFft(originalFft1))
 | 
			
		||||
invOriginalFft1 = inverseFft(originalFft1)
 | 
			
		||||
axes[0].imshow(invOriginalFft1)
 | 
			
		||||
axes[1].set_title('PRNU with periodic patterns attenuated')
 | 
			
		||||
axes[0].imshow(inverseFft(fixedImage))
 | 
			
		||||
axes[1].imshow(inverseFft(fixedImage), vmin = invOriginalFft1.min(), vmax = invOriginalFft1.max())
 | 
			
		||||
plt.tight_layout()
 | 
			
		||||
plt.show()
 | 
			
		||||
		Reference in New Issue
	
	Block a user