@@ -0,0 +1,1600 @@
+# License: Public Domain%0A# (C) 2014 Toshimitsu Kimura%0A%0Aimport sys%0Aimport cv2%0Aimport numpy as np%0Aimport math%0A%0Adef main():%0A    if len(sys.argv) != 3:%0A        print %22./circle_transform.py %3Cin_file%3E %3Cout_file%3E%22%0A        quit()%0A%0A    filename = sys.argv%5B1%5D%0A    outfile = sys.argv%5B2%5D%0A%0A    image = cv2.imread(filename, cv2.IMREAD_COLOR)%0A%0A    if image is None:%0A        print %22input file is not found%22%0A        quit()%0A%0A    circle = np.zeros(%5Bimage.shape%5B0%5D, image.shape%5B1%5D, 2%5D, dtype=np.float)%0A    center = %5Bimage.shape%5B0%5D/2.0, image.shape%5B1%5D/2.0%5D%0A%0A    for i in range(0, image.shape%5B0%5D):%0A        for j in range(0, image.shape%5B1%5D):%0A            pos = %5Bi-center%5B0%5D, j-center%5B1%5D%5D%0A            if pos%5B0%5D == 0: continue%0A            n = pos%5B1%5D/pos%5B0%5D # y = nx, x = y/n%0A            if n == 0: continue%0A            circle%5Bi,j,0%5D = 1.0 - math.sqrt(pos%5B0%5D**2 + pos%5B1%5D**2) / math.sqrt(min(center%5B0%5D**2 + (n*center%5B0%5D)**2, center%5B1%5D**2 + (center%5B1%5D/n)**2))%0A            circle%5Bi,j,1%5D = math.atan2(pos%5B1%5D, pos%5B0%5D)%0A%0A    img_out_size = max(image.shape%5B0%5D, image.shape%5B1%5D) / 2.0%0A    img_out = np.zeros(%5Bimg_out_size, img_out_size, image.shape%5B2%5D%5D, dtype=np.uint8)%0A%0A    out_half = %5Bimg_out.shape%5B0%5D/2.0, img_out.shape%5B1%5D/2.0%5D%0A    for i in range(0, image.shape%5B0%5D):%0A        for j in range(0, image.shape%5B1%5D):%0A            dist = circle%5Bi,j,0%5D%0A            rad = circle%5Bi,j,1%5D%0A            idx_x = (math.cos(rad)*dist*out_half%5B0%5D + out_half%5B0%5D)%25img_out.shape%5B0%5D%0A            idx_y = (math.sin(rad)*dist*out_half%5B1%5D + out_half%5B1%5D)%25img_out.shape%5B1%5D%0A            img_out%5Bidx_x, idx_y%5D = image%5Bi, j%5D%0A%0A    cv2.imwrite(outfile, img_out)%0A%0Amain()%0A

Add circle transform script that may be useful for OCR