In [1]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt

In [2]:
im = plt.imread('testim.png')
print(im.dtype, im.shape, np.min(im), np.max(im))
plt.imshow(im)


float32 (267, 477, 3) 0.0 1.0
Out[2]:
<matplotlib.image.AxesImage at 0x7e76a90>

In [3]:
def contrast_adjustmenst(im, c, l):
    return (c * (im ** l))

In [4]:
plt.imshow(contrast_adjustmenst(im, 1, 0.37))


Out[4]:
<matplotlib.image.AxesImage at 0x7f5ff98>

In [5]:
plt.imshow(contrast_adjustmenst(im, 1, 1.37))


Out[5]:
<matplotlib.image.AxesImage at 0x7cbb7f0>

In [6]:
def contrast_scaling(im):
    rmax, rmin = np.max(im, axis=(0, 1)), np.min(im, axis=(0, 1))
    return (im - rmin) / (rmax - rmin)

In [7]:
im = plt.imread('testim.png')
im[im<0.2] = 0.2  # for illustration purpose
im[im>0.8] = 0.8 # for illustration purpose
plt.figure(figsize=(8, 8))
plt.subplot(121)
plt.imshow(im)
plt.subplot(122)
plt.imshow(contrast_scaling(im))


Out[7]:
<matplotlib.image.AxesImage at 0x7ff1710>

In [ ]: