![]() ![]() |
CImage:Expand
The Expand method enlarges the background "canvas"around the image. The border is assigned a value and Gaussian random noise may be optionally added. The result replaces the current image.
bResult = CImage:Expand( CRect, value, noise=0 ) |
CRect describes the new image size and placement.
See Remarks.
value is the pixel value of the new background, and
may be a number or string.
noise is the optional noise sigma, and may be a
number or string.
On success,
this method returns true.
On failure,
this method returns false.
This method creates a new, larger image that extends the borders with a value and optional random noise. The scale of the image is not changed, but the existing image is imbedded into a larger canvas. The new size and the position of the current image are encoded in the members of a CRect as follows:
Let
xmax = new column dimension, in
pixels.
Let
ymax = new row dimension, in
pixels.
Let
xmin = column (x) position in the
expanded image.
Let
ymin = row (y) position in the expanded
image.
Use
CRect:Set( xmin,
xmax, ymin, ymax ) or an equivalent method to initialize the
CRect.
If you do not want to add random noise to the border region, set noise=0 or omit the value from the argument list.
Suppose that a CImage I exists. The following script fragment doubles its width and height and centers the current image in the new image. The new background value is 1000 and the noise sigma is 8.25:
nCols = I:Cols() * 2 |
-- new width in pixels |
nRows = I:Rows() * 2 |
-- new height in pixels |
cOff = I:Cols() / 4 |
-- new edge at 1/4 of column dimension |
rOff = I:Rows() / 4 |
-- new edge at 1/4 of row dimension |
R = CRect:new() |
-- create a rectangle |
R:Set(cOff,nCols,rOff,nRows) |
|
I:Expand( R, "100", 8.25 ) |
-- perform the operation on image I |