Skip to content

Commit

Permalink
Merge pull request #88 from scikit-beam/imagedisplay-scipyresize
Browse files Browse the repository at this point in the history
replace scipy resize with PIL resize in imagedisplay.py
  • Loading branch information
yxqd authored Aug 21, 2022
2 parents a062c90 + 88e01d2 commit 5284343
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
12 changes: 8 additions & 4 deletions ipywe/imagedisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,10 @@ def createImg(self):
view_size = np.max((self.width, self.height))
if size > view_size:
downsample_ratio = 1.*view_size/size
import scipy.misc
img = scipy.misc.imresize(img, downsample_ratio)
img = resize(img, downsample_ratio)
else:
upsample_ratio = 1.*view_size/size
import scipy.misc
img = scipy.misc.imresize(img, upsample_ratio)
img = resize(img, upsample_ratio)
"""Chooses the correct string IO method based on
which version of Python is being used.
Once Python 2.7 support ends, this can be replaced
Expand Down Expand Up @@ -159,3 +157,9 @@ def resetImg(self, change):
self.curr_img_data = self.arr.copy()
self._b64value = self.createImg()
return

def resize(img, ratio):
from PIL import Image
nrows, ncols = img.shape
shape1 = nrows1, ncols1 = int(ratio*nrows), int(ratio*ncols)
return np.array(Image.fromarray(img).resize(shape1))
8 changes: 4 additions & 4 deletions ipywe/imgdatagraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,10 @@ def getimg_bytes(self):
view_size = np.max((self.width, self.height))
if size > view_size:
downsample_ratio = view_size/size
import scipy.misc
img = scipy.misc.imresize(img, downsample_ratio)
img = resize(img, downsample_ratio)
else:
upsample_ratio = view_size/size
import scipy.misc
img = scipy.misc.imresize(img, upsample_ratio)
img = resize(img, upsample_ratio)
if sys.version_info < (3, 0):
from cStringIO import StringIO
f = StringIO()
Expand Down Expand Up @@ -410,3 +408,5 @@ def get_data_diagonal(self, x_init, y_init, x_fin, y_fin):
vals.append(i/n)
bins = bin_borders
return bins, vals, bin_step

from .imagedisplay import resize

0 comments on commit 5284343

Please sign in to comment.