Demo iahisteq

Illustrate how to make a histogram equalization


The histogram equatization is an intensity transform that makes the histogram of the output image as flat as possible.


Computing the normalized cumulative histogram (NCH)

1. import ia636 as ia
3. f = adreadgray('woodlog.pgm')
4. adshow(f, 'input image f')
5. h = ia.iahistogram(f)
6. adshow(ia.iaplot(h, ylabel='n. occurrences', xlabel='gray scale'), 'Histogram')
7. nch = cumsum(h) / (1.*f.size)
8. adshow(ia.iaplot(nch, ylabel='percentage of occurrence', xlabel='gray scale'), 'Normalized cumulative histogram')

input image f


Normalized cumulative histogram

Use the NCH as intensity transform

1. gn = (255 * ia.iaapplylut(f, nch)).astype(uint8)
2. adshow(gn, 'equalized image')
3. gh = ia.iahistogram(gn)
4. adshow(ia.iaplot(gh, ylabel='n. occurrences', xlabel='gray scale'), 'Equalized histogram')
5. gch = cumsum(gh) # cumulative histogram
6. adshow(ia.iaplot(gch, ylabel='n. occurrences', xlabel='gray scale'), 'Cumulative histogram')

equalized image

Equalized histogram

Cumulative histogram

See Also