ImageTools[Draw]
Line
ImageTools:-Draw Line Primitive
Calling Sequence
Parameters
Description
Package Usage
Examples
Compatibility
Line( image, x1, y1, x2, y2, color, thickness, round, pattern )
image
-
ImageTools:-Image
x1
numeric
y1
x2
y2
color
(optional) see description
thickness
(optional) numeric := 1.0
round
(optional) truefalse := false
pattern
(optional) identical("none", "solid", "dash", "dot", "dashdot", "dashdotdot") := "solid"
After first creating an image using ImageTools:-Create, or loading an image with ImageTools:-Read, drawing operations can be performed on it using a number of primitives (functions that draw one kind of object). The first argument to each primitive is the image itself, as returned by Create or Read.
The Line primitive draws a straight line between two specified points. The same result can be achieved using the Poly primitive with a list of two points, except that the line primitive also has the ability to draw tapered lines.
The x1, y1, x2, and y2 arguments give the coordinates of the end-points, (x1,y1) and (x2,y2).
The color argument can be specified in one of several forms:
gray
A numeric value between 0 and 1 specifying a shade of gray. The value 0 corresponds to black, and 1 to white.
[r,g,b]
A list of three numeric values between 0 and 1 specifying the red, green, and blue components separately.
[r,g,b,α]
A list of four numeric values between 0 and 1 specifying the red, green, blue, and opacity (alpha) separately. When the opacity is less than 1, the color will be blended with the existing content of the image.
ColorTools:-Color
A value of type ColorTools:-Color.
ColorTools:-Color argument(s)
Any form accepted by the ColorTools:-Color constructor, such as a string giving a color name (e.g. "red", palette and color name (e.g. "Niagara DarkOrchid"), or palette and color number (e.g. "Nautical 1"). Two argument forms are accepted as well, but then it is necessary to always use the keyword form of the color argument, since otherwise the two arguments will be interpreted as two separate arguments to the drawing primitive. For example, color=("HSV",[0.5,0.6,0.6]).
The thickness argument specifies the apparent thickness of the line, measured in pixels. Because of anti-aliasing, the number of pixels used to render the line at any point may be more than this, but the line will appear to be of the specified thickness.
Instead of a single thickness, a list of two separate thicknesses for the start and end of the line can be specified, producing a tapered line
By default, the line ends exactly at the specified coordinates, and for a line with thickness noticeably larger than 1, the ends of the line will be perpendicular to the line itself. If the round argument is specified as true, then the line ends will be rounded, and the specified end-points will be the centers of those rounded ends, i.e., the line will extend by half its thickness in all directions from the end-points
The pattern argument can be used to draw lines with one of a fixed number of patterns. The default pattern, solid, draws solid lines. The other available patterns are:
"dash"
"dot"
"dashdot"
"dashdotdot"
"none"
The options beginning with color are best provided as keyword equations, but can also be provided as positional arguments starting in the 6th position as declared in the calling sequence above.
This function is part of the ImageTools:-Draw package, so it can be used in the short form Line(..) only after executing the command with(ImageTools:-Draw). However, it can always be accessed through the long form of the command by using ImageTools:-Draw:-Line(..).
with⁡ImageTools:
with⁡ImageTools:-Draw:
Lines of different thicknesses.
img≔Create⁡240,320,channels=3,background=white:
Line⁡img,32,32,288,144,color=0.25,thickness=0.5
Line⁡img,32,64,288,176,color=0.25,thickness=1
Line⁡img,32,96,288,208,color=0.25,thickness=3
Embed⁡img
Tapered lines.
Line⁡img,32,32,288,144,color=0.25,thickness=0.5,5
Line⁡img,32,96,288,208,color=0.25,thickness=15,5
Round vs. square line ends.
Line⁡img,32,32,288,144,color=0.25,thickness=10,round=true
Line⁡img,32,96,288,208,color=0.25,thickness=10,round=false
Supporting Functions for the Examples
Draw a red crosshair centered at (x*scale,y*scale).
crossHair := proc( img :: Array, x :: numeric, y :: numeric, scale :: numeric ) uses ImageTools:-Draw; Line(img,(x-1.5)*scale,y*scale,(x+1.5)*scale,y*scale, color="red",thickness=1.5); Line(img,x*scale,(y-1.5)*scale,x*scale,(y+1.5)*scale, color="red",thickness=1.5) end:
Draw a background grid with specified interval.
gridFill := proc( img :: Array, interval :: numeric ) local x, y, w, h; uses ImageTools:-Draw; w, h := Width(img), Height(img); for x from interval by interval while x < w do Line(img,x,0,x,h,color=[0,1,1,0.25]) od; for y from interval by interval while y < h do Line(img,0,y,w,y,color=[0,1,1,0.25]) od end:
Zoomed image of anti-aliased line with integer endpoints.
img≔Create⁡15,20,channels=3,background=white:
Line⁡img,2,2,18,13,color=0
img≔Scale⁡img,16,method=nearest:
gridFill⁡img,16
crossHair⁡img,2,2,16
crossHair⁡img,18,13,16
Zoomed image of anti-aliased line with non-integer endpoints.
Line⁡img,2.5,2.5,17.5,12.5,color=0
crossHair⁡img,2.5,2.5,16
crossHair⁡img,17.5,12.5,16
Line pattern examples.
img≔Create⁡260,320,channels=3,background=white:
Line⁡img,32,32,288,144,pattern=dash
Line⁡img,32,64,288,176,pattern=dot
Line⁡img,32,96,288,208,pattern=dashdot
Line⁡img,32,128,288,240,pattern=dashdotdot
The ImageTools[Draw][Line] command was introduced in Maple 2018.
For more information on Maple 2018 changes, see Updates in Maple 2018.
See Also
ImageTools
ImageTools:-Draw:-Circle
ImageTools:-Draw:-Poly
ImageTools:-Draw:-SolidRectangle
ImageTools:-Draw:-Text
ImageTools:-Draw:-TextSize
Download Help Document