<jupyter_start><jupyter_text><jupyter_code>import cv2
import numpy as np
import matplotlib
from matplotlib.pyplot import imshow
from matplotlib import pyplot as plt
from google.colab.patches import cv2_imshow as show

img = cv2.imread('./andrew_w00_fix_1_csi.tif')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

kernel_size = 5
#blur_gray = cv2.GaussianBlur(gray,(kernel_size, kernel_size),0)

#Create default Fast Line Detector (FSD)
fld = cv2.ximgproc.createFastLineDetector()

#Detect lines in the image
lines = fld.detect(gray)

#Draw detected lines in the image
drawn_img = fld.drawSegments(img,lines)

#Show image
cv2_imshow(img)
cv2.waitKey(0)

import sys
from PIL import Image

#source https://note.nkmk.me/en/python-numpy-image-processing/
#Passing the image data read by PIL.Image.open() to np.array() returns 3D ndarray whose shape is (row (height), column (width), color (channel)).
# convert('L') returns the image as grayscale

im = np.array(Image.open('./andrew_w00_fix_1_csi.tif').convert('L'))

# Shape of the array
im.shape


# You can get the value of a pixel by specifying the coordinates at the index [row, columns] 
# of ndarray. Note that the order is y, x in xy coordinates. The origin is the upper left.

copy = np.array(im)

for x in range(500):
  for y in range(768):
    if(copy[x][y] < 22):
      copy[x][y] = 0
    else:
      copy[x][y] = 255

      
pil_img = Image.fromarray(copy)
pil_img
lines = fld.detect(copy)

#Draw detected lines in the image
drawn_img = fld.drawSegments(img,lines)

#Show image
cv2_imshow(img)
cv2.waitKey(0)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1111111111111111, 'fraction_numerical': 0.02197112366603892, 'mean_word_length': 4.672597864768683, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 1, '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': '525021', 'license': 'MIT', 'n_tokens_mistral': 613, 'n_tokens_neox': 586, 'n_words': 171, 'path': 'task1_Imagepreprocessing.ipynb', 'repo_name': 'raynerz/BankAccount', 'size': '1593'}