iT邦幫忙

0

Python將輸入圖片像素轉成224*224的問題

  • 分享至 

  • xImage

主要想問執行後出現module 'PIL.Image' has no attribute 'ANTIALIAS'的原因及該如何處理。(疑問及程式碼如附圖https://ithelp.ithome.com.tw/upload/images/20230731/20161741a8qa13tjDj.png

from PIL import Image


def resize_image(input_image_path, output_image_path, target_size=(224, 224)):
    try:
        # 開啟輸入圖像
        with Image.open(input_image_path) as img:
            # 調整大小
            resized_img = img.resize(target_size, Image.ANTIALIAS)
            # 儲存調整後的圖像
            resized_img.save(output_image_path)
            print("圖像調整成功,已儲存至", output_image_path)
    except Exception as e:
        print("圖像調整失敗:", str(e))


if __name__ == "__main__":
    # 輸入的圖像路徑
    input_image_path = "C:/Users/ChaoHuaLee/Desktop/Bone_age_CNN/trainingdataset/1377.png"
    # 輸出的調整大小後圖像路徑
    output_image_path = "C:/Users/ChaoHuaLee/Desktop/resized_image.png"

    # resize_image函式,將輸入圖像調整為指定大小並儲存
    resize_image(input_image_path, output_image_path, target_size=(224, 224))
pickuse iT邦新手 3 級 ‧ 2023-07-31 11:52:31 檢舉
請「正確」的「附上完整程式碼」,不然根據你這張截圖很難理解
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

1

我要發表回答

立即登入回答