Mahotas – Loading image as grey
In this article we will see how we can load the image as grey in mahotas, there are lots of images available in mahotas we use mahotas.demos.load method to load them, in this tutorial we will use “luispedro” image, below is the command to load it.
mahotas.demos.load('luispedro')
Below is the luispedro image
In order to do this we will use mahotas.demos.load method
Syntax : mahotas.demos.load(‘luispedro’, as_grey=True)
Argument : It takes image name as argument
Return : It returns numpy.ndarray i.e image object
Example 1:
Python3
import mahotas
import mahotas.demos
import numpy as np
from pylab import imshow, gray, show
from os import path
photo = mahotas.demos.load( 'luispedro' )
print ( "Original Image" )
imshow(photo)
show()
photo = mahotas.demos.load( 'luispedro' , as_grey = True )
print ( "Image loaded as grey" )
imshow(photo)
show()
|
Output :
Example 2:
Python3
import mahotas
import mahotas.demos
import numpy as np
from pylab import imshow, gray, show
from os import path
photo = mahotas.demos.load( 'luispedro' )
print ( "Original Image" )
imshow(photo)
show()
photo = mahotas.demos.load( 'luispedro' , as_grey = True )
photo = photo.astype(np.uint8)
gray()
print ( "Image loaded as grey" )
imshow(photo)
show()
|
Output :
Last Updated :
20 Aug, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...