From 033abea7e36821d2e390c5a55834f090ab1c429d Mon Sep 17 00:00:00 2001 From: Technoduck Date: Wed, 11 Dec 2024 19:04:29 -0500 Subject: [PATCH] more warning about red and blue averaging function --- app.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 8b478eb..39318be 100644 --- a/app.py +++ b/app.py @@ -288,11 +288,20 @@ class renderedImageZoom: def get_image_average(self,color,low, high): + #i keep getting divizion by zero errors in the branches where it should be impossible to get a division by zero error. + # sometimes i truly hate python if color == "blue": slice = self.image[:][low:high] blue = 0 for line in slice: - blue += sum([p[2]/(p[0]+p[1]+p[2]) for p in line]) + for pixel in line: + print(type(pixel)) + if pixel[2] == 0 or pixel[2] == None: + blue += 0 + else: + blue += pixel[2]/(pixel[0]+pixel[1]+pixel[2]) + print("active pixel value",pixel[2]/sum(pixel)) + print(blue) blue = blue / (100*(high-low)) return "{} is the pixel average".format(blue) @@ -301,10 +310,11 @@ class renderedImageZoom: red = 0 for line in slice: for pixel in line: - if sum(pixel) == 0: + if pixel[0] == 0 or pixel[0] == None: red += 0 else: - red += pixel[0]/sum(pixel) + red += pixel[2]/(pixel[0]+pixel[1]+pixel[2]) + print(red) red = red / (100*(high-low)) return "{} is the pixel average".format(red)