PhysAugNet 1.0.1
VQ-VQE powered augmentation for metal defect segmentation
Loading...
Searching...
No Matches
augment_thermal.py
Go to the documentation of this file.
1import argparse
2import os
3from physaug.augment.thermal import apply_thermal_augmentation
4from physaug.augment.grain import apply_grain_noise
5from physaug.utils.io import load_image_folder, save_image
6from tqdm import tqdm
7import numpy as np
8
9
11 parser = argparse.ArgumentParser(description="Apply thermal and grain noise augmentations")
12 parser.add_argument("--input_dir", type=str, required=True, help="Directory with input images")
13 parser.add_argument("--output_dir", type=str, required=True, help="Where to save augmented images")
14 parser.add_argument("--mode", type=str, choices=["rgb", "gray"], default="rgb", help="Image mode")
15 parser.add_argument("--apply_grain", action="store_true", help="Apply grain noise")
16 return parser.parse_args()
17
18
19def main():
20 args = parse_args()
21 os.makedirs(args.output_dir, exist_ok=True)
22 images, filenames = load_image_folder(args.input_dir, mode=args.mode)
23
24 for img, name in tqdm(zip(images, filenames), total=len(images)):
25 thermal = apply_thermal_augmentation(img)
26 if args.apply_grain:
27 thermal = apply_grain_noise(thermal)
28 save_path = os.path.join(args.output_dir, name)
29 save_image(thermal, save_path, mode=args.mode)
30
31
32if __name__ == "__main__":
33 main()
Definition main.py:1