File size: 306 Bytes
65d1089
 
 
 
 
 
6724345
65d1089
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
import numpy as np
import cv2
from PIL import Image

IMAGE_SIZE = 128

def preprocess_for_cnn(image: Image.Image):
    img = np.array(image.convert("L"))
    img = cv2.resize(img, (IMAGE_SIZE, IMAGE_SIZE))
    img = img.astype(np.float32) / 255.0
    img = np.expand_dims(img, axis=(0, -1))
    return img