diff --git a/README.md b/README.md index dcc3d96..3c2e181 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Feature Extraction: Extracts various features such as brightness, contrast, hue, Style Transfer: Applies the style of the reference image to the target image using histogram matching. -Image Enhancement: Enhances the processed image by adjusting brightness, contrast, and color. +Image Enhancement: Enhances the processed image by adjusting brightness, contrast, and color. Additional utilities allow for highlight/shadow adjustments and vignette effects. Visualization: Plots the reference image, original target image, and processed target image along with their respective features. ![result4](https://github.com/user-attachments/assets/0e020632-f4d6-4abf-9d1e-d9addab57eed) ![reslut2](https://github.com/user-attachments/assets/e81435cd-294b-44d4-8ab2-9b29b329081b) @@ -25,6 +25,8 @@ The Image Style Transfer project extracts features from a reference image and ap - **Feature Extraction**: Extracts various features such as brightness, contrast, hue, saturation, vibrance, color moments, and color coherence vector (CCV) from the images. - **Style Transfer**: Applies the style of the reference image to the target image using histogram matching. - **Image Enhancement**: Enhances the processed image by adjusting brightness, contrast, and color. +- **Highlight and Shadow Control**: Fine-tunes shadows and highlights for better exposure. +- **Vignette Effect**: Adds an optional vignette for creative styling. - **Visualization**: Plots the reference image, original target image, and processed target image along with their respective features. ## Requirements diff --git a/Script b/Script index 0c96a6e..b2cc373 100644 --- a/Script +++ b/Script @@ -169,6 +169,26 @@ class ImageStyleTransfer: image_enhanced = enhancer.enhance(color) return np.array(image_enhanced) + def adjust_highlights_shadows(self, image, shadow_factor=1.0, highlight_factor=1.0): + """Adjust shadows and highlights similar to photo editors.""" + hsv = cv2.cvtColor(image, cv2.COLOR_RGB2HSV).astype(np.float32) + v = hsv[:, :, 2] / 255.0 + shadows = v < 0.5 + v[shadows] = np.clip(v[shadows] * shadow_factor, 0, 1) + v[~shadows] = np.clip(v[~shadows] * highlight_factor, 0, 1) + hsv[:, :, 2] = v * 255 + return cv2.cvtColor(hsv.astype(np.uint8), cv2.COLOR_HSV2RGB) + + def add_vignette(self, image, strength=0.5): + """Apply a vignette effect to the image.""" + rows, cols = image.shape[:2] + kernel_x = cv2.getGaussianKernel(cols, int(cols * strength)) + kernel_y = cv2.getGaussianKernel(rows, int(rows * strength)) + kernel = kernel_y @ kernel_x.T + mask = kernel / kernel.max() + vignette = image * mask[:, :, np.newaxis] + return vignette.astype(np.uint8) + def plot_results(self, reference_image, reference_features, original_image, original_features, processed_image, processed_features, title): """