<commit_before>#!/usr/bin/env python

import os,sys,math,operator
import numpy as np
from scipy import ndimage, misc
import argparse

parser = argparse.ArgumentParser(description="Unwrap photos from a parabolic mirror")
parser.add_argument("input", metavar="Input Image", help="Input Image File")
parser.add_argument("output", metavar="Output Image", help="Output Image File")
parser.add_argument("--center", help="Position of center pixel in the form x,y or \" +/-x,+/-y\"")
parser.add_argument("--size", help="Output image size in the form WIDTHxHEIGHT")
args = parser.parse_args()
raw_img = misc.imread(args.input)

center = (raw_img.shape[0] / 2, raw_img.shape[1] / 2)
if args.center:
  try:
    x,y = args.center.split(',')
    if '-' in args.center or '+' in args.center:
      new_center = (center[0] + int(y), center[1] + int(x))
      center = new_center
    else:
      center = (int(y),int(x))
  except:
    print "Center must me integers in the form x,y or +/-x,+/-y"
    sys.exit(-1)

size = (1024, 2048)
if args.size:
  try:
    width,height = args.size.split('x')
    width = int(width)
    height = int(height) 
    size = (height,width)
  except:
    print  "Size must be integers in the form WIDTHxHEIGHT"
    sys.exit(-1)
    
square_img = np.zeros((size[0], size[1]), np.uint8)
color_img  = np.zeros((size[0], size[1], 3), np.uint8)
it = np.nditer(square_img, flags=['multi_index'], op_flags=['readwrite'])
while not it.finished:
    axA = it.multi_index[0]
    axB = it.multi_index[1]

    radius = ((size[0]-float(axA)-1)/size[0])*center[0]
    cx = math.cos(2*math.pi*axB/size[1])*radius + center[1]
    cy = math.sin(2*math.pi*axB/size[1])*radius + center[0]
    r = raw_img[cy, cx, 0]
    g = raw_img[cy, cx, 1]
    b = raw_img[cy, cx, 2]

    color_img[axA, axB, 0] = r
    color_img[axA, axB, 1] = g
    color_img[axA, axB, 2] = b

    it.iternext()
misc.imsave(args.output, color_img)<commit_msg>Fix unwrap direction<commit_after>#!/usr/bin/env python

import os,sys,math,operator
import numpy as np
from scipy import ndimage, misc
import argparse

parser = argparse.ArgumentParser(description="Unwrap photos from a parabolic mirror")
parser.add_argument("input", metavar="Input Image", help="Input Image File")
parser.add_argument("output", metavar="Output Image", help="Output Image File")
parser.add_argument("--center", help="Position of center pixel in the form x,y or \" +/-x,+/-y\"")
parser.add_argument("--size", help="Output image size in the form WIDTHxHEIGHT")
args = parser.parse_args()
raw_img = misc.imread(args.input)

center = (raw_img.shape[0] / 2, raw_img.shape[1] / 2)
if args.center:
  try:
    x,y = args.center.split(',')
    if '-' in args.center or '+' in args.center:
      new_center = (center[0] + int(y), center[1] + int(x))
      center = new_center
    else:
      center = (int(y),int(x))
  except:
    print "Center must me integers in the form x,y or +/-x,+/-y"
    sys.exit(-1)

size = (1024, 2048)
if args.size:
  try:
    width,height = args.size.split('x')
    width = int(width)
    height = int(height) 
    size = (height,width)
  except:
    print  "Size must be integers in the form WIDTHxHEIGHT"
    sys.exit(-1)
    
square_img = np.zeros((size[0], size[1]), np.uint8)
color_img  = np.zeros((size[0], size[1], 3), np.uint8)
it = np.nditer(square_img, flags=['multi_index'], op_flags=['readwrite'])
while not it.finished:
    axA = it.multi_index[0]
    axB = it.multi_index[1]

    radius = ((size[0]-float(axA)-1)/size[0])*center[0]
    cx = -math.cos(2*math.pi*axB/size[1])*radius + center[1]
    cy = math.sin(2*math.pi*axB/size[1])*radius + center[0]
    r = raw_img[cy, cx, 0]
    g = raw_img[cy, cx, 1]
    b = raw_img[cy, cx, 2]

    color_img[axA, axB, 0] = r
    color_img[axA, axB, 1] = g
    color_img[axA, axB, 2] = b

    it.iternext()
misc.imsave(args.output, color_img)
{'fraction_non_alphanumeric': 0.1703838174273859, 'fraction_numerical': 0.021265560165975105, 'mean_word_length': 3.7267156862745097, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1391228', 'n_tokens_mistral': 1539, 'n_tokens_neox': 1463, 'n_words': 353}