[Tutor] New to Python - simple question
Kal Sze
swordangel at gmail.com
Sun Nov 18 06:15:16 CET 2012
On 18 November 2012 07:40, Alan Gauld <alan.gauld at btinternet.com> wrote:
> 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/
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
Hi all,
The function histogram is supposed to come from the numpy module; at
least that's the case on my computer (I have numpy 1.6.2 for Python
2.7):
>>> from numpy import *
>>> histogram
<function histogram at 0x10b0c0ed8>
Maybe something is wrong with Unaiza's version of numpy.
Kal
More information about the Tutor
mailing list