CImage:Expand2d


The Expand2d method enlarges a 2-dimensional image in 1 or 2 dimensions. An offset also can be specified along the direction of expansion. By default, new pixels are filled with value 0. You also can specify a fill value and a noise value for the new pixels. To work with 1-d or general n-dimensional image, use Expand1d or Expand, respectively.

Syntax

bSuccess = CImage:Expand2d( CRect )

bSuccess = CImage:Expand2d( CRect, sValue )

bSuccess = CImage:Expand2d( CRect, sValue, sSigma )

bSuccess = CImage:Expand2d( nLengthX, LengthY, nOffsetY, nOffsetY )

bSuccess = CImage:Expand2d( nLengthX, LengthY, nOffsetY, nOffsetY, sValue )

bSuccess = CImage:Expand2d( nLengthX, LengthY, nOffsetY, nOffsetY, sValue, sSigma )

where

    CRect specifies the expansion as a CRect (rectangle) object. The elements of the CRect are specified as described below.

    nLengthX and nLengthY are the new number of elements (pixels) along axis 1 and axis 2.

    nOffsetX and nOffsetY are the number of elements (pixels) to offset the existing data along the axis 1 and axis 2. If not specified, no offsets are applied.

    sValue is the noise sigma used for blank pixels created by the expansion or offset.

    sSigma is the optional noise sigma for blank pixels created by the expansion or offset.

    bSuccess is the returned success code. On success it is true, otherwise 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=0or omit the value from the argument list.

Example

Suppose that a CImage I exists. The following script 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 = NewRect()

-- create a rectangle

R:Set(cOff,nCols,rOff,nRows)

 

I:Expand( R, "100", 8.25 )

-- perform the operation on image I

Related Topics

Expand

Expand1d

Offset2d

Offset

CImage class

CRect class