question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sp.ndimage.zoom / tf.image.resize_images alternative

See original GitHub issue

It would be nice to have a batched image resize (interpolation) operation implemented in JAX, afaik these are scipy.ndimage.zoom in scipy or tensorflow.image.resize_images in Tensorflow.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
hawkinspcommented, Jun 20, 2019

I spent a bit of time looking at this. My guess is that perhaps skimage.transform.resize (or rescale) is a good choice? It looks to me like scipy.ndimage.zoom suffers from some of the same pixel-centering bugs that TF’s resize bilinear used to suffer from (https://hackernoon.com/how-tensorflows-tf-image-resize-stole-60-days-of-my-life-aba5eb093f35)

3reactions
mattjjcommented, Jun 18, 2019

Good idea! Is scipy.ndimage.zoom the API you want?

In the meantime here’s a pure-NumPy snippet you can use:

def interpolate_bilinear(im, rows, cols):
  # based on http://stackoverflow.com/a/12729229
  col_lo = np.floor(cols).astype(int)
  col_hi = col_lo + 1
  row_lo = np.floor(rows).astype(int)
  row_hi = row_lo + 1

  nrows, ncols = im.shape[-3:-1]
  def cclip(cols): return np.clip(cols, 0, ncols - 1)
  def rclip(rows): return np.clip(rows, 0, nrows - 1)
  Ia = im[..., rclip(row_lo), cclip(col_lo), :]
  Ib = im[..., rclip(row_hi), cclip(col_lo), :]
  Ic = im[..., rclip(row_lo), cclip(col_hi), :]
  Id = im[..., rclip(row_hi), cclip(col_hi), :]

  wa = np.expand_dims((col_hi - cols) * (row_hi - rows), -1)
  wb = np.expand_dims((col_hi - cols) * (rows - row_lo), -1)
  wc = np.expand_dims((cols - col_lo) * (row_hi - rows), -1)
  wd = np.expand_dims((cols - col_lo) * (rows - row_lo), -1)

  return wa*Ia + wb*Ib + wc*Ic + wd*Id
Read more comments on GitHub >

github_iconTop Results From Across the Web

scipy.ndimage.zoom — SciPy v1.9.3 Manual
The array is zoomed using spline interpolation of the requested order. Parameters. inputarray_like. The input array. zoomfloat or sequence. The zoom factor ...
Read more >
MRI mask 3D array resize with scipy.ndimage.zoom, the ...
This issue was asked in another post A weird image modification after applying scipy.ndimage.zoom function to a mri segmentation image and ...
Read more >
When to use those similar layers in Keras?
Resizing ZeroPadding2D UpSampling2D sp.ndimage.zoom Conv2DTranspose Cropping2D. Group 2. Reshape RepeatVector.
Read more >
Python Scipy Ndimage Zoom With Examples
In the above code, we have provided the image to a method zoom() with zoom factor equal to 1.5. View the zoomed image...
Read more >
cupyx.scipy.ndimage.zoom — CuPy 11.4.0 documentation
cupyx.scipy.ndimage.zoom(input, zoom, output=None, order=3, mode='constant', ... The array is zoomed using spline interpolation of the requested order.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found