Did I find the right examples for you? yes no

# PIL.ImageOps.autocontrast

All Samples(29)  |  Call(29)  |  Derive(0)  |  Import(0)
```Maximize (normalize) image contrast. This function calculates a
histogram of the input image, removes **cutoff** percent of the
lightest and darkest pixels from the histogram, and remaps the image
so that the darkest pixel becomes black (0), and the lightest
becomes white (255).

:param image: The image to process.
:param cutoff: How many percent to cut off from the histogram.
:param ignore: The background pixel value (use None for no background).
:return: An image.
```

```        def autocontrast(image, cutoff=0, ignore=None):
"""
Maximize (normalize) image contrast. This function calculates a
histogram of the input image, removes **cutoff** percent of the
lightest and darkest pixels from the histogram, and remaps the image
so that the darkest pixel becomes black (0), and the lightest
becomes white (255).

:param image: The image to process.
:param cutoff: How many percent to cut off from the histogram.
:param ignore: The background pixel value (use None for no background).
:return: An image.
"""
histogram = image.histogram()
lut = []
for layer in range(0, len(histogram), 256):
h = histogram[layer:layer+256]
if ignore is not None:
# get rid of outliers
try:
h[ignore] = 0
except TypeError:
# assume sequence
for ix in ignore:
h[ix] = 0
if cutoff:
# cut off pixels from both ends of the histogram
# get number of pixels
n = 0
for ix in range(256):
n = n + h[ix]
# remove cutoff% pixels from the low end
cut = n * cutoff // 100
for lo in range(256):
if cut > h[lo]:
cut = cut - h[lo]
h[lo] = 0
else:
h[lo] = h[lo] - cut
cut = 0
if cut <= 0:
break
# remove cutoff% samples from the hi end
cut = n * cutoff // 100
for hi in range(255, -1, -1):
if cut > h[hi]:
cut = cut - h[hi]
h[hi] = 0
else:
h[hi] = h[hi] - cut
cut = 0
if cut <= 0:
break
# find lowest/highest samples after preprocessing
for lo in range(256):
if h[lo]:
break
for hi in range(255, -1, -1):
if h[hi]:
break
if hi <= lo:
# don't bother
lut.extend(list(range(256)))
else:
scale = 255.0 / (hi - lo)
offset = -lo * scale
for ix in range(256):
ix = int(ix * scale + offset)
if ix < 0:
ix = 0
elif ix > 255:
ix = 255
lut.append(ix)
return _lut(image, lut)
```

```    def process(self, img):
return ImageOps.autocontrast(img,
cutoff=self.cutoff,
ignore=self.ignore)

```

```      alpha = croppedImage.split()[1]
croppedImage = \
ImageOps.autocontrast(croppedImage.split()[0], cutoff=self.cutoff)
croppedImage.putalpha(alpha)
image.paste(croppedImage, image.bbox)
```
```      # Equalize the composite image
compositeImage = \
ImageOps.autocontrast(compositeImage.split()[0], cutoff=self.cutoff)
# Paste the part of the equalized image within the mask back
# into the cropped image
```
```    elif self.region == 'all':
alpha = image.split()[1]
image = ImageOps.autocontrast(image.split()[0], cutoff=self.cutoff)
image.putalpha(alpha)
return image
```

```    def autocontrast(self, image, params):
return ImageOps.autocontrast(image, params.get('cutoff', 0))

def equalize(self, image, params):
return ImageOps.equalize(image)
```

```    def autocontrast(self, image, params):
return ImageOps.autocontrast(image, params.get('cutoff', 0))

def equalize(self, image, params):
return ImageOps.equalize(image)
```

```        im = ImageEnhance.Brightness(im).enhance(brightness)
if autocontrast and im.mode in ('L', 'RGB'):
im = ImageOps.autocontrast(im, cutoff=0.1)
elif contrast != 1.0:
im = ImageEnhance.Contrast(im).enhance(contrast)
```

```			im = im.crop((f.x-50, f.y-50, f.x+f.width+50, f.y+f.height+50))
im = ImageOps.autocontrast(im, cutoff=0.5)
crop = '%s/%s_crop_%s.jpg' % (CROP_DIR, os.path.basename(file), i)
```

```    def optimizeContrast(self, subscriber, image):
im = image.getSliceAsImage()
co = self.paramCutoff.value
result = ImageOps.autocontrast(im, co)
return DataContainer.DataContainer(result, image.units)
```

```    def optimizeContrast(self, subscriber, image):
im = image.getSliceAsImage()
co = self.paramCutoff.value
result = ImageOps.autocontrast(im, co)
return DataContainer.DataContainer(result, image.units)
```

```                gamma = 1.0
if gamma == 1.0:
self.image = ImageOps.autocontrast(self.image)
else:
self.image = ImageOps.autocontrast(Image.eval(self.image, lambda a: 255 * (a / 255.) ** gamma))
```

```        im = im.resize((w,h),Image.ANTIALIAS)