Skip to content

Commit 63f7bb8

Browse files
authored
Merge pull request #662 from AllenInstitute/660/remove-imresize
remove imresize
2 parents 966dbf7 + 4b524ff commit 63f7bb8

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

allensdk/brain_observatory/stimulus_info.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import six
3737
import numpy as np
3838
import scipy.ndimage.interpolation as spndi
39-
from scipy.misc import imresize
39+
from PIL import Image
4040
from allensdk.api.cache import memoize
4141
import itertools
4242

@@ -495,10 +495,13 @@ def lsn_image_to_screen(self, img, stimulus_type, origin='lower', background_col
495495

496496
# assert img.dtype == np.uint8
497497

498-
pixels_per_patch = LOCALLY_SPARSE_NOISE_PIXELS[stimulus_type]
499498

500499
full_image = np.full((self.n_pixels_r, self.n_pixels_c), background_color, dtype=np.uint8)
501-
img_full_res = imresize(img, float(pixels_per_patch), interp='nearest')
500+
501+
pixels_per_patch = float(LOCALLY_SPARSE_NOISE_PIXELS[stimulus_type])
502+
target_size = tuple( int(pixels_per_patch * dimsize) for dimsize in img.shape[::-1] )
503+
img_full_res = np.array(Image.fromarray(img).resize(target_size, 0)) # 0 -> nearest neighbor interpolator
504+
502505
mr, mc = lsn_coordinate_to_monitor_coordinate((0, 0), (self.n_pixels_r, self.n_pixels_c), stimulus_type)
503506
Mr, Mc = lsn_coordinate_to_monitor_coordinate(img.shape, (self.n_pixels_r, self.n_pixels_c), stimulus_type)
504507
full_image[int(mr):int(Mr), int(mc):int(Mc)] = img_full_res
@@ -536,7 +539,7 @@ def natural_scene_image_to_screen(self, img, origin='lower', translation=(0,0)):
536539

537540
def natural_movie_image_to_screen(self, img, origin='lower', translation=(0,0)):
538541

539-
img = imresize(img, NATURAL_MOVIE_PIXELS)
542+
img = np.array(Image.fromarray(img).resize(NATURAL_MOVIE_PIXELS[::-1], 2)).astype(np.uint8) # 2 -> bilinear interpolator
540543

541544
assert img.dtype == np.uint8
542545

allensdk/core/reference_space.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import os
4141
import csv
4242

43-
from scipy.misc import imresize
4443
from scipy.ndimage.interpolation import zoom
4544
import numpy as np
4645
import nrrd

0 commit comments

Comments
 (0)