<commit_before>import os
from PIL import Image
import numpy as np


def crop_images(image):
    return image

def align_to_square(image):
    return image

def preprocess(directory):
    save_path = (directory+"/preProcessed/")
    if not os.path.exists(save_path):
        os.makedirs(save_path)
    image_list = os.listdir(directory)
    for i in xrange(len(image_list)):
        image_name = image_list[i]
        print "Currently processing: "+ image_name
        image = Image.open(directory+"/"+image_name)
        image = crop_images(image)
        width, height = image.size
        image = image.resize((64,64*height/width))
        image = align_to_square(image)
        image.save(save_path +image)<commit_msg>Added the crop function<commit_after>import os
from PIL import Image
import numpy as np


def crop_images(image):
    image_array = np.asarray(image, dtype="uint8")
    image_array_0= image_array[:,:,0]+image_array[:,:,1]+image_array[:,:,2]
    sum_of_column = image_array_0.sum(axis=0)
    i, j = 0, len(sum_of_column)-1
    start_column, end_column = i,j
    while(sum_of_column[i] < sum_of_column.min()+(sum_of_column.max()-sum_of_column.min())/50):
        start_column = i
        i += j
    while(sum_of_column[j] < sum_of_column.min()+(sum_of_column.max()-sum_of_column.min())/50):
        end_column = j
        j -= 1
    sum_of_row = image_array_0.sum(axis=1)
    while(sum_of_row[i] < sum_of_row.min()+(sum_of_row.max()-sum_of_row.min())/50):
        start_row = i
        i += j
    while(sum_of_row[j] < sum_of_row.min()+(sum_of_row.max()-sum_of_row.min())/50):
        end_row = j
        j -= 1
    new_image_array = image_array[start_row:end_row,start_column:end_column,:]
    image = Image.fromarray(new_image_array,"RGB")
    return image

def align_to_square(image):
    return image

def preprocess(directory, custom_height, custom_width):
    save_path = (directory+"/preProcessed/")
    if not os.path.exists(save_path):
        os.makedirs(save_path)
    image_list = os.listdir(directory)
    for i in xrange(len(image_list)):
        image_name = image_list[i]
        print "Currently processing: "+ image_name
        image = Image.open(directory+"/"+image_name)
        image = crop_images(image)
        width, height = image.size
        image = image.resize((custom_height,custom_width*height/width))
        image = align_to_square(image)
        image.save(save_path +image)
{'fraction_non_alphanumeric': 0.12644151565074135, 'fraction_numerical': 0.01029654036243822, 'mean_word_length': 3.4163636363636365, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1538314', 'n_tokens_mistral': 858, 'n_tokens_neox': 845, 'n_words': 150}