主要想問執行後出現module 'PIL.Image' has no attribute 'ANTIALIAS'的原因及該如何處理。(疑問及程式碼如附圖
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))