<jupyter_start><jupyter_text>Preprocessing of images<jupyter_code>import cv2
import numpy as np
from matplotlib import pyplot as plt
%matplotlib inline

file_location = "/home/syedjafer/Documents/Handwriting_recognition_svm/test1/images/aaa.png"
img = cv2.imread(file_location,0)
ret,thresh1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY)
ret,thresh2 = cv2.threshold(img,127,255,cv2.THRESH_BINARY_INV)
ret,thresh3 = cv2.threshold(img,127,255,cv2.THRESH_TRUNC)
ret,thresh4 = cv2.threshold(img,127,255,cv2.THRESH_TOZERO)
ret,thresh5 = cv2.threshold(img,127,255,cv2.THRESH_TOZERO_INV)

titles = ['Original Image','BINARY','BINARY_INV','TRUNC','TOZERO','TOZERO_INV']
images = [img, thresh1, thresh2, thresh3, thresh4, thresh5]

for i in range(6):
    plt.subplot(2,3,i+1),plt.imshow(images[i],'gray')
    plt.title(titles[i])
    plt.xticks([]),plt.yticks([])

plt.show()


cv2.imwrite("res.png",thresh1)


import glob 
image_location = "/home/syedjafer/Documents/Handwriting_recognition_svm/test1/images/"
folder_depth = 8 

image_x = []
image_y = []
files = []

# to get list of files in the current directory
for level in range(folder_depth):
    folder = chr(ord("a")+level)
    print (image_location+folder+"/")
    label_len = len(glob.glob(image_location+folder+"/"+"*.png"))
    files = files + glob.glob(image_location+folder+"/"+"*.png")
    print(files)

for file in files:
    img = cv2.imread(file,0)
    ret,thresh1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY)
    resized_image = cv.resize(thresh1, (100, 100))
    cv2.imwrite(file,resized_image)<jupyter_output>/home/syedjafer/Documents/Handwriting_recognition_svm/test1/images/a/
['/home/syedjafer/Documents/Handwriting_recognition_svm/test1/images/a/a_11.png', '/home/syedjafer/Documents/Handwriting_recognition_svm/test1/images/a/a_12.png', '/home/syedjafer/Documents/Handwriting_recognition_svm/test1/images/a/a_01.png', '/home/syedjafer/Documents/Handwriting_recognition_svm/test1/images/a/a_21.png', '/home/syedjafer/Documents/Handwriting_recognition_svm/test1/images/a/a_02.png', '/home/syedjafer/Documents/Handwriting_recognition_svm/test1/images/a/a_08.png', '/home/syedjafer/Documents/Handwriting_recognition_svm/test1/images/a/a_14.png', '/home/syedjafer/Documents/Handwriting_recognition_svm/test1/images/a/a_00.png', '/home/syedjafer/Documents/Handwriting_recognition_svm/test1/images/a/a_18.png', '/home/syedjafer/Documents/Handwriting_recognition_svm/test1/images/a/a_19.png', '/home/syedjafer/Documents/Handwriting_recognition_svm/test1/images/a/a_13.png', '/home/syedjafer/Documents/Handwriting[...]
{'fraction_non_alphanumeric': 0.15193798449612403, 'fraction_numerical': 0.044573643410852716, 'mean_word_length': 6.332386363636363, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '369250', 'license': 'MIT', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1029, 'n_words': 106, 'path': 'test1/images/.ipynb_checkpoints/Untitled-checkpoint.ipynb', 'repo_name': 'swapnilmarathe007/Handwriting-Recognition', 'size': '2580'}