scanbook/process.py
def process(filename, folder, threshold=19):
    """
    Processes an image file and saves the processed image to the specified
    folder.
    """
    image = cv2.imread(filename)

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

    # Threshold it
    T = threshold_local(image, threshold, offset=10, method='gaussian')
    image = (image > T).astype('uint8') * 255

    # Slightly blur it
    gaussian = cv2.GaussianBlur(image, (9, 9), 0.0)

    # Sharpen it
    image = cv2.addWeighted(image, 1.5, gaussian, -0.5, 0, image)

    # # And blur it again
    image = cv2.GaussianBlur(image, (3, 3), 10.0)

    # Resize it to 2500px high
    height = 2500
    scale_factor = height / image.shape[0]
    width = int(scale_factor * image.shape[1])
    image = cv2.resize(image, (width, height), interpolation=cv2.INTER_AREA)

    cv2.imwrite(f'{folder}/{filename}', image)

    Processes an image file and saves the processed image to the specified
    folder.
    
Processes an image file and saves the processed image to the specified
folder.
Processes an image file and saves the processed image to the specified folder .
def process(filename, folder, threshold=19):
    image = cv2.imread(filename)
    image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    T = threshold_local(image, threshold, offset=10, method='gaussian')
    image = (image > T).astype('uint8') * 255
    gaussian = cv2.GaussianBlur(image, (9, 9), 0.0)
    image = cv2.addWeighted(image, 1.5, gaussian, -0.5, 0, image)
    image = cv2.GaussianBlur(image, (3, 3), 10.0)
    height = 2500
    scale_factor = height / image.shape[0]
    width = int(scale_factor * image.shape[1])
    image = cv2.resize(image, (width, height), interpolation=cv2.INTER_AREA)
    cv2.imwrite(f'{folder}/{filename}', image)
def process ( filename , folder , threshold = 19 ) : image = cv2 . imread ( filename ) image = cv2 . cvtColor ( image , cv2 . COLOR_BGR2GRAY ) T = threshold_local ( image , threshold , offset = 10 , method = 'gaussian' ) image = ( image > T ) . astype ( 'uint8' ) * 255 gaussian = cv2 . GaussianBlur ( image , ( 9 , 9 ) , 0.0 ) image = cv2 . addWeighted ( image , 1.5 , gaussian , - 0.5 , 0 , image ) image = cv2 . GaussianBlur ( image , ( 3 , 3 ) , 10.0 ) height = 2500 scale_factor = height / image . shape [ 0 ] width = int ( scale_factor * image . shape [ 1 ] ) image = cv2 . resize ( image , ( width , height ) , interpolation = cv2 . INTER_AREA ) cv2 . imwrite ( f'{folder}/{filename}' , image )
Processes an image file and saves the processed image to the specified
folder.
Processes an image file and saves the processed image to the specified folder .
"""
    Processes an image file and saves the processed image to the specified
    folder.
    """ # Convert to grayscale # Threshold it # Slightly blur it # Sharpen it # # And blur it again # Resize it to 2500px high
filename
folder
threshold