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:
- [Solved] Error in uploading app icon when IOS app is released (image can’t contain alpha channels or transparencies)
- Solutions to the channel problem of PIL PNG format
- Error in SciPy. Misc. Toimage()
- [Solved] Tensorflow Error: ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray)
- [Solved] tf.summary Error: tags and values not the same shape
- Solve the problem of HTTP 000 connection failed for URL in Anaconda
- Python OpenCV BUG: all the input arrays must have same number of dimensions
- Anaconda establishes a new environment, and condahttpererror: http 000 connection failed for URL… Solution process appears
- [Solved] PyTorch error: TypeError: ‘builtin_function_or_method‘ object is unsubscriptable
- The Usage of Numpy.unravel_index() function