[Tutor] New to Python - simple question
Alan Gauld
alan.gauld at btinternet.com
Sun Nov 18 00:40:55 CET 2012
On 16/11/12 17:40, Unaiza Ahsan wrote:
> There is a function created for histogram equalization of images (called
> *histeq*), and saved in imtools.py.
>>>> from PIL import Image
>>>> from numpy import *
>>>> im = array(Image.open('Tulips.jpg').convert('L'))
>>>> im2,cdf = imtools.histeq(im)
>
> I get this:
>
> Traceback (most recent call last):
> im2,cdf = imtools.histeq(im)
> File "C:\Python27\imtools.py", line 18, in histeq
> imhist,bins = histogram(im.flatten(),nbr_bins,normed=True)
> NameError: global name 'histogram' is not defined
This tells us that the name histogram is not defined
in the imtools.py file. Is it one of the modules ytou show imported
above? If so it will not be visible inside imtools.py. You need to
import the required module in that file too.
But that's just a guess...
> And the relevant portion in imtools.py is:
> def histeq(im,nbr_bins=256):
> """ Histogram equalization of a grayscale image. """
>
> #get image histogram
> imhist,bins = histogram(im.flatten(),nbr_bins,normed=True)
This is the call, but where is histogram? If it is in imtools are you
sure the spelling is correct? If its not there you need to import it
from wherever it is defined.
HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list