INNER CODE UNIT · Python
process_directory
changyeyu/LLM-RL-Visualized · src/clip_images.py:30
def process_directory(input_dir, tmp_dir, padding=10):
"""
Recursively traverses the input_dir, processes all PNG images,
and saves the processed images to the tmp_dir preserving the relative path.
"""
for root, dirs, files in os.walk(input_dir):
for file in files:
if file.lower().endswith(".png"):
input_path = os.path.join(root, file)
# Compute the relative path from the input directory
rel_path = os.path.relpath(input_path, input_dir)
output_tmp = os.path.join(tmp_dir, rel_path)
# Ensure the target directory exists
os.makedirs(os.path.dirname(output_tmp), exist_ok=True)
print(f"Processing {input_path} -> {output_tmp}")
trim_whitespace(input_path, output_tmp, padding)