
Calling Sequence


ImageTools[Draw][command]( arguments )
command( arguments )


Description


•

ImageTools:Draw is a subpackage of ImageTools that provides primitives for drawing into an ImageTools:Image. All primitives work in terms of continuous mathematical coordinates, not discrete pixels, and are rendered using antialiasing.



List of ImageTools:Draw Package Commands


•

The following is a list of the commands in the ImageTools[Draw] package.



Coordinate System


•

ImageTools:Draw uses a different coordinate system than that of the underlying ImageTools:Image. An Image is an H×W, H×W×3, or H×Wx4 Array of double precision (64bit) hardware floating point values, each representing a pixel. The topleft pixel of the image has the coordinates [1,1] and the bottomright pixel is at [H,W]. Notice that this is both upsidedown compared to Cartesian coordinates (the lowest y value is at the top), and also that the order of coordinates is reversed (the coordinates are of the form [y,x]). This was done to correspond with the conventions of indexing arrays and matrices, where indexing starts at the top, and the row is specified first.

•

The coordinate system used by ImageTools:Draw is that of the upperright quadrant of the Cartesian coordinate system. Furthermore, the coordinates refer to pixel boundaries, not the pixels themselves. For an image stored in an H×W Array, ImageTools:Draw coordinates are of the form [x,y], where 0 ≤ x ≤ W and 0 ≤ y ≤ H. The bottomleft corner has coordinates [0,0] and the topright corner [W,H].

•

The coordinates specified in ImageTools:Draw commands are not restricted to integer values. A point, such as the endpoint of a line, can be specified to be anywhere within the range of valid coordinates. Since all primitives drawn by ImageTools:Draw are rendered using antialiasing, subpixelsized changes in the positions of points are actually visible. The images below were generated at 20 pixels width and 15 pixels height, magnified by a factor of 16, and then augmented with red crosshairs to show the mathematical endpoints of the lines.


Line from (2.0,2.0) to (18.0,13.0), thickness=1:


Line from (2.5,2.5) to (17.5,12.5), thickness=1:


The correspondence between point coordinates [x,y] and Array indices [r,c] is given by:



Primitives


•

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.

•

Each primitive is a member of the ImageTools:Draw package, and can be referenced by prefixing the primitive name with the package name (e.g., ImageTools:Draw:Poly), or using the bare primitive name in a context in which ImageTools:Draw is in scope: after a call to with(ImageTools:Draw), within a procedure having a uses ImageTools:Draw clause, or within a use ImageTools:Draw in ... end statement.

•

In addition to the drawing primitives any other command from the ImageTools package can be applied to the image at any time, so one can combine drawing operations with other image manipulation techniques.



Examples


>

$\mathrm{with}\left(\mathrm{ImageTools}\right)\:$

>

$\mathrm{with}\left(\mathrm{ImageTools}:\mathrm{Draw}\right)\:$

>

$\mathrm{img}\u2254\mathrm{Create}\left(240\,240\,\mathrm{channels}=3\,\mathrm{background}=\mathrm{white}\right)\:$

>

$\mathrm{Circle}\left(\mathrm{img}\,120\,120\,24064\,\mathrm{color}=0.5\,\mathrm{thickness}=3\right)$

>

$\mathrm{Poly}\left(\mathrm{img}\,\left[\left[60\,60\right]\,\left[60\,180\right]\,\left[180\,180\right]\,\left[180\,60\right]\,\left[60\,60\right]\right]\,\mathrm{color}=0\,\mathrm{fill\_color}=\left[0.9\,1\,0.8\right]\,\mathrm{fill\_pattern}=''sphere''\right)$

>

$\mathrm{Text}\left(\mathrm{img}\,121\,131\,''Draw''\,\mathrm{color}=\left[0.6\,0.2\,0.2\right]\,\mathrm{font}=18\,\mathrm{font\_size}=30\right)\:$

>

$\mathrm{Text}\left(\mathrm{img}\,120\,130\,''Draw''\,\mathrm{color}=\left[0.4\,0.1\,0.1\right]\,\mathrm{font}=18\,\mathrm{font\_size}=30\right)\:$

>

$\mathrm{expr}\u2254{\left(x120\right)}^{2}+{\left(y120\right)}^{2}={\left(\frac{24064}{2}\right)}^{2}\:$

>

$r\u2254\mathrm{solve}\left(\mathrm{expr}\,y\right)$

${r}{\u2254}{120}{+}\sqrt{{}{{x}}^{{2}}{+}{240}{}{x}{}{6656}}{,}{120}{}\sqrt{{}{{x}}^{{2}}{+}{240}{}{x}{}{6656}}$
 (6.1) 
>

$\mathbf{for}\phantom{\rule[0.0ex]{0.3em}{0.0ex}}\mathrm{x1}\phantom{\rule[0.0ex]{0.3em}{0.0ex}}\mathbf{from}\phantom{\rule[0.0ex]{0.3em}{0.0ex}}32.\phantom{\rule[0.0ex]{0.3em}{0.0ex}}\mathbf{by}\phantom{\rule[0.0ex]{0.3em}{0.0ex}}11.\phantom{\rule[0.0ex]{0.3em}{0.0ex}}\mathbf{to}\phantom{\rule[0.0ex]{0.3em}{0.0ex}}208.\phantom{\rule[0.0ex]{0.3em}{0.0ex}}\mathbf{do}\phantom{\rule[0.0ex]{0.0em}{0.0ex}}\phantom{\rule[0.0ex]{2.0em}{0.0ex}}\mathrm{SolidCircle}\left(\mathrm{img}\,\mathrm{x1}\,\mathrm{eval}\left(r\left[1\right]\,'x'=\mathrm{x1}\right)\,5\,\mathrm{color}=\mathrm{black}\right);\phantom{\rule[0.0ex]{0.0em}{0.0ex}}\phantom{\rule[0.0ex]{2.0em}{0.0ex}}\mathrm{SolidCircle}\left(\mathrm{img}\,\mathrm{x1}\,\mathrm{eval}\left(r\left[2\right]\,'x'=\mathrm{x1}\right)\,5\,\mathrm{color}=\mathrm{red}\right)\phantom{\rule[0.0ex]{0.0em}{0.0ex}}\mathbf{end}\phantom{\rule[0.0ex]{0.3em}{0.0ex}}\mathbf{do}$

>

$\mathrm{Embed}\left(\mathrm{img}\right)$



Compatibility


•

The ImageTools[Draw] package was introduced in Maple 2018.



