File size: 2,070 Bytes
4dccf1d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
import os
from PIL import Image
import pandas as pd
# Define the directories
original_directories = [
"../data/resized-original-images"
]
processed_directories = {
"Photoroom": "../data/processed/photoroom",
"Clipdrop": "../data/processed/clipdrop",
"RemoveBG": "../data/processed/removebg",
"BRIA RMBG 2.0": "../data/processed/bria"
}
def compute_megapixels(width, height):
return (width * height) / 1_000_000
def check_image_sizes_comparison():
data = []
for original_directory in original_directories:
for filename in os.listdir(original_directory):
if filename.endswith(('.png', '.jpg', '.jpeg')):
original_path = os.path.join(original_directory, filename)
with Image.open(original_path) as img:
original_size = f"{img.size[0]}x{img.size[1]}"
original_megapixels = compute_megapixels(img.size[0], img.size[1])
sizes = {
"original_file_name": filename,
"original_size": original_size,
"original_megapixels": original_megapixels
}
png_filename = os.path.splitext(filename)[0] + ".png"
for model, directory in processed_directories.items():
image_path = os.path.join(directory, png_filename)
if os.path.exists(image_path):
with Image.open(image_path) as img:
image_size = f"{img.size[0]}x{img.size[1]}"
image_megapixels = compute_megapixels(img.size[0], img.size[1])
else:
image_size = "Not found"
image_megapixels = "Not found"
sizes[model] = image_size
sizes[f"{model}_megapixels"] = image_megapixels
data.append(sizes)
df = pd.DataFrame(data)
df.to_csv("image_sizes_comparison.csv", index=False)
if __name__ == "__main__":
check_image_sizes_comparison() |