INNER CODE UNIT · Python
upper
changyeyu/LLM-RL-Visualized · src/clip_images.py:21
upper = max(bbox[1] - padding, 0)
right = min(bbox[2] + padding, width)
lower = min(bbox[3] + padding // 2, height) # Adjust lower padding to avoid covering text
cropped_im = im.crop((left, upper, right, lower))
cropped_im.save(output_path)
else:
im.save(output_path)
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)