2.1.17.5.14 ocmath_image_lines_profile


Description

Computes the intensity along a straight line or a polyline in an image.

Syntax

int ocmath_image_lines_profile( int nRows, int nCols, double * pMat, int nVertices, double * pxVertices, double * pyVertices, int nPoints, double * pxPoints, double * pyPoints, double * pIntensity, double * pError = NULL, int nWidth = 1, int iMethod = INTERP2_NEAREST, int iProjection = PROJECTION_NONE )

Parameters

nRows
[input] The number of rows.
nCols
[input] The number of columns.
pMat
[input] The input matrix of size nRows*nCols.
nVertices
[input] The number of vertices contained in the polyline path. Constraint: nVertices >= 2.
pxVertices
[input] The X coordinates of polyline path.
pyVertices
[input] The Y cooridnates of polyline path.
nPoints
[input] The number of points to be interpolated.
pxPoints
[output] The X coordinates of size nPionts.
pyPoints
[output] The Y Coordinates of size nPoints.
pIntensity
[output] The output intensities of size nPoints. If nWidth > 1, the function will average pixels in a direction perpendicular to the path.
pError
[output] Standear error of mean for averaging for nWidth > 1.
nWidth
[input] The width of the polyline, in the unit of matrix index. nWdith = (nWidth%2 == 1) ? nWidth : nWidth +1.
iMethod
[input] The interpolation methods: INTERP2_NEAREST, INTERP2_BILINEAR, INTERP2_BICUBIC, INTERP2_SPLINE.
iProjection
[input] Projects to X or Y axis when equally distributing interpolation points.

Return

Returns OE_NOERROR if succeed, error codes otherwise.

Examples

EX1

//Before running, make sure a matrixlayer exists and activated in current project
#define NUM_PTS_IN_LINES    200
#define LINE_WIDTH            3
void ocmath_image_lines_profile_ex1(int x1, int y1, int x2, int y2)
{
    MatrixLayer ml = Project.ActiveLayer();
    MatrixObject mo = ml.MatrixObjects(0);
    matrixbase& matbase = mo.GetDataObject();
    matrix mat = matbase;

    int nCols = mat.GetNumCols();
    int nRows = mat.GetNumRows();

    vector vx, vy;
    vx.Add(x1);
    vx.Add(x2);
    vy.Add(y1);
    vy.Add(y2);

    vector vIntensity(NUM_PTS_IN_LINES);
    vector vError(NUM_PTS_IN_LINES);    
    vector vXPoints(NUM_PTS_IN_LINES);
    vector vYPoints(NUM_PTS_IN_LINES);
    
    int nSize = vx.GetSize();
    
    int nRet = ocmath_image_lines_profile(nRows, nCols, mat,
        nSize, vx, vy,
        NUM_PTS_IN_LINES, vXPoints, vYPoints, vIntensity, NULL,
        LINE_WIDTH, INTERP2_NEAREST, PROJECTION_NONE); 
        
    if (nRet != OE_NOERROR)
    {
        printf("Error occurs when calling ocmath function!\n");
        return
    }
    
    static GraphPage gp;
    if (!gp.IsValid())
    {
        gp.Create("Line");
    }
    vector vPlotX;
    vPlotX.Data(1, NUM_PTS_IN_LINES);
    static Worksheet wks;
    if (!wks.IsValid())
    {
        wks.Create("Origin", CREATE_HIDDEN);
    }
    DataRange drOut;
    drOut.Add("X", wks, 0, 0, -1, 0);
    drOut.Add("Y", wks, 0, 1, -1, 1);
    drOut.SetData(&vIntensity, &vPlotX);

    GraphLayer gl = gp.Layers(0);
    gl.AddPlot(drOut, IDM_PLOT_LINE);
    gl.Rescale();
}

Remark

Computes the intensity along a straight line or a polyline in an image.
The function chooses equally spaced points along the line that you specified, or along the horizontal or vertical direction specified by iProjection.
Two dimensional interpolations are used to find intensity value for every point.
When the line width is larger than 1 pixel, the function averages points on a line perpendicular to the current point on path; standard deviation from computation is given.
The function works in matrix index space, and users may want to map the result intensities back into XYZ space after calling.

See Also

ocmath_2d_interpolate

Header to Include

origin.h

Reference