diff --git a/src/spectralforensics/dataset.py b/src/spectralforensics/dataset.py index 895247b..5b4c296 100644 --- a/src/spectralforensics/dataset.py +++ b/src/spectralforensics/dataset.py @@ -1,13 +1,10 @@ from pathlib import Path from uuid import uuid4 - import pandas as pd from .features import extract_features as extract_image_features from tqdm import tqdm support_ext = {".jpg", ".jpeg", ".png", ".bmp", ".tif", ".tiff", ".webp"} - - def _rename_images(folder_path, prefix): folder = Path(folder_path) if not folder.exists(): @@ -15,42 +12,27 @@ def _rename_images(folder_path, prefix): if not folder.is_dir(): raise NotADirectoryError(f"Expected a folder: {folder}") - images = sorted( - ( - file - for file in folder.iterdir() - if file.is_file() and file.suffix.lower() in support_ext - ), - key=lambda file: file.name.lower(), - ) - - # Stage every file first so existing names such as real1.jpg cannot collide. + images = sorted((file for file in folder.iterdir()if file.is_file() and file.suffix.lower() in support_ext), + key=lambda file: file.name.lower(),) staged_images = [] for image in images: temporary_path = folder / f".spectralforensics-{uuid4().hex}{image.suffix}" image.rename(temporary_path) staged_images.append((temporary_path, image.suffix.lower())) - renamed_images = [] for index, (temporary_path, suffix) in enumerate(staged_images, start=1): new_path = folder / f"{prefix}{index}{suffix}" temporary_path.rename(new_path) renamed_images.append(new_path) - print(f"{len(renamed_images)} images renamed with the '{prefix}' prefix.") return renamed_images - def rename_real_images(folder_path): - """Rename supported images sequentially as real1, real2, and so on.""" return _rename_images(folder_path, "real") - def rename_generated_images(folder_path): - """Rename supported images sequentially as gen1, gen2, and so on.""" return _rename_images(folder_path, "gen") - def extract_features(path, output_csv=None, image_size=(255, 255), high_freq_threshold=0.65, output="all", show_progress=True): path = Path(path) if not path.exists():