Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Summary
We currently use a relatively complicated image resampling algorithm because we want to preserve data values above vmin and vmax but theagg
resample routines only allow values between 0 and 1. Agg also does not preserve NaN, so we need to remask at the end. This makesimage._make_image
quite long and convoluted.
Proposed fix
Pillow allows 32-bit one-channel images, with no apparent restrictions on the values, and has aresize
method that seems to do resampling as we would like.
The only issue that I can see is that Pillow has fewerresampling kernels than we do
- nearest
- box
- bilinear
- bicubic
- hamming
- lanczos
Whereas we allow quite a few more currently (inherited fromagg
):
methods = [None, 'none', 'nearest', 'bilinear', 'bicubic', 'spline16', 'spline36', 'hanning', 'hamming', 'hermite', 'kaiser', 'quadric', 'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc', 'lanczos']
I frankly think very few people are using the more exotic filters, or need to. If we want to change to pillow we could
- keep the old resampling around for the other filters (perhaps deprecating them)
- add the other filters to Pillow
The patch for the giant resampling code is:
+ im = Image.fromarray(A)+ output = np.asarray(im.resize(out_shape, Image.BICUBIC))+ output = self.norm(output)+ out_alpha = np.ones_like(output)