<jupyter_start><jupyter_text>Crop input image into seperate letters  Import Modules<jupyter_code>import cv2
import numpy as np
import imutils
# Load image data
img = cv2.imread('data/2.jpg', -1)

rgb_planes = cv2.split(img)

result_planes = []
result_norm_planes = []

# Remove shadows
for plane in rgb_planes:
    dilated_img = cv2.dilate(plane, np.ones((7,7), np.uint8))
    bg_img = cv2.medianBlur(dilated_img, 21)
    diff_img = 255 - cv2.absdiff(plane, bg_img)
    norm_img = cv2.normalize(diff_img,None, alpha=0, beta=255, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_8UC1)
#     result_planes.append(diff_img)
    result_norm_planes.append(norm_img)

# result = cv2.merge(result_planes)
result_norm_planes_image = cv2.merge(result_norm_planes)

image = imutils.resize(result_norm_planes_image, height=800)#width=800,

# Increase brightness
# hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
# hsv[:,:,2] += 30
# image = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)

# make a copy
original = image.copy()

#convert to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

#parameters for threshold
thresholdValue = 0
maxVal = 255
thresholdingTechnique = cv2.THRESH_OTSU + cv2.THRESH_BINARY
thresh = cv2.threshold(gray,thresholdValue,maxVal,thresholdingTechnique)[1]

# Selecting ROIs
ROIs = cv2.selectROIs("Select Rois",original)
cv2.destroyAllWindows()
crop_number=0

#loop over every bounding box save in array "ROIs"
# for rect in ROIs:
for rect in ROIs:
    x1=rect[0]
    y1=rect[1]
    x2=rect[2]
    y2=rect[3]

    #crop roi from original image
    img_crop=thresh[y1:y1+y2,x1:x1+x2]

    #save cropped image
    cv2.imwrite("crop"+str(crop_number)+".jpeg",img_crop)
    crop_number+=1

cv2.waitKey(0)
cv2.destroyAllWindows()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11958997722095673, 'fraction_numerical': 0.042710706150341685, 'mean_word_length': 5.342960288808665, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '402975', 'license': 'MIT', 'n_tokens_mistral': 745, 'n_tokens_neox': 705, 'n_words': 131, 'path': 'script/old/1_crop_image2letters.ipynb', 'repo_name': 'bhagesh-codebeast/H2T', 'size': '1756'}