Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the scipy.misc.imsave () function of python

Shulou Source: shulou.com Published: 2022-06-01 13:33:57 09月21日 Update

This article mainly introduces the python scipy.misc.imsave () function how to use the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe you will have a harvest after reading this python scipy.misc.imsave () function, let's take a look at it.

This function is used to store pictures and save arrays as images.

This feature is only available when Python Imaging Library (PIL) is installed. The version is also older, and the new replacement is imageio.imwrite ().

Usage: imsave (* args, * * kwds) parameters:

Name: file name or file name plus directory

The three formats of arr:np-array matrix and MxN or MxNx3 or MxNx4 correspond to grayscale image, RGB image and RGB+alpha image respectively.

Format: strtype, the type of image output, if omitted, the picture directly outputs the extension of the picture.

Usage: # Grayscale image from scipy.misc import imsavex = np.zeros ((255,255)) x = np.zeros ((255,255), dtype=np.uint8) x [:] = np.arange (255,255) imsave ('gradient.png', x) # RGB image rgb = np.zeros ((255,255,3), dtype=np.uint8) rgb [., 0] = np.arange (255,255) rgb [., 1] = 55rgb [. 2] = 1-np.arange (255) imsave ('rgb_gradient.png', rgb)

It is worth noting that by default, this function detects the range of RGB values you enter, and automatically expands the range to 0 to 255 if they are all between 0 and 1.

In other words, at this time, whether you multiply by 255 or not, the effect of the output picture is the same.

Add: imsave in scipy.misc has been disabled

Import scipy.miscdir (scipy.misc) # you can see that modules such as imsave can no longer be found in scipy1.3.1

Imageio package can be used instead

This is the end of imageio.imwrite 's article on "how to use python's scipy.misc.imsave () function". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to use the scipy.misc.imsave () function of python". If you want to learn more, you are welcome to follow the industry information channel.

Tags: Image function picture knowledge output content file name grayscale article scope between that is value function parameter case extension easy to operate Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Tech Info Shulou Information Docker macOS