SolidRectangle - Maple Help

ImageTools[Draw]

 SolidRectangle
 ImageTools:-Draw Solid Rectangle Primitive

 Calling Sequence SolidRectangle( image, x1, y1, x2, y2, color )

Parameters

 image - x1 - numeric y1 - numeric x2 - numeric y2 - numeric color - (optional) see description

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 SolidRectangle primitive draws a rectangle whose boundaries fall (perceptually) on the mathematical rectangle specified by two opposing corners. This differs from using the Poly primitive with matching line color and solid fill pattern in that with the latter, half of the thickness of the enclosing line segments falls outside of the boundaries.
 • The x1, y1, x2, and y2 arguments define the bounds of the rectangle. There is no requirement that x1 be less than x2 or y1 be less than y2. That is, any two opposing corners can be specified, in either order.
 • 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. 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 color option can be specified as a keyword equation or as the 6th positional argument in the calling sequence.

Package Usage

 • This function is part of the ImageTools:-Draw package, so it can be used in the short form SolidRectangle(..) 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:-SolidRectangle(..).

Examples

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

Solid gray rectangle.

 > $\mathrm{img}≔\mathrm{Create}\left(240,320,\mathrm{channels}=3,\mathrm{background}=\mathrm{white}\right):$
 > $\mathrm{SolidRectangle}\left(\mathrm{img},32,32,288,208,\mathrm{color}=0.5\right)$
 > $\mathrm{Embed}\left(\mathrm{img}\right)$

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:

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 corners of the rectangles.

Zoomed solid gray rectangle with integer bounds.

 > $\mathrm{img}≔\mathrm{Create}\left(15,20,\mathrm{channels}=3,\mathrm{background}=\mathrm{white}\right):$
 > $\mathrm{SolidRectangle}\left(\mathrm{img},2,2,18,13,\mathrm{color}=0.5\right)$
 > $\mathrm{img}≔\mathrm{Scale}\left(\mathrm{img},16,\mathrm{method}=\mathrm{nearest}\right):$
 > $\mathrm{gridFill}\left(\mathrm{img},16\right)$
 > $\mathrm{crossHair}\left(\mathrm{img},2,2,16\right)$
 > $\mathrm{crossHair}\left(\mathrm{img},18,13,16\right)$
 > $\mathrm{Embed}\left(\mathrm{img}\right)$

Zoomed solid gray rectangle with some non-integer bounds.

 > $\mathrm{img}≔\mathrm{Create}\left(15,20,\mathrm{channels}=3,\mathrm{background}=\mathrm{white}\right):$
 > $\mathrm{SolidRectangle}\left(\mathrm{img},2.5,2,18,12.7,\mathrm{color}=0.5\right)$
 > $\mathrm{img}≔\mathrm{Scale}\left(\mathrm{img},16,\mathrm{method}=\mathrm{nearest}\right):$
 > $\mathrm{gridFill}\left(\mathrm{img},16\right)$
 > $\mathrm{crossHair}\left(\mathrm{img},2.5,2,16\right)$
 > $\mathrm{crossHair}\left(\mathrm{img},18,12.7,16\right)$
 > $\mathrm{Embed}\left(\mathrm{img}\right)$

Compatibility

 • The ImageTools[Draw][SolidRectangle] command was introduced in Maple 2018.