2.1.23.2.3 ocmath_find_baseline_part_by_small_curvature


Description

Get baseline points of the input curve by second derivative method or small curvature

Syntax

int ocmath_find_baseline_part_by_small_curvature( UINT nSize, const double * px, const double * py, double * pBasePtsX, double * pBasePtsY, double dThresh, double dTrimThresh = 0.8, int nLeftRightPts = 0)

Parameters

nSize
[input] size of data px,py;
px
[input] The x data of the curve;
py
[input] The y data of the curve;
pBasePtsX
[output] The x data of baseline of the curve
pBasePtsY
[output] The y data of baseline of the curve
dThresh
[input] The threshold of curvature (or 2nd derivative) restricted in (0,1), suggested value 0.005 but can be increased to return more baseline points, the most likely baselines points are sorted to put in the beginning of the vector (while there may exist spurious baseline points in the end of the vector)
dTrimThresh
[input] The trim threshold, restricted in (0,1), suggested value 0.8, (near 1 trim less points, while near 0 trim more points). This is used to trim out spurious baseline points in the end of the vector.
nLeftRightPts
[input] Number of points to one side of symmetric window(left or right) of given point.
Zero leaves the data unchanged.

Return

Return number of baseline points if succeed, otherwise, non-zero error code is returned.

Examples

EX1

//Assume in the current worksheet, the first column is X data and second column is
//Y data. This piece of code get the XY data from the above two clomns and find the 
//baseline. Another two new columns will be added into current worksheet to show the 
//result. The data plots of the original curve and the baseline curve will be given. 
void ocmath_find_baseline_part_in_smooth_curve_ex1(double dThresh)
{
    Worksheet wks = Project.ActiveLayer();
    if(!wks)
        printf("no active worksheet found\n"); 
    //get X&Y Data of the curve
    Dataset dsSrcX(wks,0);
    Dataset dsSrcY(wks,1);
 
    int nSize = dsSrcY.GetSize();
    vector vx(nSize);
    vector vy(nSize);
    vx = dsSrcX;
    vy = dsSrcY;
 
    vector vxBaseLine(nSize);
    vector vyBaseLine(nSize);
 
    int nNumBaselinePts = ocmath_find_baseline_part_by_small_curvature((UINT)nSize,vx,vy,vxBaseLine,vyBaseLine,dThresh);
    if(nNumBaselinePts<0) {printf("error\n"); return;}
    else
    {
        vxBaseLine.SetSize(nNumBaselinePts);
        vyBaseLine.SetSize(nNumBaselinePts);
    }
 
    //add two new columns to show the result
    int nColX = wks.AddCol();
    int nColY = wks.AddCol();
    Dataset dsBaseLineX(wks,nColX);
    Dataset dsBaseLineY(wks,nColY);
    dsBaseLineX = vxBaseLine;
    dsBaseLineY = vyBaseLine;
 
    XYRange xySrc, xyBaseLine;
    xySrc.Add(wks,0,"X");
    xySrc.Add(wks,1,"Y");
    xyBaseLine.Add(wks,nColX,"X");
    xyBaseLine.Add(wks,nColY,"Y");
 
    //new a graphlayer to plot the original data and baseline
    GraphPage gp;
    gp.Create("origin");
    if(!gp)
    {
        printf("graph page creation failed\n");
    }
    GraphLayer gl(gp.GetName(),0);
    if(!gl)
    {
        printf("Graph layer failed\n");
    }
 
    gl.AddPlot(xySrc);
    int nDataPlot=gl.AddPlot(xyBaseLine);
    DataPlot dp=gl.DataPlots(nDataPlot);
    dp.SetColor(1);    
    gl.Rescale();
    return;
}

Remark

See Also

Header to Include

origin.h

Reference