In fact, we have used the drawing of the image before, such as:
Io.imshow (IMG)
The essence of this line of code is to draw the picture with the Matplotlib package, and then return a matplotlib type of data after the drawing succeeds. Therefore, we can also write this:
Import Matplotlib.pyplot as PLT
plt.imshow (IMG)
The Imshow () function is in the following format:
Matplotlib.pyplot.imshow (X, Cmap=none)
X: The image or array to draw.
CMAP: Color Map (COLORMAP), which is drawn by default to RGB (A) color space.
Other optional color maps are listed below:
| Color Map |
Description |
| Autumn |
Red-orange-yellow |
| Bone |
Black-White, X-ray |
| Cool |
Cyan-Magenta |
| Copper |
Black-Copper |
| Flag |
Red-white-blue-black |
| Gray |
Black-White |
| Hot |
Black-red-yellow-white |
| Hsv |
HSV color space, red-yellow-green-cyan-blue-magenta-red |
| Inferno |
Black-red-yellow |
| Jet |
Blue-green-yellow-red
|
| Magma |
Black-red-white |
| Pink |
Black-pink-white |
| Plasma |
Green-red-yellow |
| Prism |
Red-yellow-green-blue-violet-...-Green mode |
| Spring |
Magenta-Yellow |
| Summer |
Green-Yellow |
| viridis |
Blue-green-yellow |
| Winter |
Blue-Green |
Use more of the Gray,jet, such as:
Plt.imshow (Image,plt.cm.gray)
Plt.imshow (Img,cmap=plt.cm.jet)
Returns a Axesimage object after the picture is drawn on the window. To display this object on the window, we can call the show () function to display it, but in practice (in the Ipython environment), we can usually omit the show () function and automatically display it.
From skimage import io,data
img=data.astronaut ()
dst=io.imshow (img)
print (type (DST))
Io.show ()
Display as:
As you can see, the type is ' matplotlib.image. Axesimage '. Displays a picture, which we usually prefer to write:
Import Matplotlib.pyplot as PLT from
skimage import io,data
img=data.astronaut ()
plt.imshow (IMG)
Plt.show ()
Matplotlib is a professional drawing of the library, equivalent to the plot in MATLAB, you can set up a number of figure windows, set the figure title, hide the ruler, can even use subplot in a figure display more than one picture. In general we can import the Matplotlib library this way:
Import Matplotlib.pyplot as Plt
In other words, our drawing is actually using the Pyplot module of the Matplotlib package.
First, using the figure function and the subplot function to create the main window and the child graph respectively
Example: three passages that separate and display astronaut pictures at the same time
From skimage Import data
import Matplotlib.pyplot as Plt
img=data.astronaut ()
plt.figure (num= ' astronaut ') , figsize= (8,8)) #创建一个名为astronaut的窗口, and set the size
plt.subplot (2,2,1) #将窗口分为两行两列四个子图, you can display four pictures
plt.title (' Origin image ') #第一幅图片标题
plt.imshow (img) #绘制第一幅图片
plt.subplot (2,2,2) #第二个子图
plt.title (' R channel ') #第二幅图片标题
plt.imshow (img[:,:,0],plt.cm.gray) #绘制第二幅图片, and grayscale
plt.axis (' off ') #不显示坐标尺寸
Plt.subplot (2,2,3) #第三个子图
plt.title (' G channel ') #第三幅图片标题
plt.imshow (img[:,:,1],plt.cm.gray ) #绘制第三幅图片, and grayscale
plt.axis (' off ') #不显示坐标尺寸 plt.subplot (
2,2,4) #第四个子图
plt.title (' B Channel ') #第四幅图片标题
plt.imshow (img[:,:,2],plt.cm.gray) #绘制第四幅图片, and grayscale
plt.axis (' off ') #不显示坐标尺寸
plt.show () #显示窗口
In the picture drawing process, we use the figure () function under the Matplotlib.pyplot module to create the display window, which is in the form of:
Matplotlib.pyplot.figure (Num=none, Figsize=none, Dpi=none, Facecolor=none, Edgecolor=none)
All parameters are optional and have default values, so the function can be invoked without any arguments, with the following:
Num: Integral or character-type is OK. If set to integral type, the integer number represents the number of the window. If set to a character type, the string represents the name of the window. Use this parameter to name the window, and if the two window ordinal or name is the same, the last window overwrites the previous window.
Figsize: Sets the window size. is a tuple type of integer, such as figsize= (8,8)
DPI: Reshaping numbers that represent the resolution of a window.
Facecolor: The background color of the window.
Edgecolor: The border color of the window.
A window created with the figure () function can only display a picture, and if you want to display more than one picture, you need to divide the window into several sub graphs, displaying a different picture in each of the children. We can use the subplot () function to divide the child graph, the function format is:
Matplotlib.pyplot.subplot (nrows, Ncols, Plot_number)
Nrows: The number of rows in the child graph.
Ncols: The number of columns in the child graph.
Plot_number: The number of the current child graph.
Such as:
Plt.subplot (2,2,1)
The figure window is divided into 2 rows, 2 columns, and a total of 4 children, currently the 1th child graph. We can sometimes use this notation:
Plt.subplot (221)
The two kinds of writing effects are the same. The title of each child chart can be set using the title () function, or whether the axis () function can be used to set the ruler, such as:
Plt.subplot (221)
Plt.title ("A-subwindow")
plt.axis (' off ')
Second, use subplots to create Display window and partition sub-graph
In addition to the above method of creating a display window and dividing a child graph, there is another way to write it, as in the following example:
Import Matplotlib.pyplot as PLT from
skimage import data,color
img = data.immunohistochemistry ()
HSV = Color . RGB2HSV (IMG)
fig, axes = plt.subplots (2, 2, figsize= (7, 6))
ax0, Ax1, ax2, ax3 = Axes.ravel ()
ax0.imshow (img )
Ax0.set_title ("Original image")
ax1.imshow (hsv[:,:, 0], Cmap=plt.cm.gray)
ax1.set_title ("H")
ax2.imshow (hsv[:,:, 1], Cmap=plt.cm.gray)
ax2.set_title ("S")
ax3.imshow (hsv[:,:, 2], cmap= Plt.cm.gray)
ax3.set_title ("V") for
Ax-axes.ravel ():
ax.axis (' off ')
fig.tight_layout () #自动调整subplot间的参数
Use the subplots () function directly to create and divide the window. Notice that there is one more s than the previous subplot () function, which is in the form:
Matplotlib.pyplot.subplots (Nrows=1, Ncols=1)
Nrows: The number of rows for all child graphs, defaults to 1.
Ncols: The number of all child graphs, default is 1.
Returns a window figure, and a tuple-type Ax object that contains all the child graphs that can be knot