|
import cv2 |
|
import numpy as np |
|
from PIL import Image, ImageEnhance |
|
|
|
|
|
|
|
def preprocess_image001(image): |
|
|
|
image = np.array(image) |
|
|
|
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) |
|
|
|
enhancer = ImageEnhance.Contrast(Image.fromarray(gray)) |
|
enhanced_image = enhancer.enhance(2) |
|
|
|
_, binary = cv2.threshold(np.array(enhanced_image), 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU) |
|
|
|
denoised = cv2.fastNlMeansDenoising(binary, None, 30, 7, 21) |
|
return Image.fromarray(denoised) |
|
|
|
|
|
def preprocess_image002(image): |
|
|
|
image_np = np.array(image) |
|
|
|
gray = cv2.cvtColor(image_np, cv2.COLOR_BGR2GRAY) |
|
gray = cv2.bilateralFilter(gray, 11, 17, 17) |
|
edged = cv2.Canny(gray, 30, 200) |
|
return Image.fromarray(edged) |
|
|