From 7e1a68f6e1b18ef7a85e9d86ed94e195f1896cec Mon Sep 17 00:00:00 2001 From: Divyendu Dutta Date: Wed, 27 Aug 2025 09:04:30 +0200 Subject: [PATCH 1/2] [FEAT] Implement data augmentation script for method exploration Developed a script to experiment with different data augmentation techniques. Currently testing Albumentations library --- .../scripts/data_augmentation_explore.py | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 nanodefectnet/scripts/data_augmentation_explore.py diff --git a/nanodefectnet/scripts/data_augmentation_explore.py b/nanodefectnet/scripts/data_augmentation_explore.py new file mode 100644 index 0000000..0b4b654 --- /dev/null +++ b/nanodefectnet/scripts/data_augmentation_explore.py @@ -0,0 +1,42 @@ +import os +import cv2 +import albumentations as A + +from nanodefectnet.utils.dir_utils import clean_create_dir + +from nanodefectnet.utils.logger import LoggerConfig + +LOGGER = LoggerConfig().logger + +IMAGE_NAME = "center_defect.png" +IMAGE_PATH = os.path.join(os.getcwd(), "assets", "test_images", IMAGE_NAME) +AUG_PATH = os.path.join(os.getcwd(), "assets", "test_images", "augmented_images") + +NUM_AUG_IMAGES = 10 + +# List of Albumentation data augmentations - https://explore.albumentations.ai/ +transform = A.Compose( + [ + A.Flip(p=0.5), + A.Rotate(p=0.5), + A.ShiftScaleRotate(shift_limit=0.0625, rotate_limit=45, p=0.5), + A.Transpose(p=0.5), + ] +) + +image = cv2.imread(IMAGE_PATH) +image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) +name_file_no_ext = IMAGE_NAME.split(".")[0] +file_ext = IMAGE_NAME.split(".")[-1] + +clean_create_dir(AUG_PATH) + +LOGGER.info(f"Augmented images will be saved to: {AUG_PATH}") +LOGGER.info(f"Generating {NUM_AUG_IMAGES} augmented images from: {IMAGE_PATH}") + +for i in range(NUM_AUG_IMAGES): + augmented_image = transform(image=image)["image"] + augmented_image = cv2.cvtColor(augmented_image, cv2.COLOR_RGB2BGR) + cv2.imwrite( + os.path.join(AUG_PATH, f"{name_file_no_ext}_{i+1}.{file_ext}"), augmented_image + ) From f1778ddc7f56ee804dc68d06f0fd41c694ed5de8 Mon Sep 17 00:00:00 2001 From: Divyendu Dutta Date: Wed, 27 Aug 2025 09:04:50 +0200 Subject: [PATCH 2/2] [CHORE] Add directory for augmented test images in .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 1fe3642..87fd9c2 100644 --- a/.gitignore +++ b/.gitignore @@ -206,3 +206,6 @@ cython_debug/ /checkpoints/ /lightning_logs/ *.ckpt + +# Assets +/assets/test_images/augmented_images/