Mahotas – Creating RGB Image
Last Updated :
10 Jul, 2020
In this article we will see how we can create a RGB image in mahotas. An RGB image, sometimes referred to as a truecolor image, is stored in MATLAB as an m-by-n-by-3 data array that defines red, green, and blue color components for each individual pixel. RGB image can be created with the help of array of each channel.
In order to do this we will use as_rgb
method
Syntax : mahotas.as_rgb(r, g, b)
Argument : It takes three numpy array as argument
Return : It returns RGB ndarray object
Below is the implementation
import mahotas
import mahotas.demos
from pylab import gray, imshow, show
import numpy as np
r = np.arange( 2500 ).reshape( 50 , 50 )
g = np.arange( 2500 ).reshape( 50 , 50 )
b = np.arange( 2500 ).reshape( 50 , 50 )
r = r * 0
g = g * 100
b = b * 0
img = mahotas.as_rgb(r, g, b)
imshow(img)
show()
|
Output :
Another example
import mahotas
import mahotas.demos
from pylab import gray, imshow, show
import numpy as np
z1 = np.linspace( 0 , np.pi)
X, Y = np.meshgrid(z1, z1)
red = np.sin(X)
green = np.cos( 4 * Y)
blue = X * Y
img = mahotas.as_rgb(red, green, blue)
imshow(img)
show()
|
Output :
Share your thoughts in the comments
Please Login to comment...