Beispiel #1
0
void GImagePixelAdder::ProcessImageAOIed(const GImageDouble & aoiImage)
{
	IncrementCountProcessed();
	int Npix = aoiImage.size().width() * aoiImage.size().height();
	int hei = aoiImage.size().height();
	int wid = aoiImage.size().width();
	GDoubleArray & zArray = aoiImage.DoubleArray();
	double sum = 0;
	double sumSquare = 0;
	int pxTot = 0;
	for(int i = 0; i < Npix; i++) {
		double valPix = zArray[i];
		if(qIsNaN(valPix) || qIsInf(valPix))
			continue;
		pxTot++;
		sum += valPix;
		sumSquare += valPix * valPix;
	}
	if(!pxTot)
		return;
	double dNpixTot = double(pxTot);
	m_SumPix = sum;
	sum /= dNpixTot;
	sumSquare /= dNpixTot;
	m_AvePix = sum;
	m_StdDevPix = qSqrt(sumSquare - sum * sum);
}
void Fit( GImageDouble imageIn, GImage2DGaussFitter* ptr )
{
    QThread::currentThread()->setPriority(QThread::LowPriority);

    int Npix = imageIn.size().width() * imageIn.size().height();
    int hei = imageIn.size().height();
    int wid = imageIn.size().width();
    // the array of values
    GDoubleArray & zArray = imageIn.DoubleArray();
    // the array containing the coordinates of the points as described in the AlgLib documentation
    GDoubleArray x2Array(2 * Npix);
    int iTot = 0;
    for(int jLine = 0; jLine < hei; jLine++) {
        const uchar* scanL = imageIn.constScanLine(jLine);
        for(int iCol = 0; iCol < wid; iCol++) {
            x2Array[2 * iTot] = double(iCol);
            x2Array[2 * iTot + 1] = double(jLine);
            iTot++;
        }
    }
    // the array to set the weight of the point. For NaN and inf values, the weight is 0.0
    GDoubleArray wArray(Npix);
    for(int ind = 0; ind < Npix; ind++) {
        double & valPix = zArray[ind];
        if(qIsNaN(valPix) || qIsInf(valPix)) {
            zArray[ind] = 0.0; // put an acceptable value
            wArray[ind] = 0.0; // set the weigh to 0.0
        }
        else
            wArray[ind] = 1.0;
    }

    real_2d_array x;
    real_1d_array y;
    real_1d_array w;
    x.setcontent(Npix, 2, x2Array.constData());
    y.setcontent(Npix, zArray.constData());
    w.setcontent(Npix, wArray.constData());
    real_1d_array c;
    c.setlength(6);
    c[0] = ptr->m_FitMask[0] ? ptr->m_IniOffset	: ptr->m_Offset;
    c[1] = ptr->m_FitMask[1] ? ptr->m_IniAmpl	: ptr->m_Ampl;
    c[2] = ptr->m_FitMask[2] ? ptr->m_IniX0		: ptr->m_X0;
    c[3] = ptr->m_FitMask[3] ? ptr->m_IniY0		: ptr->m_Y0;
    c[4] = ptr->m_FitMask[4] ? ptr->m_IniSigmaX	: ptr->m_SigmaX;
    c[5] = ptr->m_FitMask[5] ? ptr->m_IniSigmaY	: ptr->m_SigmaY;

    double epsf = 0.0001;
    double epsx = 0.0001;
    ae_int_t maxits = 100;
    ae_int_t info;
    lsfitstate state;
    lsfitreport rep;
    double diffstep = 0.0001;

// STRANGE! fires "Warning: QObject::startTimer: timers cannot be started from another thread"
// 	ptr->UpdateGraphicsItem();

    int whichOne = 2;
    switch (whichOne)
    {
    case 1:
        lsfitcreatewf(x, y, w, c, Npix, 2, 6, diffstep, state);
        lsfitsetcond(state, epsf, epsx, maxits);
        lsfitsetxrep(state, true);
        lsfitfit(state, Gaus2D_func, function_to_call_after_each_iteration, ptr);
        lsfitresults(state, info, c, rep);
        break;
    case 2:
        lsfitcreatewfg(x, y, w, c, Npix, 2, 6, false, state);
        lsfitsetcond(state, epsf, epsx, maxits);
        lsfitsetxrep(state, true);
        lsfitfit(state, Gaus2D_func, Gaus2D_grad, function_to_call_after_each_iteration, ptr);
        lsfitresults(state, info, c, rep);
        break;
    case 3:
        lsfitcreatewfg(x, y, w, c, Npix, 2, 6, true, state);
        lsfitsetcond(state, epsf, epsx, maxits);
        lsfitsetxrep(state, true);
        lsfitfit(state, Gaus2D_func, Gaus2D_grad, function_to_call_after_each_iteration, ptr);
        lsfitresults(state, info, c, rep);
        break;
    case 4:
        lsfitcreatewfgh(x, y, w, c, Npix, 2, 6, state);
        lsfitsetcond(state, epsf, epsx, maxits);
        lsfitsetxrep(state, true);
        lsfitfit(state, Gaus2D_func, Gaus2D_grad, Gaus2D_hess, function_to_call_after_each_iteration, ptr);
        lsfitresults(state, info, c, rep);
        break;
    }

    GVectorDouble finalValues(6);
    c[4] = qAbs(c[4]);
    c[5] = qAbs(c[5]);
    for(int i = 0; i < 6 ; i++) {
        finalValues[i] = c[i];
    }
    QMetaObject::invokeMethod(ptr, "UpdateFinalResultValues", Qt::QueuedConnection, Q_ARG(GVectorDouble, finalValues));
}