<jupyter_start><jupyter_text>Testing Thresholding<jupyter_code>import numpy as np
import cv2
from tkinter import Tk, filedialog

# let user choose file, returns image
def open_image():
    root = Tk()
    root.fileName = filedialog.askopenfilename(
        initialdir="./samples",
        title="Select an Image",
        filetypes=((".jpg", "*.jpg"), (".png", "*.png"), ("all files", "*.*")),
    )
    fname = root.fileName
    image = cv2.imread(fname)
    return image


def thresholding(image, thresh):
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    blurred = cv2.GaussianBlur(gray, (9, 9), 0)
    retval, th = cv2.threshold(blurred, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
    return th
thresh_val = 40


def change_thresh(new_thresh):
    global thresh_val
    thresh_val = new_thresh

open_image()
cv2.namedWindow("Thresholding", cv2.WINDOW_AUTOSIZE)
cv2.createTrackbar("Thresh value", "Thresholding", thresh_val, 200, change_thresh)
while True:
    thresholded = thresholding(linearized_image, sigma)
    cv2.imshow("Thresholding", thresholded)
    key = cv2.waitKey(1)
    if key == 27:
        break<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12922810060711187, 'fraction_numerical': 0.02515177797051171, 'mean_word_length': 4.017391304347826, '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': '489852', 'license': 'MIT', 'n_tokens_mistral': 430, 'n_tokens_neox': 413, 'n_words': 90, 'path': 'notebooks/.ipynb_checkpoints/test-checkpoint.ipynb', 'repo_name': 'pun-ishment/Spectral-Curve-Calculator', 'size': '1153'}