In pillow library, BICUBIC is not working

1.4k Views Asked by At

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?

1

There are 1 best solutions below

5
zython On

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