ImageTools[Draw] - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Graphics : Image Processing : ImageTools Package : Draw Subpackage : ImageTools/Draw/Line

ImageTools[Draw]

  

Line

  

ImageTools:-Draw Line Primitive

 

Calling Sequence

Parameters

Description

Package Usage

Examples

Compatibility

Calling Sequence

Line( image, x1, y1, x2, y2, color, thickness, round, pattern )

Parameters

image

-

ImageTools:-Image

x1

-

numeric

y1

-

numeric

x2

-

numeric

y2

-

numeric

color

-

(optional) see description

thickness

-

(optional) numeric := 1.0

round

-

(optional) truefalse := false

pattern

-

(optional) identical("none", "solid", "dash", "dot", "dashdot", "dashdotdot") := "solid"

Description

• 

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.

Package Usage

• 

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(..).

Examples

withImageTools:

withImageTools:-Draw:

Lines of different thicknesses.

imgCreate240,320,channels=3,background=white:

Lineimg,32,32,288,144,color=0.25,thickness=0.5

Lineimg,32,64,288,176,color=0.25,thickness=1

Lineimg,32,96,288,208,color=0.25,thickness=3

Embedimg

Tapered lines.

imgCreate240,320,channels=3,background=white:

Lineimg,32,32,288,144,color=0.25,thickness=0.5,5

Lineimg,32,96,288,208,color=0.25,thickness=15,5

Embedimg

Round vs. square line ends.

imgCreate240,320,channels=3,background=white:

Lineimg,32,32,288,144,color=0.25,thickness=10,round=true

Lineimg,32,96,288,208,color=0.25,thickness=10,round=false

Embedimg

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.

imgCreate15&comma;20&comma;channels=3&comma;background=white&colon;

Lineimg&comma;2&comma;2&comma;18&comma;13&comma;color=0

imgScaleimg&comma;16&comma;method=nearest&colon;

gridFillimg&comma;16

crossHairimg&comma;2&comma;2&comma;16

crossHairimg&comma;18&comma;13&comma;16

Embedimg

Zoomed image of anti-aliased line with non-integer endpoints.

imgCreate15&comma;20&comma;channels=3&comma;background=white&colon;

Lineimg&comma;2.5&comma;2.5&comma;17.5&comma;12.5&comma;color=0

imgScaleimg&comma;16&comma;method=nearest&colon;

gridFillimg&comma;16

crossHairimg&comma;2.5&comma;2.5&comma;16

crossHairimg&comma;17.5&comma;12.5&comma;16

Embedimg

Line pattern examples.

imgCreate260&comma;320&comma;channels=3&comma;background=white&colon;

Lineimg&comma;32&comma;32&comma;288&comma;144&comma;pattern=dash

Lineimg&comma;32&comma;64&comma;288&comma;176&comma;pattern=dot

Lineimg&comma;32&comma;96&comma;288&comma;208&comma;pattern=dashdot

Lineimg&comma;32&comma;128&comma;288&comma;240&comma;pattern=dashdotdot

Embedimg

Compatibility

• 

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