Parameters: |
|
---|---|
Returns: |
|
Other Parameters: |
|
matshow
imshow
expects RGB images adopting the straight(unassociated) alpha representation.data[<arg>]
) andmembership test (<arg>indata
).imshow()
creates an image from a2-dimensional numpy array. The image will have one square for eachelement of the array. The color of each square is determined by the value of the correspondingarray element and the color map used by imshow()
.imshow()
scales elements of the numpy array so that the smallest elementbecomes 0, the largest becomes 1, and intermediate values are mapped to the interval[0, 1] by a linear function. Optionally imshow()
can be called with arguments vmin
and vmax
. In such case all elements of the array smaller or equal to vmin
are mappedto 0, all elements greater or equal to vmax
are sent to 1, and the elements betweenvmin
and vmax
are mapped in a linear fashion into the interval [0,1].imsave()
function is similar to imshow()
, but instead ofdisplaying an image it saves it to a file. In the file eachelement of the numpy array describes one pixel. The imsave()
function does not have the interpolation
argument.(0,0,0)
represents the black color and (1,1,1)
(or(255,255,255)
) represents white.imshow()
and imsave()
can create images withcolors specified by RGB coordinates. To do thiswe use a 3-dimensional numpy array a
of dimensions m (times)n (times) 3. Such array consists of three slices a[:,:,0]
,a[:,:,1]
, and a[:,:,2]
that give RGB coordinates of colors inthe image.imshow()
and imsave()
produce an image from a numpy array,the imread()
function takes as its argument an image file andconverts it into a numpy array. The following code uses the filetiger.jpg.img_array
a 3-dimensional numpy array that describes RGB coordinatesof all pixels of the image:img_array
are positive integers. This is the casebecause, as it was mentioned above, in computer applications RGB coordinates areoften represented by integers in the range 0-255. For the purposes ofmanipulating this array it will be convenient to convert its entriesinto floats in the range 0.0-1.0. This can be done by dividing allentries of img_array
by 255:imshow()
to display the image: