From ee7353cfde7a4dc88e607d6730fd9463b76451c3 Mon Sep 17 00:00:00 2001 From: Benjamin Loison <12752145+Benjamin-Loison@users.noreply.github.com> Date: Sat, 27 Apr 2024 15:58:29 +0200 Subject: [PATCH] Correct `iterativeMean` implementation for images Otherwise get: ``` Traceback (most recent call last): File "/home/benjamin/robust_image_source_identification_on_modern_smartphones/datasets/raise/./extract_noise.py", line 148, in treatImage(imageFileName, color = color) File "/home/benjamin/robust_image_source_identification_on_modern_smartphones/datasets/raise/./extract_noise.py", line 114, in treatImage estimatedPrnuIterativeMean.add(imageNoiseNpArray) File "/home/benjamin/robust_image_source_identification_on_modern_smartphones/datasets/raise/utils.py", line 34, in add self.mean = ((self.mean * self.numberOfElementsInMean) + element) / (self.numberOfElementsInMean + 1) ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TypeError: unsupported operand type(s) for *: 'NoneType' and 'int' ``` --- datasets/raise/utils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/datasets/raise/utils.py b/datasets/raise/utils.py index 258c80a..1ce8916 100644 --- a/datasets/raise/utils.py +++ b/datasets/raise/utils.py @@ -31,5 +31,8 @@ class iterativeMean: numberOfElementsInMean = 0 def add(self, element): - self.mean = ((self.mean * self.numberOfElementsInMean) + element) / (self.numberOfElementsInMean + 1) - self.numberOfElementsInMean += 1 \ No newline at end of file + if self.mean is None: + self.mean = element + else: + self.mean = ((self.mean * self.numberOfElementsInMean) + element) / (self.numberOfElementsInMean + 1) + self.numberOfElementsInMean += 1