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 miscimports the SciPy modulemiscwhich contains functions to work with images.img = misc.imread('image.jpg')reads in the image fileimage.jpgand 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 use Scipy zeros in Python?
- How can I use Python and SciPy to find the zeros of a function?
- How do I uninstall Python Scipy?
- How can I use RK45 with Python and SciPy?
- How do I use Python and SciPy to write a WAV file?
- How can I check if a certain version of Python is compatible with SciPy?
- How do I use the NumPy transpose function in Python?
- How do I use Python and SciPy to create a tutorial PDF?
- How can I use Python and SciPy to perform a Short-Time Fourier Transform?
See more codes...