python-scipyHow can I use Python and SciPy to read an image file?
Using Python and SciPy to read an image file is relatively straightforward. The following example code reads in an image file and prints out its dimensions:
from scipy import misc
img = misc.imread('image.jpg')
print(img.shape)
Output example
(300, 400, 3)
The code is composed of the following parts:
from scipy import misc
imports the SciPy modulemisc
which contains functions to work with images.img = misc.imread('image.jpg')
reads in the image fileimage.jpg
and stores it as an array in the variableimg
.print(img.shape)
prints out the shape of the arrayimg
, which is the dimensions of the image.
Helpful links
More of Python Scipy
- How do I create a 2D array of zeros using Python and NumPy?
- How do I create a zero matrix using Python and Numpy?
- How do I update Python SciPy?
- How can I use Python and SciPy to generate a uniform distribution?
- How do I calculate a p-value using Python and SciPy?
- How do I install and use Python-Scipy on Ubuntu 20.04?
- How do I integrate scipy with Python?
- How do I create a numpy array of zeros using Python?
- How can I use Python and Numpy to zip files?
- How do I use the Python Scipy package?
See more codes...