How to resize a 'image' with negative numbers using scipy.misc.resize?

Viewed 182

I want to resize a surface normal 'image' (H*W*3). The problem is that there are negetive numbers in the array. How can I use the scipy.misc.resize or cv2.resize to resize this?

1 Answers

cv2.resize supports negative numbers.

Example:

import numpy as np
import cv2

a = np.full((5, 5, 3), -5, float))
b = cv2.resize(a, (10, 10))
print(b)

Result:

[[[-5. -5. -5.]  
  [-5. -5. -5.]  
  [-5. -5. -5.]...

It could be that you are having a problem using cv2.resize because the type of your image is int32.
cv2.resize does not support int32 type.

The following code raises an exception:

a = np.full((5, 5, 3), -5, np.int32)
b = cv2.resize(a, (10, 10))

You may convert the image to type np.int16 before resizing:

a = np.full((5, 5, 3), -5, np.int32)
b = cv2.resize(a.astype(np.int16), (10, 10))

There is no scipy.misc.resize, there is scipy.misc.imresize, but method is deprecated:

imresize is deprecated! imresize is deprecated in SciPy 1.0.0, and will be removed in 1.3.0. Use Pillow instead

It looks like there is some control over the range, using mode argument.

Related