1

I downloaded a program and trying to run it. I am facing some issues due to deprecation of Scipy essentials.

Previous programs consists of code related to scipy. In brief the operations are as follows:

import scipy


scipy.misc.imread(filename)

scipy.misc.imresize(img, (299, 299, 3), interp='bilinear')

(Note that these lines are not in sequence as in program, I just wrote the steps where I am facing issue. The lines given above are exactly replaced by the lines given in code sample below.)

Since many of them are not available now. I searched and trying to change as follows 1, 2

import matplotlib
from matplotlib import pyplot
import cv2

img = matplotlib.pyplot.imread(filename)

img = cv2.resize(img, dsize=(299, 299, 3), interpolation=cv2.INTER_LINEAR)

But, i am still getting the following error

cv2.error: OpenCV(4.5.3) :-1: error: (-5:Bad argument) in function 'resize'
> Overload resolution failed:
>  - Can't parse 'dsize'. Expected sequence length 2, got 3
>  - Can't parse 'dsize'. Expected sequence length 2, got 3

It seems that opencv just resize two dimensional images only.

Is there any simple option i.e., using single library, to perform the desired operations without producing any error? If not, how can I resize that image numpy array with bilinear interpolation?

1
  • 1
    cv2.resize says: Resizing, by default, does only change the width and height of the image. That's why it's complaining when you give a 3 element shape, while expect only 2. The old docs for imresize seem to expect to 2 values as well, but it may have ignored the 3rd. The 3 is channel/color number, which shouldn't change with resize. Commented Jul 25, 2021 at 16:55

1 Answer 1

1

Could you try this?

img = cv2.resize(img, dsize=(299, 299), interpolation=cv2.INTER_AREA)

Make sure the data type of your image is uint8.

If you want a change in the third dimension you can try numpy.reshape() function.

img = np.random.randint(0,255,(400,400))
img = img.reshape(200,200,4)
plt.imshow(img)

4 Channel

In your case

img = cv2.imread("imagepath",mode='RGB')
Sign up to request clarification or add additional context in comments.

2 Comments

What about 3 in last dimension?
If you want a change in the third dimension you can try numpy.reshape.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.