from math import hypot, pi, cos, sin
from PIL import Image


def hough(im, ntx=460, mry=360):
    
    pim = im.load()
    nimx, mimy = im.size
    mry = int(mry/2)*2          
    him = Image.new(, (ntx, mry), 255)
    phim = him.load()

    rmax = hypot(nimx, mimy)
    dr = rmax / (mry/2)
    dth = pi / ntx

    for jx in xrange(nimx):
        for iy in xrange(mimy):
            col = pim[jx, iy]
            if col == 255: continue
            for jtx in xrange(ntx):
                th = dth * jtx
                r = jx*cos(th) + iy*sin(th)
                iry = mry/2 + int(r/dr+0.5)
                phim[jtx, iry] -= 1
    return him


def test():
    
    im = Image.open().convert()
    him = hough(im)
    him.save()


if __name__ == : test()