Move getImageNpArray to utils.py

This commit is contained in:
Benjamin Loison 2024-05-03 02:32:05 +02:00
parent 790c0d6da4
commit 4bea5e3a97
No known key found for this signature in database
2 changed files with 17 additions and 17 deletions

View File

@ -4,7 +4,7 @@ import numpy as np
import os
from tqdm import tqdm
import csv
from utils import Color, denoise, iterativeMean, isARawImage, escapeFilePath, getColorChannel, saveNpArray, rescaleRawImageForDenoiser, updateExtremes, getColorMeans
from utils import Color, denoise, iterativeMean, escapeFilePath, saveNpArray, getColorMeans, getImageNpArray
import matplotlib.pyplot as plt
imagesFolderPath = 'rafael/arw'
@ -54,25 +54,11 @@ def getImageFilePath(imageFileName):
imageFilePath = f'{imagesFolderPath}/{imageFileName}'
return imageFilePath
def getImageNpArray(imageFileName, computeExtremes, color):
global minColor, maxColor
imageFilePath = getImageFilePath(imageFileName)
imageNpArray = getColorChannel(imageFilePath, color)
if computeExtremes:
minColor, maxColor = updateExtremes(imageNpArray, minColor, maxColor)
return
if isARawImage(imageFileName) and denoiser != 'mean':
imageNpArray = rescaleRawImageForDenoiser(imageNpArray, minColor, maxColor)
# Pay attention to range of values expected by the denoiser.
# Indeed if provide the thousands valued raw image, then the denoiser only returns values between 0 and 1 and making the difference between both look pointless.
return imageNpArray
# `color` is the actual color to estimate PRNU with.
def treatImage(imageFileName, computeExtremes = False, color = None):
global estimatedPrnuIterativeMean
imageNpArray = getImageNpArray(imageFileName, computeExtremes, color)
imageFilePath = getImageFilePath(imageFileName)
imageNpArray = getImageNpArray(imageFilePath, computeExtremes, color)
if imageNpArray is None:
return
if denoiser != 'mean':

View File

@ -142,3 +142,17 @@ def getColorMeans(imagesFileNames, colors = Color):
colorIterativeMean.add(imageNpArray)
colorMeans[color] = colorIterativeMean.mean
return colorMeans
def getImageNpArray(imageFilePath, computeExtremes, color):
global minColor, maxColor
imageNpArray = getColorChannel(imageFilePath, color)
if computeExtremes:
minColor, maxColor = updateExtremes(imageNpArray, minColor, maxColor)
return
if isARawImage(imageFilePath) and denoiser != 'mean':
imageNpArray = rescaleRawImageForDenoiser(imageNpArray, minColor, maxColor)
# Pay attention to range of values expected by the denoiser.
# Indeed if provide the thousands valued raw image, then the denoiser only returns values between 0 and 1 and making the difference between both look pointless.
return imageNpArray