[Tutor] New to Python - simple question

Unaiza Ahsan unaiza.ahsan at gmail.com
Tue Nov 20 15:06:04 CET 2012


I'm on Chapter 1 of Solem's book. The following function definition needs
to be added to imtools.py: [I did paste this I think in my first email].

import os
from numpy import *

def histeq(im,nbr_bins=256):
""" Histogram equalization of a grayscale image. """
# get image histogram
imhist,bins = histogram(im.flatten(),nbr_bins,normed=True)
cdf = imhist.cumsum() # cumulative distribution function
cdf = 255 * cdf / cdf[-1] # normalize
# use linear interpolation of cdf to find new pixel values
im2 = interp(im.flatten(),bins[:-1],cdf)
return im2.reshape(im.shape), cdf


Now this file is saved as imtools.py in my main C:\Python27 folder.

In IDLE, I'm supposed to write:

from PIL import Image
from numpy import *
im = array(Image.open(’AquaTermi_lowcontrast.jpg’).convert(’L’))
im2,cdf = imtools.histeq(im)

That's it. That's the code I'm using. But it's giving me that error that
"histogram" is not found.

Er, I just checked the numpy version I have downloaded. It indeed doesn't
have any histogram (although its documentation says it should :s). Sorry. I
had checked the documentation first (and thought that this version contains
histogram).

I think the function histogram is not defined in numpy at all. It's in
something called "mahotas" (No idea what that is).

Thanks all for the help.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121120/d3c62b11/attachment.html>


More information about the Tutor mailing list