-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
copy geo-location for neural network based filter results
- Loading branch information
1 parent
1e71e2b
commit 4d61758
Showing
2 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import os | ||
import argparse | ||
import piexif | ||
from PIL import Image | ||
from copy_geo_exiftool import process_single_image | ||
|
||
def main(raw_images_dir=None, mask_images_dir=None): | ||
# ... (argument parsing - same as before) ... | ||
|
||
for raw_image_name in os.listdir(raw_images_dir): | ||
raw_image_path = os.path.join(raw_images_dir, raw_image_name) | ||
# ... (construct mask_image_path - same as before) ... | ||
# Assuming mask images have a similar naming convention | ||
mask_image_name = raw_image_name.replace( | ||
"JPG", "png" | ||
) # Example transformation | ||
mask_image_path = os.path.join(mask_images_dir, mask_image_name) | ||
if os.path.exists(mask_image_path): | ||
process_single_image(raw_image_path, mask_image_path) | ||
else: | ||
print("Mask image not found. Skipping to the next image.") | ||
# raise FileNotFoundError("Mask image not found at specified path.") | ||
|
||
|
||
|
||
if __name__ == "__main__": | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument("raw_images_dir", help="Path to raw images directory") | ||
parser.add_argument("mask_images_dir", help="Path to mask images directory") | ||
args = parser.parse_args() | ||
main(args.raw_images_dir, args.mask_images_dir) | ||
|
||
# python copy_geolocation_nn.py '/home/roboticslab/Downloads/OneDrive_2024-02-03/NYCSpan8-9/raw/images' '/home/roboticslab/Downloads/OneDrive_2024-02-03/NYCSpan8-9/raw/images_out/2024-04-26_07-29-38/nn_solidfiltered_crack_overlay' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import os | ||
import argparse | ||
from PIL import Image | ||
from copy_geo_exiftool import process_single_image | ||
|
||
def main(raw_images_dir, mask_images_dir, converted_masks_dir): | ||
""" | ||
Converts PNG masks to JPEG, copies geolocation data, and places them in a new directory. | ||
Args: | ||
raw_images_dir: Path to the directory containing raw images. | ||
mask_images_dir: Path to the directory containing PNG mask images. | ||
converted_masks_dir: Path to the directory where converted JPEG masks will be stored. | ||
""" | ||
|
||
os.makedirs(converted_masks_dir, exist_ok=True) # Create the output directory if it doesn't exist | ||
|
||
for raw_image_name in os.listdir(raw_images_dir): | ||
if not raw_image_name.lower().endswith(".jpg"): | ||
print(raw_image_name.lower()) | ||
continue # Skip non-JPEG files | ||
|
||
# Construct paths for mask and converted mask images | ||
raw_image_path = os.path.join(raw_images_dir, raw_image_name) | ||
mask_image_name = raw_image_name.replace(".JPG", ".png") | ||
mask_image_path = os.path.join(mask_images_dir, mask_image_name) | ||
converted_mask_path = os.path.join(converted_masks_dir, mask_image_name.replace(".png", ".jpg")) | ||
|
||
if os.path.exists(mask_image_path): | ||
try: | ||
mask_image = Image.open(mask_image_path) | ||
if mask_image.format == "PNG": | ||
mask_image.convert("RGB").save(converted_mask_path) # Convert to JPEG and save | ||
process_single_image(raw_image_path, converted_mask_path) # Copy geolocation | ||
else: | ||
print(f"Mask {mask_image_name} is not PNG. Skipping.") | ||
except Exception as e: | ||
print(f"raw_image_path: {raw_image_path}") | ||
print(f"Error processing {mask_image_name}: {e}") | ||
else: | ||
print(f"Mask image {mask_image_name} not found. Skipping.") | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("raw_images_dir", help="Path to raw images directory") | ||
parser.add_argument("mask_images_dir", help="Path to mask images directory") | ||
parser.add_argument("converted_masks_dir", help="Path to converted masks directory") | ||
args = parser.parse_args() | ||
|
||
main(args.raw_images_dir, args.mask_images_dir, args.converted_masks_dir) | ||
|
||
# python copy_geolocation_nn_jpg.py '/home/roboticslab/Downloads/OneDrive_2024-02-03/NYCSpan8-9/raw/images' '/home/roboticslab/Downloads/OneDrive_2024-02-03/NYCSpan8-9/raw/images_out/2024-04-26_07-29-38/nn_solidfiltered_crack_overlay' '/home/roboticslab/Downloads/OneDrive_2024-02-03/NYCSpan8-9/raw/images_out/2024-04-26_07-29-38/nn_solidfiltered_crack_overlay_jpg' |