Spaces:
Sleeping
Sleeping
dev-deg
Added additional pre-processing step during inferencing and restricted model choice to ver 1.1.
7c48c3c | import cv2 | |
| import numpy as np | |
| from PIL import Image | |
| def preprocess_input(input_image): | |
| return correct_color(input_image) | |
| def correct_color(input_image): | |
| # Convert PIL Image to NumPy array (OpenCV format) | |
| open_cv_image = np.array(input_image) | |
| open_cv_image = open_cv_image[:, :, ::-1].copy() # Convert RGB to BGR | |
| # Apply color correction in LAB color space | |
| lab_image = cv2.cvtColor(open_cv_image, cv2.COLOR_BGR2LAB) | |
| l_channel, a_channel, b_channel = cv2.split(lab_image) | |
| l_channel = cv2.equalizeHist(l_channel) | |
| lab_image = cv2.merge([l_channel, a_channel, b_channel]) | |
| corrected_image = cv2.cvtColor(lab_image, cv2.COLOR_LAB2BGR) | |
| # Convert corrected image from BGR to RGB | |
| corrected_image_rgb = cv2.cvtColor(corrected_image, cv2.COLOR_BGR2RGB) | |
| # Convert back to PIL Image | |
| pil_image = Image.fromarray(corrected_image_rgb) | |
| return pil_image |