-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #293 from sparshmanni/main
Merged I/image-processing
- Loading branch information
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from PIL import Image, ImageFilter, ImageEnhance | ||
|
||
# Open an image | ||
image_path = "image.jpg" | ||
image = Image.open(image_path) | ||
|
||
# Define a menu to choose the operation | ||
print("Image Processing Options:") | ||
print("1. Gaussian Blur") | ||
print("2. Brightness Adjustment") | ||
print("3. Contrast Adjustment") | ||
print("4. Rotate") | ||
choice = input("Enter the option (1/2/3/4): ") | ||
|
||
if choice == "1": | ||
# Apply Gaussian Blur filter | ||
blurred_image = image.filter(ImageFilter.GaussianBlur(radius=5)) | ||
output_image_path = "blurred_image.jpg" | ||
blurred_image.save(output_image_path) | ||
print("Gaussian Blur applied. Modified image saved as 'blurred_image.jpg'.") | ||
|
||
elif choice == "2": | ||
# Adjust brightness | ||
brightness_factor = float(input("Enter brightness factor (0.0 to 2.0): ")) | ||
enhancer = ImageEnhance.Brightness(image) | ||
adjusted_image = enhancer.enhance(brightness_factor) | ||
output_image_path = "brightness_adjusted_image.jpg" | ||
adjusted_image.save(output_image_path) | ||
print("Brightness adjusted. Modified image saved as 'brightness_adjusted_image.jpg'.") | ||
|
||
elif choice == "3": | ||
# Adjust contrast | ||
contrast_factor = float(input("Enter contrast factor (0.0 to 2.0): ")) | ||
enhancer = ImageEnhance.Contrast(image) | ||
adjusted_image = enhancer.enhance(contrast_factor) | ||
output_image_path = "contrast_adjusted_image.jpg" | ||
adjusted_image.save(output_image_path) | ||
print("Contrast adjusted. Modified image saved as 'contrast_adjusted_image.jpg'.") | ||
|
||
elif choice == "4": | ||
# Rotate the image | ||
angle = float(input("Enter rotation angle (in degrees): ")) | ||
rotated_image = image.rotate(angle) | ||
output_image_path = "rotated_image.jpg" | ||
rotated_image.save(output_image_path) | ||
print(f"Image rotated by {angle} degrees. Modified image saved as 'rotated_image.jpg'.") | ||
|
||
else: | ||
print("Invalid choice. Please select a valid option (1/2/3/4).") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Python Image Processing Program | ||
|
||
This is a Python program for image processing using the Pillow (PIL) library. It allows you to open an image, apply various operations like Gaussian Blur, Brightness Adjustment, Contrast Adjustment, and Rotation, and save the modified image. | ||
|
||
## Prerequisites | ||
|
||
Before running the program, ensure you have the following installed: | ||
- Python | ||
- Pillow (PIL) library | ||
|
||
You can install Pillow using pip: | ||
|
||
```bash | ||
pip install pillow |