66from PIL import Image
77import numpy as np
88
9+ # Set Base Directories
10+ BASE_DIR = "2018-NEON-beetles"
11+ ORIGINAL_GROUP_IMAGES_DIR = os .path .join (BASE_DIR , "group_images" )
12+ PROCESS_DIR = os .path .join (BASE_DIR , "processed_images" )
13+
914def calculate_uniform_scaling_factors ():
1015 """
1116 Calculate uniform scaling factors between original group images and BeetlePalooza resized images.
1217 Returns a dictionary mapping picture_id -> uniform_scale_factor
1318 """
14- # Paths
15- original_group_images_dir = "/fs/ess/PAS2136/Hawaii-2025/beetles_intake/2018-NEON-beetles/group_images"
16- resized_group_images_dir = "/fs/ess/PAS2136/paloozas/BeetlePalooza-2024/Resized Images [Corrected from ISA]"
17-
1819 scaling_factors = {}
1920
2021 print ("Step 1: Calculating uniform scaling factors between original and resized group images..." )
2122
2223 # Get list of resized images
23- if not os .path .exists (resized_group_images_dir ):
24- print (f"Error: Directory { resized_group_images_dir } does not exist" )
24+ if not os .path .exists (PROCESS_DIR ):
25+ print (f"Error: Directory { PROCESS_DIR } does not exist" )
2526 return {}
2627
27- resized_files = [f for f in os .listdir (resized_group_images_dir ) if f .lower ().endswith (('.jpg' , '.jpeg' , '.png' ))]
28+ resized_files = [f for f in os .listdir (PROCESS_DIR ) if f .lower ().endswith (('.jpg' , '.jpeg' , '.png' ))]
2829 print (f"Found { len (resized_files )} resized images" )
2930
3031 processed = 0
@@ -35,7 +36,7 @@ def calculate_uniform_scaling_factors():
3536 # Find corresponding original image
3637 original_path = None
3738 for ext in ['.jpg' , '.jpeg' , '.png' , '.JPG' , '.JPEG' , '.PNG' ]:
38- potential_path = os .path .join (original_group_images_dir , picture_id + ext )
39+ potential_path = os .path .join (ORIGINAL_GROUP_IMAGES_DIR , picture_id + ext )
3940 if os .path .exists (potential_path ):
4041 original_path = potential_path
4142 break
@@ -45,8 +46,8 @@ def calculate_uniform_scaling_factors():
4546 continue
4647
4748 # Load both images and get dimensions
48- resized_path = os .path .join (resized_group_images_dir , resized_filename )
49-
49+ resized_path = os .path .join (PROCESS_DIR , resized_filename )
50+
5051 try :
5152 with Image .open (original_path ) as orig_img :
5253 orig_width , orig_height = orig_img .size
@@ -82,7 +83,7 @@ def calculate_uniform_scaling_factors():
8283 print (f" Std: { np .std (scale_values ):.3f} " )
8384
8485 # Save scaling factors to JSON file for reference
85- output_json = "/fs/ess/PAS2136/Hawaii-2025/beetles_intake/beetlepalooza_processing_scripts/ uniform_scaling_factors.json"
86+ output_json = os . path . join ( PROCESS_DIR , " uniform_scaling_factors.json")
8687 with open (output_json , 'w' ) as f :
8788 json .dump (scaling_factors , f , indent = 2 , sort_keys = True )
8889 print (f"Uniform scaling factors saved to: { output_json } " )
@@ -130,10 +131,9 @@ def resize_individual_images_uniform():
130131 print ("\n Step 2: Resizing individual specimen images using uniform scaling..." )
131132
132133 # Paths
133- csv_file = "/fs/ess/PAS2136/Hawaii-2025/beetles_intake/2018-NEON-beetles/individual_specimens.csv"
134- individual_images_base = "/fs/ess/PAS2136/Hawaii-2025/beetles_intake/2018-NEON-beetles"
135- output_dir = "/fs/ess/PAS2136/Hawaii-2025/beetles_intake/beetlepalooza_processing_scripts/individual_images_resized_uniform"
136-
134+ csv_file = os .path .join (BASE_DIR , "individual_specimens.csv" )
135+ output_dir = os .path .join (PROCESS_DIR , "individual_images_resized_uniform" )
136+
137137 # Create output directory
138138 os .makedirs (output_dir , exist_ok = True )
139139
@@ -163,7 +163,7 @@ def resize_individual_images_uniform():
163163 continue
164164
165165 # Full path to individual image
166- individual_path_full = os .path .join (individual_images_base , individual_path_rel )
166+ individual_path_full = os .path .join (BASE_DIR , individual_path_rel )
167167
168168 if not os .path .exists (individual_path_full ):
169169 skipped += 1
0 commit comments