Add find_consecutive_most_similar_images.py
Using: -dd80ba940a/utils.py (L53-L55)
-dd80ba940a/chen.py (L81-L89)
This commit is contained in:
parent
93a3078743
commit
0dd21ad34d
46
datasets/raise/find_consecutive_most_similar_images.py
Normal file
46
datasets/raise/find_consecutive_most_similar_images.py
Normal file
@ -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}')
|
Loading…
x
Reference in New Issue
Block a user