from pylab import clf, histogram, imshow, imread, bar, diff, xlim, show, \
    subplot, amin, amax

i = 1

def show_hist(a):
    global i
    subplot(2, 2, i)
    imshow(a, vmin=0, vmax=1)
    h, be = histogram(a.flatten(), bins=40)

    subplot(2, 2, i + 1)
    bar(be[:-1], h, width=diff(be)[0])
    xlim((0, 1))
    i += 2

def cst(f):
    fmin = amin(f)
    fmax = amax(f)
    return (f - fmin) / (fmax - fmin)

#a = imread('stinkbug.png')
a = imread('lowcontrast.png')

show_hist(a)
show_hist(cst(a))
show()
