Skip to content

Commit

Permalink
Merge pull request #7593 from florath/ImageStat_getextrema_opt
Browse files Browse the repository at this point in the history
 Optimize ImageStat.Stat._getextrema function
  • Loading branch information
radarhere committed Dec 6, 2023
2 parents 9248f71 + ed03954 commit e9afaee
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/PIL/ImageStat.py
Expand Up @@ -51,13 +51,16 @@ def _getextrema(self):
"""Get min/max values for each band in the image"""

def minmax(histogram):
n = 255
x = 0
res_min, res_max = 255, 0
for i in range(256):
if histogram[i]:
n = min(n, i)
x = max(x, i)
return n, x # returns (255, 0) if there's no data in the histogram
res_min = i
break
for i in range(255, -1, -1):
if histogram[i]:
res_max = i
break
return res_min, res_max

return [minmax(self.h[i:]) for i in range(0, len(self.h), 256)]

Expand Down

0 comments on commit e9afaee

Please sign in to comment.