diff options
author | kickbutt <kickbutt@yandex-team.com> | 2024-01-23 23:36:43 +0300 |
---|---|---|
committer | Alexander Smirnov <alex@ydb.tech> | 2024-01-24 15:02:13 +0300 |
commit | 299dc21a6f70a16b00e1d564fa56961331552415 (patch) | |
tree | 183f498a2e98a04f9a6143a11006ba0c10f867f3 /contrib/python/Pillow/py3/PIL/ImageStat.py | |
parent | 5ccb6ae864be6b53df427dc3a0fa14dbb95aa11c (diff) | |
download | ydb-299dc21a6f70a16b00e1d564fa56961331552415.tar.gz |
Fix separator in CUDA_ARCHITECTURES
Diffstat (limited to 'contrib/python/Pillow/py3/PIL/ImageStat.py')
-rw-r--r-- | contrib/python/Pillow/py3/PIL/ImageStat.py | 55 |
1 files changed, 18 insertions, 37 deletions
diff --git a/contrib/python/Pillow/py3/PIL/ImageStat.py b/contrib/python/Pillow/py3/PIL/ImageStat.py index b7ebddf066..13864e59cf 100644 --- a/contrib/python/Pillow/py3/PIL/ImageStat.py +++ b/contrib/python/Pillow/py3/PIL/ImageStat.py @@ -20,10 +20,9 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations -import functools import math -import operator class Stat: @@ -53,26 +52,22 @@ class Stat: """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 - v = [] - for i in range(0, len(self.h), 256): - v.append(minmax(self.h[i:])) - return v + return [minmax(self.h[i:]) for i in range(0, len(self.h), 256)] def _getcount(self): """Get total number of pixels in each layer""" - - v = [] - for i in range(0, len(self.h), 256): - v.append(functools.reduce(operator.add, self.h[i : i + 256])) - return v + return [sum(self.h[i : i + 256]) for i in range(0, len(self.h), 256)] def _getsum(self): """Get sum of all pixels in each layer""" @@ -98,11 +93,7 @@ class Stat: def _getmean(self): """Get average pixel level for each layer""" - - v = [] - for i in self.bands: - v.append(self.sum[i] / self.count[i]) - return v + return [self.sum[i] / self.count[i] for i in self.bands] def _getmedian(self): """Get median pixel level for each layer""" @@ -121,28 +112,18 @@ class Stat: def _getrms(self): """Get RMS for each layer""" - - v = [] - for i in self.bands: - v.append(math.sqrt(self.sum2[i] / self.count[i])) - return v + return [math.sqrt(self.sum2[i] / self.count[i]) for i in self.bands] def _getvar(self): """Get variance for each layer""" - - v = [] - for i in self.bands: - n = self.count[i] - v.append((self.sum2[i] - (self.sum[i] ** 2.0) / n) / n) - return v + return [ + (self.sum2[i] - (self.sum[i] ** 2.0) / self.count[i]) / self.count[i] + for i in self.bands + ] def _getstddev(self): """Get standard deviation for each layer""" - - v = [] - for i in self.bands: - v.append(math.sqrt(self.var[i])) - return v + return [math.sqrt(self.var[i]) for i in self.bands] Global = Stat # compatibility |