INNER CODE UNIT · Python

right

changyeyu/LLM-RL-Visualized · src/clip_images.py:22

        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)
                # Compute the relative path from the input directory

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…