简体   繁体   中英

In pillow library, BICUBIC is not working

This is my code.

import sys, os
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
from scipy import *
sys.path.insert(0, 'C:/research')

im = Image.open('C:/research/1.jpg')
hei, wei = im.height, im.width

im_bicubic = im.resize((wei,hei), im.BICUBIC)

im.save('C:/research/1ori.jpg')            #original image
im_bicubic.save('C:/research/1bic.jpg')    #Images with bicubic applied

But I get this error.

AttributeError: 'JpegImageFile' object has no attribute 'BICUBIC'

Why is this message coming up?

.bmp , the same message pops up.

What should I do?

You need to use PIL.Image.BICUBIC instead of im.BICUBIC .

So you need to change:

im_bicubic = im.resize((wei,hei), im.BICUBIC)

to

im.resize((wei,hei),PIL.Image.BICUBIC)

You also need to import pil like so:

import PIL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM