Small changes

This commit is contained in:
Benjamin Loison 2024-05-31 14:07:51 +02:00
parent 4eb8841ebf
commit 7f7e78cafb
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8
6 changed files with 25 additions and 14 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python
from utils import getColorChannel, Color
from utils import getColorChannel, Color, isARawImage
import os
from tqdm import tqdm
import numpy as np
@ -32,7 +32,7 @@ def getNumpyFilePath(imageFilePath, color):
for camera in tqdm(IMAGES_CAMERAS_FOLDER, 'Camera'):
imagesCameraFolder = IMAGES_CAMERAS_FOLDER[camera]
for file in tqdm(os.listdir(imagesCameraFolder), 'Image'):
if file.endswith('.NEF') or file.endswith('.ARW'):
if isARawImage(file):
#print(file)
imageFilePath = f'{imagesCameraFolder}/{file}'
for color in Color:

View File

@ -15,21 +15,21 @@ def getImageFilePath(imageIndex):
def getImageColorChannel(imageIndex, color):
imageFilePath = getImageFilePath(imageIndex)
return getColorChannel(imageFilePath, color).astype(np.int32)
return getColorChannel(imageFilePath, color)
def crop(image, interestingPosition, yRange, xRange):
return image[interestingPosition[0] - yRange: interestingPosition[0] + yRange, interestingPosition[1] - xRange: interestingPosition[1] + xRange]
# Could leverage crop already here.
colorChannels = [getImageColorChannel(imageIndex, COLOR) for imageIndex in tqdm(IMAGE_INDEX_RANGE)]
colorChannels = [crop(getImageColorChannel(imageIndex, COLOR), INTERESTING_POSITION, Y_RANGE, X_RANGE).astype(np.int32) for imageIndex in tqdm(IMAGE_INDEX_RANGE)]
meanColorChannels = np.mean(colorChannels, axis = 0)
estimatedPrnus = [colorChannel - meanColorChannels for colorChannel in tqdm(colorChannels)]
estimatedPrnu = np.mean(estimatedPrnus, axis = 0)
print(estimatedPrnu.shape)
def crop(image, interestingPosition, yRange, xRange):
return image[interestingPosition[0] - yRange: interestingPosition[0] + yRange, interestingPosition[1] - xRange: interestingPosition[1] + xRange]
#colorChannel = crop(multipleColorsImage, ORIGINAL_INTERESTING_POSITION, Y_RANGE, X_RANGE)
colorChannelToDisplay = estimatedPrnu
colorChannelToDisplay = crop(colorChannelToDisplay, INTERESTING_POSITION, Y_RANGE, X_RANGE)
#colorChannelToDisplay = crop(colorChannelToDisplay, INTERESTING_POSITION, Y_RANGE, X_RANGE)
print(colorChannelToDisplay.shape)
plt.imshow(colorChannelToDisplay)
plt.show()

View File

@ -2,6 +2,8 @@ import numpy as np
import matplotlib.pyplot as plt
from tqdm import tqdm
# TODO: seems to avoid some intermediary values resulting in visible circles
A = -1.076923838846692e-06
B = 0.0010539307456559996
C = 42
@ -30,6 +32,9 @@ def checkOriginalPoint(point):
for point in [CENTER, [0, 0], [CENTER[0], int(CENTER[1] + getDistance(0, 0) / 2)]]:
checkOriginalPoint(point)
pad = (SHAPE[1] - SHAPE[0]) // 2
cropImage = image[:, pad:-pad]
#plt.imshow(image, cmap = 'grey')
plt.imsave('vignetting.png', image * 2.55, cmap = 'grey', vmin = 0, vmax = 255)
plt.show()

View File

@ -3,13 +3,15 @@ import numpy as np
from scipy import fftpack
import matplotlib.pyplot as plt
image = np.array(Image.open('circle.png').convert('L'))# / 255
IMAGE_FILE_NAME = 'manual_tests/horizontal_ellipse'
image = np.array(Image.open(f'{IMAGE_FILE_NAME}.png').convert('L'))# / 255
# fft of image
fft1 = fftpack.fftshift(fftpack.fft2(image))
# save the image
#toDisplay = np.angle(fft1)
toDisplay = np.log10(1 + abs(fft1))
plt.imshow(toDisplay)
plt.show()
plt.imsave('ifft1.png', toDisplay)
#plt.imsave(f'{IMAGE_FILE_NAME}_fft.png', toDisplay)

View File

@ -1,6 +1,7 @@
import os
from utils import getColorChannel, Color, mergeSingleColorChannelImagesAccordingToBayerFilter
from utils import getColorChannel, Color, mergeSingleColorChannelImagesAccordingToBayerFilter, isARawImage
from tqdm import tqdm
import numpy as np
folder = 'flat-field/NEF'
@ -24,7 +25,9 @@ lastCorrelation = None
highestCorrelation = None
highestCorrelationFile = None
for file in tqdm(sorted(os.listdir(folder)), 'File'):
files = [file for file in sorted(os.listdir(folder)) if isARawImage(file)]
for file in tqdm(files, 'File'):
colorChannels = {}
for color in Color:
colorChannel = getColorChannel(f'{folder}/{file}', color)
@ -35,7 +38,8 @@ for file in tqdm(sorted(os.listdir(folder)), 'File'):
correlation = corr(mergedSingleColorChannelImage, lastMergedSingleColorChannelImage)
if highestCorrelation is None or correlation > highestCorrelation:
highestCorrelation = correlation
highestCorrelationFile = file
lastMergedSingleColorChannelImage = mergedSingleColorChannelImage
print(f'{highestCorrelationFile=} (and previous file) have a correlation of {highestCorrelation}')
print(f'{highestCorrelationFile} (and previous file) have the highest correlation with a correlation of {highestCorrelation}')

View File

@ -148,7 +148,7 @@ def isARawImage(imageFilePath):
def getColorChannel(imageFilePath, color):
if isARawImage(imageFilePath):
numpyFilePath = f'{imageFilePath}.{color}.npy'
if False and os.path.isfile(numpyFilePath):
if os.path.isfile(numpyFilePath):
imageNpArray = np.load(numpyFilePath)
else:
with rawpy.imread(imageFilePath) as raw: