INNER CODE UNIT · Python

center_crop_image

FoundationVision/Liquid · data_process/convert_imagepair_cc512.py:22

def center_crop_image(ori_image, tgt_width=512, tgt_height=512):
    Width,Height = ori_image.size
    factor = min(Width,Height)/min(tgt_width,tgt_height)
    input_image = ori_image.resize((int(Width/factor),int(Height/factor)), PIL.Image.LANCZOS)
    resize_width, resize_height = input_image.size   # Get dimensions

    left = (resize_width - tgt_width)//2
    top = (resize_height - tgt_height)//2
    right = (resize_width + tgt_width)//2
    bottom = (resize_height + tgt_height)//2
    # Crop the center of the image
    input_image = input_image.crop((left, top, right, bottom))
    return input_image

def process_item(data,image_tokenizer):
    image_path = data['image_path']
    try:
        ori_image = Image.open(image_path).convert("RGB")

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…