Skip to content

Commit

Permalink
Added: Photos of arts from different genres of styling
Browse files Browse the repository at this point in the history
  • Loading branch information
Klus3kk committed Dec 18, 2024
1 parent cf0b1eb commit 389ec91
Show file tree
Hide file tree
Showing 44 changed files with 85 additions and 21 deletions.
51 changes: 38 additions & 13 deletions core/ImageProcessor.py
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.
Binary file added images/style/abstract/Joan_Miro_Triptych_Bleu.jpg
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 images/style/abstract/Paul_Klee_Senecio.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.
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 images/style/cubism/Pablo_Picasso_Guernica.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.
55 changes: 47 additions & 8 deletions utilities/StyleRegistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,60 @@
class StyleRegistry:
def __init__(self):
self.styles = {
"impressionism": [
"images/style/impressionism/water_lilies.jpg",
"images/style/impressionism/ballet_rehearsal.jpg"
],
"abstract": [
"images/style/abstract/composition_viii.jpg",
"images/style/abstract/autumn_rhythm.jpg"
"images/style/abstract/Frankenthaler_Helen_Mountains_and_Sea.jpg",
"images/style/abstract/Jackson_Pollock_Autumn_Rhythm.jpg",
"images/style/abstract/Jackson_Pollock_Full-Fathom-Five.jpg",
"images/style/abstract/Joan_Miro_Triptych_Bleu.jpg",
"images/style/abstract/Paul_Klee_Senecio.jpg",
"images/style/abstract/Piet_Mondrian_Broadway_Boogie_Woogie.jpg",
"images/style/abstract/Theo_van_Doesburg_Peinture_Pure.jpg",
"images/style/abstract/Vassily_Kandinsky_Composition_VIII.jpg"
],
"baroque": [
"images/style/baroque/Annibale_Carracci_Lamentation_of_Christ.jpg",
"images/style/baroque/Caravaggio_Death_of_the_Virgin.jpg",
"images/style/baroque/Caravaggio_Judith_Beheading_Holofernes.jpg",
"images/style/baroque/Caravaggio_The_Calling_of_Saint_Matthew.jpg",
"images/style/baroque/Diego_Velázquez_Las_Meninas.jpg",
"images/style/baroque/Johannes_Vermeer_Girl_with_a_Pearl_Earring.jpg",
"images/style/baroque/Rembrandt_The_Anatomy_Lesson_of_Dr_Nicolaes_Tulp.jpg",
"images/style/baroque/Rembrandt_van_Rijn_The_Night_Watch.jpg"
],
"cubism": [
"images/style/cubism/les_demoiselles.jpg",
"images/style/cubism/violin_and_candlestick.jpg"
"images/style/cubism/Georges_Braque_Natura_morta_con clarinetto.jpg",
"images/style/cubism/Georges_Braque_Violin_and_Candlestick.jpg",
"images/style/cubism/Juan_Gris_Guitar_on_the_table.jpg",
"images/style/cubism/Juan_Gris_Portrait_of_Pablo_Picasso.jpg",
"images/style/cubism/Marc_Chagall_I_am_The_Village.jpg",
"images/style/cubism/Pablo_Picasso_Guernica.jpg",
"images/style/cubism/Pablo-Picasso-Panny-Z-Awinionu.jpg",
"images/style/cubism/Paul_Cézanne_Les_Grandes_Baigneuses.jpg"
],
"expressionism": [
"images/style/expressionism/David_Alfaro_Siqueiros_Birth_of_Fascism.jpg",
"images/style/expressionism/Edvard_Munch_The_Scream.jpg",
"images/style/expressionism/Emil_Nolde_Dance_Around_the_Golden Calf.jpg",
"images/style/expressionism/Ernst_Ludwig_Kirchner_Street_Berlin.jpg",
"images/style/expressionism/Marc_Franz_Blaues_Pferdchen_Saarlandmuseum.jpg",
"images/style/expressionism/Max_Beckmann_The_Night.jpg",
"images/style/expressionism/Pablo_Picasso_Stary_Gitarzysta.jpg",
"images/style/expressionism/Wassily_Kandinsky_The_Blue_Rider.jpg"
],
"impressionism": [
"images/style/impressionism/Auguste_Renoir_Dance_at_Le_Moulin_de_la_Galette.jpg",
"images/style/impressionism/Claude_Monet_Impression_Sunrise.jpg",
"images/style/impressionism/Claude_Monet_Lilies.jpg",
"images/style/impressionism/Claude_Monet_Woman_with_a_Parasol.jpg",
"images/style/impressionism/Edgar_Degas_The_Dance_Class.jpg",
"images/style/impressionism/Edouard_Manet_Woman_Reading.jpg",
"images/style/impressionism/Gustave_Caillebotte_LHomme_au_balcon_boulevard.jpg",
"images/style/impressionism/Gustave_Caillebotte_Paris_Street_Rainy_Day.jpg"
]
}

def get_random_style_image(self, category):
if category in self.styles:
return random.choice(self.styles[category])
raise ValueError(f"Style category '{category}' not found!")

0 comments on commit 389ec91

Please sign in to comment.