import numpy as np from PIL import Image def load_and_preprocess_image(image_path, target_size=(224, 224)): """ Loads an image from disk, converts to RGB, resizes, and normalizes it. Returns: img (PIL.Image): Original unresized PIL image. img_resized (PIL.Image): Resized PIL image (224x224). img_normalized (np.ndarray): Normalized image array scaled to float range [0.0, 1.0]. """ # 1. Format Conversion & Load img = Image.open(image_path).convert("RGB") # 2. Resize img_resized = img.resize(target_size) # 3. Normalization (Scaling to [0, 1]) img_normalized = np.array(img_resized, dtype=np.float32) / 255.0 return img, img_resized, img_normalized