Skip to content

Bicubic resize of an uint16 image #4402

@clkotnik

Description

@clkotnik

What did you do?

I moved an existing Python app from a machine with Pillow 6.2.1 to a new machine which had Pillow 7.0.0 installed. The app failed to resize a PIL.Image.

What did you expect to happen?

I expected it to work as before

What actually happened?

resize threw an exception ValueError: image has wrong mode

What are your OS, Python and Pillow versions?

  • OS: ubuntu 18.04
  • Python: 3.6.9
  • Pillow: 7.0.0
import numpy as np
from PIL import Image

imgdata = np.array( [[484, 451, 481, 465, 488, 442],
 [823, 897, 971, 920, 855, 908],
 [758, 919, 854, 920, 850, 854],
 [840, 873, 950, 893, 872, 881],
 [937, 940, 835, 879, 895, 774],
 [841, 914, 867, 886, 922, 952]]).astype(np.uint16)

pimg = Image.fromarray(imgdata)
scale_factor = 0.5
size = tuple((np.array(pimg.size) * scale_factor).astype(int))
newim = pimg.resize(size)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-1-5c0c4827f11b> in <module>
     12 scale_factor = 0.5
     13 size = tuple((np.array(pimg.size) * scale_factor).astype(int))
---> 14 newim = pimg.resize(size)

e:\program files\python37\lib\site-packages\PIL\Image.py in resize(self, size, resample, box, reducing_gap)
   1871                 )
   1872 
-> 1873         return self._new(self.im.resize(size, resample, box))
   1874 
   1875     def reduce(self, factor, box=None):

ValueError: image has wrong mode

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions