Python Digital Image Processing (12): Drawing graphics

Source: Internet
Author: User

Graphics include lines, circles, ellipses, polygons, and so on.

In the Skimage package, draw the drawing module, do not confuse with the drawing image.

1. Draw lines

The function call format is:

Skimage.draw. Line (r1,c1,r2,c2)

R1,R2: Number of rows and end points of the start point

C1,C2: Number of columns and end points of the start point

Returns the coordinates of all points on the currently drawn drawing, such as:

RR, CC =draw.line (1, 5, 8, 2)

Represents a line from (1,5) to (8,2), returning all pixel coordinates on the line [RR,CC]

 from Import Draw,data Import Matplotlib.pyplot as pltimg==draw.line (1, 470,=255 plt.imshow(IMG, Plt.cm.gray)

If you want to draw lines of other colors, you can use the set_color () function, in the following format:

Skimage.draw. Set_color (img, coords, color)

Cases:

Draw.set_color (img,[rr,cc],[255,0,0])

The red line is drawn.

 from Import Draw,data Import Matplotlib.pyplot as pltimg==draw.line (1, img,[rr,cc],[0,0, +) Draw.set_color 255]) plt.imshow (Img,plt.cm.gray)

2. Draw a Circle

function format:skimage.draw. Circle (Cy, CX, radius)

Cy and CX represent center points, radius represents radius

 from Import Draw,data Import Matplotlib.pyplot as pltimg=Data.chelsea () RR, CC=draw.circle (150,150,50) Draw.set_color (IMG, [rr,cc],[255, 0,0]) plt.imshow (Img,plt.cm.gray)

3. Polygon

function Format: Skimage.draw. Polygon (y,x)

Y is the rowset of the polygon vertices, and X is the collection of column values for each vertex.

 from Import Draw,data Import Matplotlib.pyplot as Plt Import NumPy as npimg=Data.chelsea () Y=np.array ([10,10,60,60]) X=np.array ([200,400,400,200  ]) RR, cc=draw.polygon (y,x) draw.set_color (img,[rr,cc],[255, 0,0]) plt.imshow (Img,plt.cm.gray) 

I've only set four vertices here, so it's a quad.

4. Ellipse

Format:skimage.draw. Ellipse (Cy, CX, Yradius, Xradius)

Cy and CX are center point coordinates, and Yradius and Xradius represent short and long axes.

 from Import Draw,data Import Matplotlib.pyplot as pltimg=Data.chelsea () RR, CC=draw.ellipse (in.) Draw.set_color ( img,[rr,cc],[255, 0,0]) plt.imshow (Img,plt.cm.gray)

5, Bessa Curve

format: Skimage.draw. Bezier_curve (y1,x1,y2,x2,y3,x3,weight)

Y1,X1 represents the first control point coordinate

Y2,X2 represents the coordinates of the second control point

Y3,X3 represents the third control point coordinate

The weight represents the weight of the middle control point and is used to control the curvature of the curve.

 from Import Draw,data Import Matplotlib.pyplot as pltimg=Data.chelsea () RR, CC=draw.bezier_curve (150,50,50,280,260,400,2) Draw.set_color (img,[rr,cc],[255, 0,0]) plt.imshow (Img,plt.cm.gray)

6. Draw Hollow Circle

And the previous circle is the same, but the front is a solid circle, and here to draw a hollow circle, only the border line.

Format:skimage.draw. Circle_perimeter (Yx,yc,radius)

YX,YC is the center coordinate, radius is the radius

 from Import Draw,data Import Matplotlib.pyplot as pltimg=Data.chelsea () RR, CC=draw.circle_perimeter (150,150,50) draw.set_ Color (img,[rr,cc],[255, 0,0]) plt.imshow (Img,plt.cm.gray)

7. Hollow Ellipse

Format:skimage.draw. Ellipse_perimeter (Cy, CX, Yradius, Xradius)

CY,CX means Center

Yradius,xradius = Short axis

 from Import Draw,data Import Matplotlib.pyplot as pltimg=Data.chelsea () RR, CC=draw.ellipse_perimeter (.) Draw.set_color (img,[rr,cc],[255, 0,0]) plt.imshow (Img,plt.cm.gray)

Python Digital Image Processing (12): Drawing graphics

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.