Python Digital Image processing (5): Drawing of images

Source: Internet
Author: User

In fact, we have already used the drawing of the image in the front, such as:

Io.imshow (IMG)

This line of code is to use the Matplotlib package to draw the picture, after the successful drawing, return a matplotlib type of data. To display the drawn picture, we can call the show () function to display it, but in practice we can omit the show () function and display it automatically.

 from Import io,dataimg=Data.astronaut () DST=io.imshow (img)print(type (DST))
Io.show ()

Shown as:

As you can see, the type is ' matplotlib.image.AxesImage ', except for the information of the image itself, as well as other information such as sitting ruler. If you want to display two pictures at the same time, the first picture will be overwritten when the second picture is displayed.

Matplotlib is a library of professional drawings, equivalent to plot in MATLAB, you can set up multiple figures, set the caption of a figure, hide the ruler, and even use subplot to display multiple images in a figure. In general, we can import matplotlib libraries like this:

import Matplotlib.pyplot as Plt

In other words, our drawing is actually using the Pyplot module of the Matplotlib package.

Example: three channels to separate and display astronaut pictures simultaneously

 fromSkimageImportDataImportMatplotlib.pyplot as Pltimg=Data.astronaut () plt.figure (Num='Astronaut', figsize= (8,8))#Create a window named astronaut, and set the sizePlt.subplot (2,2,1)#four pictures can be displayed by dividing the window into two rows, two columns, four sub-WindowsPlt.title ('Origin Image')#First picture titlePlt.imshow (IMG)#draw the first picturePlt.subplot (2,2,2)#Second child windowPlt.title ('R Channel')#Second Picture titlePlt.imshow (Img[:,:,0],plt.cm.gray)#draw a second picture, and it's a grayscale imagePlt.axis ('off')#coordinate dimensions are not displayedPlt.subplot (2,2,3)#Third child windowPlt.title ('G Channel')#Third picture titlePlt.imshow (Img[:,:,1],plt.cm.gray)#draws a third picture, and is a grayscale imagePlt.axis ('off')#coordinate dimensions are not displayedPlt.subplot (2,2,4)#Fourth child windowPlt.title ('B Channel')#Fourth picture titlePlt.imshow (Img[:,:,2],plt.cm.gray)#draws the fourth picture, and is a grayscale imagePlt.axis ('off')#coordinate dimensions are not displayedplt.show ()#Display window

Another way to write is to:

ImportMatplotlib.pyplot as Plt fromSkimageImportdata,colorimg=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") forAxinchaxes.ravel (): Ax.axis ('off') fig.tight_layout ()#automatic adjustment of parameters between subplot

The two methods of writing effect is the same, you like which kind of the use of which!!

In addition to using the Matplotlib library to draw pictures, Skimage also has another module Imageviewer, which can also display pictures.

It uses the QT tool to create a canvas for drawing images on the canvas.

Cases:

 from Import Data  from Import  == imageviewer (img) viewer.show ()

Python Digital Image processing (5): Drawing of images

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.