diff --git a/datasets/raise/find_consecutive_most_similar_images.py b/datasets/raise/find_consecutive_most_similar_images.py new file mode 100644 index 0000000..54d6679 --- /dev/null +++ b/datasets/raise/find_consecutive_most_similar_images.py @@ -0,0 +1,46 @@ +import os +from utils import getColorChannel, Color, mergeSingleColorChannelImagesAccordingToBayerFilter +from tqdm import tqdm + +folder = 'flat-field/NEF' + +# Could focus on a given crop. + +# Section I. of *Determining Image Origin and Integrity Using Sensor Noise*. +def dotProduct(X, Y): + return np.multiply(X, Y).sum() + +# Section I. of *Determining Image Origin and Integrity Using Sensor Noise*. +def corr(X, Y): + XMinusItsMean = X - X.mean() + YMinusItsMean = Y - Y.mean() + return dotProduct(XMinusItsMean, YMinusItsMean) / (np.linalg.norm(XMinusItsMean) * np.linalg.norm(YMinusItsMean)) + +def crop(image, yRange, xRange): + interestingPosition = np.array(image.shape) // 2 + return image[interestingPosition[0] - yRange: interestingPosition[0] + yRange, interestingPosition[1] - xRange: interestingPosition[1] + xRange] + +lastMergedSingleColorChannelImage = None +lastCorrelation = None + +highestCorrelation = None +highestCorrelationFile = None + +for file in tqdm(sorted(os.listdir(folder)), 'File'): + #print(file) + colorChannels = {} + for color in Color: + colorChannel = getColorChannel(f'{folder}/{file}', color) + colorChannel = crop(colorChannel, 200, 200) + colorChannels[color] = colorChannel + mergedSingleColorChannelImage = mergeSingleColorChannelImagesAccordingToBayerFilter(colorChannels) + if lastMergedSingleColorChannelImage is not None: + correlation = corr(mergedSingleColorChannelImage, lastMergedSingleColorChannelImage) + #print(correlation) + #break + if highestCorrelation is None or correlation > highestCorrelation: + highestCorrelation = correlation + + lastMergedSingleColorChannelImage = mergedSingleColorChannelImage + +print(f'{highestCorrelationFile=} (and previous file) have a correlation of {highestCorrelation}') \ No newline at end of file