<commit_before>import numpy as np
import os
import subprocess
import tempfile

# list of functions in this module:

# tmpfile
# run
# shellquote
#
# matrix_write
# matrix_read
# matrix_read_from_string
# matrix_translation
#
# bounding_box2D
# points_apply_homography
#
# image_crop_LARGE
# image_crop_TIFF
# image_apply_homography
# image_size
# image_crop
#
# image_sift_keypoints
# sift_keypoints_match
# image_qauto
#
# image_pleiades_unsharpening_mtf
# image_zeropadding_from_image_with_target_size
# image_fftconvolve


# add the bin folder to system path
current_dir = os.path.dirname(os.path.abspath(__file__))
bin_dir = '%s/../bin' % current_dir
os.environ['PATH'] += os.pathsep
os.environ['PATH'] += bin_dir

# global variable
# list of intermediary files generated by the script
garbage = list()

def tmpfile(ext=''):
    # TODO: fix this function
    # imout = os.tmpnam()+ext
    handler, imout = tempfile.mkstemp(suffix = ext)
    garbage.append(imout);
    return imout

def run(cmd):
    print cmd
    subprocess.call(cmd, shell=True)

def shellquote(s):
    return "'" + s.replace("'", "'\\''") + "'"

def matrix_write(filename , H12):
    f = open(filename,'w')
    f.write('[ %.20f  %.20f  %.20f ; '%(H12[0, 0], H12[0, 1], H12[0, 2]))
    f.write('  %.20f  %.20f  %.20f ; '%(H12[1, 0], H12[1, 1], H12[1, 2]))
    f.write('  %.20f  %.20f  %.20f ] '%(H12[2, 0], H12[2, 1], H12[2, 2]))
    f.close()

def matrix_read(fileName, rows=None, cols=None):
    return matrix_read_from_string(open(fileName).read(), rows, cols)

def matrix_read_from_string(line, rows=None, cols=None):
    x0 = []
    line = line.replace('[',' ')
    line = line.replace(']',' ')
    line = line.replace(',',' ')
    line = line.replace(';',' ')
    da = line.split()
    x0.append(map(float,da))
    #
    if(cols == None):
       x0 = np.array(x0)
    else:
       x0 = np.array(x0).reshape(rows, cols)
    #
    return(x0)

def matrix_translation(tx, ty):
    T = np.eye(3)
    T[0, 2] = tx;
    T[1, 2] = ty;
    return T

def image_size(im):
    out = tmpfile()
    run('imsize %s > %s' % (shellquote(im), out));
    (nc, nr) = map(int, open(out).read().split())
    return (nc, nr)

def image_pix_dim(im):
    out = tmpfile()
    run('imprintf "%%c" %s > %s' % (shellquote(im), out));
    dim = open(out).readline().split()[0]
    return int(dim) 

def image_crop(im, x, y, w, h, out=None):
    if (out == None):
        out = tmpfile()
    run('crop %s %s %d %d %d %d' % (im, out, x, y, w, h));
    return out<commit_msg>use 'imprintf' instead of 'imsize' in python image_size function to reduce dependencies<commit_after>import numpy as np
import os
import subprocess
import tempfile

# list of functions in this module:

# tmpfile
# run
# shellquote
#
# matrix_write
# matrix_read
# matrix_read_from_string
# matrix_translation
#
# bounding_box2D
# points_apply_homography
#
# image_crop_LARGE
# image_crop_TIFF
# image_apply_homography
# image_size
# image_crop
#
# image_sift_keypoints
# sift_keypoints_match
# image_qauto
#
# image_pleiades_unsharpening_mtf
# image_zeropadding_from_image_with_target_size
# image_fftconvolve


# add the bin folder to system path
current_dir = os.path.dirname(os.path.abspath(__file__))
bin_dir = '%s/../bin' % current_dir
os.environ['PATH'] += os.pathsep
os.environ['PATH'] += bin_dir

# global variable
# list of intermediary files generated by the script
garbage = list()

def tmpfile(ext=''):
    # TODO: fix this function
    # imout = os.tmpnam()+ext
    handler, imout = tempfile.mkstemp(suffix = ext)
    garbage.append(imout);
    return imout

def run(cmd):
    print cmd
    subprocess.call(cmd, shell=True)

def shellquote(s):
    return "'" + s.replace("'", "'\\''") + "'"

def matrix_write(filename , H12):
    f = open(filename,'w')
    f.write('[ %.20f  %.20f  %.20f ; '%(H12[0, 0], H12[0, 1], H12[0, 2]))
    f.write('  %.20f  %.20f  %.20f ; '%(H12[1, 0], H12[1, 1], H12[1, 2]))
    f.write('  %.20f  %.20f  %.20f ] '%(H12[2, 0], H12[2, 1], H12[2, 2]))
    f.close()

def matrix_read(fileName, rows=None, cols=None):
    return matrix_read_from_string(open(fileName).read(), rows, cols)

def matrix_read_from_string(line, rows=None, cols=None):
    x0 = []
    line = line.replace('[',' ')
    line = line.replace(']',' ')
    line = line.replace(',',' ')
    line = line.replace(';',' ')
    da = line.split()
    x0.append(map(float,da))
    #
    if(cols == None):
       x0 = np.array(x0)
    else:
       x0 = np.array(x0).reshape(rows, cols)
    #
    return(x0)

def matrix_translation(tx, ty):
    T = np.eye(3)
    T[0, 2] = tx;
    T[1, 2] = ty;
    return T

def image_size(im):
    out = tmpfile()
    run('imprintf "%%w %%h" %s > %s' % (shellquote(im), out));
    (nc, nr) = map(int, open(out).read().split())
    return (nc, nr)

def image_pix_dim(im):
    out = tmpfile()
    run('imprintf "%%c" %s > %s' % (shellquote(im), out));
    dim = open(out).readline().split()[0]
    return int(dim)

def image_crop(im, x, y, w, h, out=None):
    if (out == None):
        out = tmpfile()
    run('crop %s %s %d %d %d %d' % (im, out, x, y, w, h));
    return out
{'fraction_non_alphanumeric': 0.17560975609756097, 'fraction_numerical': 0.027317073170731707, 'mean_word_length': 3.5004389815627746, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4071178', 'n_tokens_mistral': 2100, 'n_tokens_neox': 2025, 'n_words': 468}