Re: [Tutor] New to Python - simple question

2012-11-17 Thread staticsafe
On 11/16/2012 12:40, Unaiza Ahsan wrote:
 Hi all,
 
 I am following Jan Erik Solem's book Programming Computer Vision with
 Python and I'm just on the first chapter. The book asked us to create a
 file imtools.py and put down helpful functions there, which we can just
 call later.
 
 There is a function created for histogram equalization of images (called *
 histeq*), and saved in imtools.py. When I use this function and type this
 in IDLE:
 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):
   File pyshell#59, line 1, in module
 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
 
 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)
 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
 
 
 Can anybody point out where I'm going wrong? I have Python 2.7, NumPY,
 SciPY etc.
 
 Thanks very much
 
 Python Newbie!

Where is the histogram() function from? Is it in imtools.py as well?
-- 
staticsafe
O ascii ribbon campaign - stop html mail - www.asciiribbon.org
Please don't top post - http://goo.gl/YrmAb
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Formatting questions regarding datetime.isoformat()

2012-09-05 Thread staticsafe
Hello,

I am running Python 2.6.6 on a Debian Squeeze system. I am using two
modules in this bit of code - datetime and python-tvrage (available on
pypy here: http://pypi.python.org/pypi/python-tvrage/).

My goal is to find the time remaining until a certain show airs. Here is
some code I have written so far:

#!/usr/bin/env python
from tvrage import quickinfo
from datetime import tzinfo, timedelta, datetime

showinfo = quickinfo.fetch(Warehouse 13)
nextairdate = showinfo['RFC3369']
now = datetime.now().isoformat()

Now for my question/problem.

In [68]: showinfo['RFC3339']
Out[68]: '2012-09-10T21:00:00-4:00'

In [72]: datetime.now().isoformat()
Out[72]: '2012-09-05T22:47:46.061688'

isoformat() is in a different format than the value returned by the API.
My question is how would one format both values so that I can perform a
timedelta on them as is the purpose of my code?

I hope I have provided the right amount of detail for my question.

Thanks,
-- 
staticsafe
http://staticsafe.ca
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor