-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added: Photos of arts from different genres of styling
- Loading branch information
Showing
44 changed files
with
85 additions
and
21 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,22 +1,47 @@ | ||
from PIL import Image | ||
from io import BytesIO | ||
from PIL import Image, ImageOps | ||
import os | ||
|
||
class ImageProcessor: | ||
@staticmethod | ||
def preprocess_image(image_path_or_data, size=512): | ||
def preprocess_image(image_path_or_data, size=(512, 512)): | ||
""" | ||
Preprocess an individual image by resizing while maintaining aspect ratio and padding to a square. | ||
:param image_path_or_data: Path to the image file or in-memory image data. | ||
:param size: Target size for the square output (default: 512x512). | ||
:return: Processed PIL Image object. | ||
""" | ||
if isinstance(image_path_or_data, (str, bytes)): | ||
image = Image.open(image_path_or_data).convert("RGB") | ||
elif isinstance(image_path_or_data, BytesIO): | ||
image = Image.open(image_path_or_data).convert("RGB") | ||
img = Image.open(image_path_or_data).convert("RGB") | ||
elif isinstance(image_path_or_data, Image.Image): | ||
img = image_path_or_data | ||
else: | ||
raise ValueError("Invalid input type for image") | ||
image = image.resize((size, size)) | ||
return image | ||
|
||
img.thumbnail(size, Image.ANTIALIAS) | ||
|
||
# Add padding to make the image square | ||
delta_width = size[0] - img.size[0] | ||
delta_height = size[1] - img.size[1] | ||
padding = (delta_width // 2, delta_height // 2, delta_width - delta_width // 2, delta_height - delta_height // 2) | ||
padded_img = ImageOps.expand(img, padding, fill=(0, 0, 0)) | ||
|
||
return padded_img | ||
|
||
|
||
@staticmethod | ||
def save_image(image, output_path): | ||
'''Save the processed image.''' | ||
image.save(output_path) | ||
def preprocess_images(input_dir, output_dir, size=(512, 512)): | ||
""" | ||
Batch preprocess images in a directory. | ||
:param input_dir: Directory containing raw images. | ||
:param output_dir: Directory to save preprocessed images. | ||
:param size: Target size for the square output (default: 512x512). | ||
""" | ||
os.makedirs(output_dir, exist_ok=True) | ||
for file_name in os.listdir(input_dir): | ||
if file_name.endswith(('.jpg', '.png')): | ||
img_path = os.path.join(input_dir, file_name) | ||
img = ImageProcessor.preprocess_image(img_path, size) | ||
|
||
|
||
# Save as JPEG | ||
output_path = os.path.join(output_dir, os.path.splitext(file_name)[0] + ".jpg") | ||
img.save(output_path, "JPEG") | ||
print(f"Processed: {output_path}") |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+128 KB
images/style/baroque/Rembrandt_The_Anatomy_Lesson_of_Dr_Nicolaes_Tulp.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+120 KB
images/style/expressionism/David_Alfaro_Siqueiros_Birth_of_Fascism.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Binary file added
BIN
+11.2 KB
images/style/expressionism/Emil_Nolde_Dance_Around_the_Golden Calf.jpg
Oops, something went wrong.
Oops, something went wrong.
Binary file added
BIN
+102 KB
images/style/expressionism/Marc_Franz_Blaues_Pferdchen_Saarlandmuseum.jpg
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Binary file added
BIN
+521 KB
images/style/impressionism/Auguste_Renoir_Dance_at_Le_Moulin_de_la_Galette.jpg
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Binary file added
BIN
+140 KB
images/style/impressionism/Gustave_Caillebotte_LHomme_au_balcon_boulevard.jpg
Oops, something went wrong.
Binary file added
BIN
+156 KB
images/style/impressionism/Gustave_Caillebotte_Paris_Street_Rainy_Day.jpg
Oops, something went wrong.
Binary file added
BIN
+682 KB
...tyle/post-impressionism/1364px-Van_Gogh_-_Starry_Night_-_Google_Art_Project.jpg
Oops, something went wrong.
Oops, something went wrong.
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