mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-06 12:53:12 +03:00
Merge pull request #7593 from florath/ImageStat_getextrema_opt
Optimize ImageStat.Stat._getextrema function
This commit is contained in:
commit
e9afaee248
|
@ -51,13 +51,16 @@ class Stat:
|
||||||
"""Get min/max values for each band in the image"""
|
"""Get min/max values for each band in the image"""
|
||||||
|
|
||||||
def minmax(histogram):
|
def minmax(histogram):
|
||||||
n = 255
|
res_min, res_max = 255, 0
|
||||||
x = 0
|
|
||||||
for i in range(256):
|
for i in range(256):
|
||||||
if histogram[i]:
|
if histogram[i]:
|
||||||
n = min(n, i)
|
res_min = i
|
||||||
x = max(x, i)
|
break
|
||||||
return n, x # returns (255, 0) if there's no data in the histogram
|
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)]
|
return [minmax(self.h[i:]) for i in range(0, len(self.h), 256)]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user