Add fft scripts

This commit is contained in:
Benjamin Loison 2024-05-14 01:19:05 +02:00
parent 4bab354a95
commit 810bde8e35
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8
3 changed files with 49 additions and 3 deletions

View File

@ -3,8 +3,24 @@ import numpy as np
import imageio
from PIL import Image, ImageDraw
import matplotlib.pyplot as plt
import sys
image = imageio.imread('image.jpg', mode = 'L')
sys.path.insert(0, '../')
from utils import Color, mergeSingleColorChannelImagesAccordingToBayerFilter
PREFIX = 'mean_rafael_230424_mean_'
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
#image = imageio.imread('image.jpg', mode = 'L')
#plt.imshow(image, cmap = 'grey')
#plt.show()
@ -17,7 +33,7 @@ fft1 = fftpack.fftshift(fftpack.fft2(imageNp))
# create a low pass filter image
x, y = imageNp.shape
# size of circle
CIRCLE_RADIUS = 50
CIRCLE_RADIUS = 20
eX, eY = CIRCLE_RADIUS, CIRCLE_RADIUS
# create a box
middleX, middleY = x / 2, y / 2
@ -38,4 +54,6 @@ ifft2 = np.real(fftpack.ifft2(fftpack.ifftshift(filtered)))
ifft2 = np.maximum(0, np.minimum(ifft2, 255))
# save the image
imageio.imsave('fft-then-ifft.png', ifft2.astype(np.uint8))
plt.imshow(ifft2)
plt.show()
#imageio.imsave('fft-then-ifft.png', ifft2.astype(np.uint8))

View File

@ -0,0 +1,13 @@
from PIL import Image
import numpy as np
fft = np.array(Image.open('fft.png').convert('L'))# / 255
print(fft)
ifft2 = np.real(fftpack.ifft2(fftpack.ifftshift(fft)))
ifft2 = np.maximum(0, np.minimum(ifft2, 255)) * 255# / 255
# save the image
plt.imshow(ifft2)
plt.show()
#plt.imsave('ifft2.png', ifft2)

View File

@ -0,0 +1,15 @@
from PIL import Image
import numpy as np
image = np.array(Image.open('image_4.png').convert('L'))# / 255
print(image)
# fft of image
# fftpack.fftshift
fft1 = (fftpack.fft2(image))
# save the image
# np.log10
plt.imshow(np.log10(abs(fft1)))
plt.show()
#plt.imsave('ifft1.png', fft1)