From 7f7e78cafb8f6d5807755b9801b0dcd2d8290776 Mon Sep 17 00:00:00 2001 From: Benjamin Loison Date: Fri, 31 May 2024 14:07:51 +0200 Subject: [PATCH] Small changes --- datasets/raise/benchmark_load_part_of_images.py | 4 ++-- .../raise/extract_4_color_channel_images_from_raw.py | 12 ++++++------ datasets/raise/fft/generate_vignetting.py | 5 +++++ datasets/raise/fft/image_to_fourier.py | 6 ++++-- .../raise/find_consecutive_most_similar_images.py | 10 +++++++--- datasets/raise/utils.py | 2 +- 6 files changed, 25 insertions(+), 14 deletions(-) diff --git a/datasets/raise/benchmark_load_part_of_images.py b/datasets/raise/benchmark_load_part_of_images.py index ce1576e..d8e5a29 100755 --- a/datasets/raise/benchmark_load_part_of_images.py +++ b/datasets/raise/benchmark_load_part_of_images.py @@ -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: diff --git a/datasets/raise/extract_4_color_channel_images_from_raw.py b/datasets/raise/extract_4_color_channel_images_from_raw.py index 30a48d1..0799695 100644 --- a/datasets/raise/extract_4_color_channel_images_from_raw.py +++ b/datasets/raise/extract_4_color_channel_images_from_raw.py @@ -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() \ No newline at end of file diff --git a/datasets/raise/fft/generate_vignetting.py b/datasets/raise/fft/generate_vignetting.py index a21f083..e8336dc 100644 --- a/datasets/raise/fft/generate_vignetting.py +++ b/datasets/raise/fft/generate_vignetting.py @@ -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() \ No newline at end of file diff --git a/datasets/raise/fft/image_to_fourier.py b/datasets/raise/fft/image_to_fourier.py index b52d458..4d666a5 100644 --- a/datasets/raise/fft/image_to_fourier.py +++ b/datasets/raise/fft/image_to_fourier.py @@ -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) \ No newline at end of file +#plt.imsave(f'{IMAGE_FILE_NAME}_fft.png', toDisplay) \ No newline at end of file diff --git a/datasets/raise/find_consecutive_most_similar_images.py b/datasets/raise/find_consecutive_most_similar_images.py index 3d7a463..0f312fc 100644 --- a/datasets/raise/find_consecutive_most_similar_images.py +++ b/datasets/raise/find_consecutive_most_similar_images.py @@ -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}') \ No newline at end of file +print(f'{highestCorrelationFile} (and previous file) have the highest correlation with a correlation of {highestCorrelation}') \ No newline at end of file diff --git a/datasets/raise/utils.py b/datasets/raise/utils.py index a89eba1..87c379d 100644 --- a/datasets/raise/utils.py +++ b/datasets/raise/utils.py @@ -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: