Scipy ValueError: ‘arr’ does not have a suitable array shape for any mode.

First, import scipy as sp by default.

Generally speaking, this type of problem is encountered with sp.misc.imsave or sp.misc.imresize.

1. imsave encountered the problem
According to scipy’s imsave official document, we can know that the arr in the parameter

arr: ndarray , MxN or MxNx3 or MxNx4

Array containing image values. If the shape is  MxN, the array represents a grey-level image. Shape  MxNx3 stores the red, green and blue bands along the last dimension. An alpha layer may be included, specified as the last colour band of an  MxNx4 array.

Corresponding to a single gray channel, RGB three channels, RGB+alpha four channels . But most people should only use the first two (actually because the blogger tried sp.misc.imsave to save the four-channel image and failed haha, no matter so many)

Therefore, if the dimensions of the image you want to save do not meet the above three (usually the first two) default methods , such an error will be reported!

(The problem encountered by the blogger is to save the single-channel picture in the way of M x N x 1, so it reports an error)

2.imresize encountered the problem
sp.misc.imresize(img, [img_size_1, img_size_2])

Please note that img must be a numpy array . The blogger did not use the prescribed format in this place and reported the error, remember to check it.

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *