|
36 | 36 | import six |
37 | 37 | import numpy as np |
38 | 38 | import scipy.ndimage.interpolation as spndi |
39 | | -from scipy.misc import imresize |
| 39 | +from PIL import Image |
40 | 40 | from allensdk.api.cache import memoize |
41 | 41 | import itertools |
42 | 42 |
|
@@ -495,10 +495,13 @@ def lsn_image_to_screen(self, img, stimulus_type, origin='lower', background_col |
495 | 495 |
|
496 | 496 | # assert img.dtype == np.uint8 |
497 | 497 |
|
498 | | - pixels_per_patch = LOCALLY_SPARSE_NOISE_PIXELS[stimulus_type] |
499 | 498 |
|
500 | 499 | 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 | + |
502 | 505 | mr, mc = lsn_coordinate_to_monitor_coordinate((0, 0), (self.n_pixels_r, self.n_pixels_c), stimulus_type) |
503 | 506 | Mr, Mc = lsn_coordinate_to_monitor_coordinate(img.shape, (self.n_pixels_r, self.n_pixels_c), stimulus_type) |
504 | 507 | 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)): |
536 | 539 |
|
537 | 540 | def natural_movie_image_to_screen(self, img, origin='lower', translation=(0,0)): |
538 | 541 |
|
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 |
540 | 543 |
|
541 | 544 | assert img.dtype == np.uint8 |
542 | 545 |
|
|
0 commit comments