void xy_plots(int first = 5808, int last = 11688) { TH1D *h[2][3][2]; int i, j, k; char str[64]; TCanvas *cv[2]; TPaveStats *st; float y, dy; int mask[3] = {2, 4, 8}; // down, middle, up gROOT->SetStyle("Plain"); gStyle->SetOptStat(1000000); gStyle->SetOptFit(); TFile *fRoot = new TFile("xy_plots.root", "RECREATE"); HPainter *p[3]; for (i=0; i<3; i++) p[i] = new HPainter(mask[i], first, last); if (!p[0]->IsOpen() || !p[1]->IsOpen() || !p[2]->IsOpen()) { printf("Something wrong with data files.\n"); return; } for (i=0; i<3; i++) p[i]->SetFile(fRoot); TCut cVeto("gtFromVeto > 60"); TCut cIso("(gtFromPrevious > 45 && gtToNext > 80 && EventsBetween == 0) || (gtFromPrevious == gtFromVeto)"); TCut cX("PositronX[0] < 0 || (PositronX[0] > 2 && PositronX[0] < 94)"); TCut cY("PositronX[1] < 0 || (PositronX[1] > 2 && PositronX[1] < 94)"); TCut cZ = "PositronX[2] > 3.5 && PositronX[2] < 95.5"; TCut cR("Distance < 100 && DistanceZ > -40 && DistanceZ < 40"); TCut cT20("gtDiff > 2"); TCut cGamma("AnnihilationEnergy < 1.5 && AnnihilationGammas < 9"); TCut cPe("PositronEnergy > 1"); TCut cSig = cIso && cR && cT20 && cGamma && cPe; fRoot->cd(); for (i=0; i<2; i++) for (j=0; j<3; j++) { sprintf(str, "hX%d%c", j, (i) ? 'C' : 'S'); h[0][j][i] = new TH1D(str, "Positron vertex X;X, cm;mHz", 25, 0, 100); sprintf(str, "hY%d%c", j, (i) ? 'C' : 'S'); h[1][j][i] = new TH1D(str, "Positron vertex Y;Y, cm;mHz", 25, 0, 100); } printf("Histograms are created\n"); for (i=0; i<3; i++) { p[i]->Project(h[0][i][0], "PositronX[0]+2", cVeto && cSig && cY && "PositronX[0] >= 0" && cZ); p[i]->Project(h[0][i][1], "PositronX[0]+2", !cVeto && cSig && cY && "PositronX[0] >= 0" && cZ); printf("X%d\n", i); p[i]->Project(h[1][i][0], "PositronX[1]+2", cVeto && cSig && cX && "PositronX[1] >= 0" && cZ); p[i]->Project(h[1][i][1], "PositronX[1]+2", !cVeto && cSig && cX && "PositronX[1] >= 0" && cZ); printf("Y%d\n", i); } printf("Projections are done\n"); fRoot->cd(); for (i=0; i<2; i++) for (j=0; j<3; j++) for (k=0; k<2; k++) h[i][j][k]->Write(); fRoot->Close(); }
// ---------------------------------------------------------------- // ---------------------------------------------------------------- int wmain(int argc, wchar_t *argv[]) { // int main(int argc, char **argv) { int i = 0; int j = 0; int k = 0; bool aTestCti = false; SAP_UC *aChr; SAP_cout << TProperties::getInstance()->getVersion(true) << std::endl; #if 0 for (j = 0; j < 50000; j++) { SHERLOK_FCT_BEGIN(cR("package1"), cR("aClass1"), cR("aMethod1"), cR("()V")) SHERLOK_FCT_BEGIN(cR("package2"), cR("aClass2"), cR("aMethod2"), cR("()V")) aChr = (SAP_UC *)mallocU(1000); SHERLOK_FCT_END SHERLOK_FCT_END } SLEEP(100000); #endif // SAP_cout << TProperties::getInstance()->getVersion(true) << std::endl; return 0; }
void stereoCalibThread::stereoCalibRun() { imageL=new ImageOf<PixelRgb>; imageR=new ImageOf<PixelRgb>; Stamp TSLeft; Stamp TSRight; bool initL=false; bool initR=false; int count=1; Size boardSize, imageSize; boardSize.width=this->boardWidth; boardSize.height=this->boardHeight; while (!isStopping()) { ImageOf<PixelRgb> *tmpL = imagePortInLeft.read(false); ImageOf<PixelRgb> *tmpR = imagePortInRight.read(false); if(tmpL!=NULL) { *imageL=*tmpL; imagePortInLeft.getEnvelope(TSLeft); initL=true; } if(tmpR!=NULL) { *imageR=*tmpR; imagePortInRight.getEnvelope(TSRight); initR=true; } if(initL && initR && checkTS(TSLeft.getTime(),TSRight.getTime())){ bool foundL=false; bool foundR=false; mutex->wait(); if(startCalibration>0) { string pathImg=imageDir; preparePath(pathImg.c_str(), pathL,pathR,count); string iml(pathL); string imr(pathR); imgL= (IplImage*) imageL->getIplImage(); imgR= (IplImage*) imageR->getIplImage(); Mat Left(imgL); Mat Right(imgR); std::vector<Point2f> pointbufL; std::vector<Point2f> pointbufR; if(boardType == "CIRCLES_GRID") { foundL = findCirclesGridDefault(Left, boardSize, pointbufL, CALIB_CB_SYMMETRIC_GRID | CALIB_CB_CLUSTERING); foundR = findCirclesGridDefault(Right, boardSize, pointbufR, CALIB_CB_SYMMETRIC_GRID | CALIB_CB_CLUSTERING); } else if(boardType == "ASYMMETRIC_CIRCLES_GRID") { foundL = findCirclesGridDefault(Left, boardSize, pointbufL, CALIB_CB_ASYMMETRIC_GRID | CALIB_CB_CLUSTERING); foundR = findCirclesGridDefault(Right, boardSize, pointbufR, CALIB_CB_ASYMMETRIC_GRID | CALIB_CB_CLUSTERING); } else { foundL = findChessboardCorners( Left, boardSize, pointbufL, CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FAST_CHECK | CV_CALIB_CB_NORMALIZE_IMAGE); foundR = findChessboardCorners( Right, boardSize, pointbufR, CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FAST_CHECK | CV_CALIB_CB_NORMALIZE_IMAGE); } if(foundL && foundR) { cvCvtColor(imgL,imgL,CV_RGB2BGR); cvCvtColor(imgR,imgR, CV_RGB2BGR); saveStereoImage(pathImg.c_str(),imgL,imgR,count); imageListR.push_back(imr); imageListL.push_back(iml); imageListLR.push_back(iml); imageListLR.push_back(imr); Mat cL(pointbufL); Mat cR(pointbufR); drawChessboardCorners(Left, boardSize, cL, foundL); drawChessboardCorners(Right, boardSize, cR, foundR); count++; } if(count>numOfPairs) { fprintf(stdout," Running Left Camera Calibration... \n"); monoCalibration(imageListL,this->boardWidth,this->boardHeight,this->Kleft,this->DistL); fprintf(stdout," Running Right Camera Calibration... \n"); monoCalibration(imageListR,this->boardWidth,this->boardHeight,this->Kright,this->DistR); stereoCalibration(imageListLR, this->boardWidth,this->boardHeight,this->squareSize); fprintf(stdout," Saving Calibration Results... \n"); updateIntrinsics(imgL->width,imgL->height,Kright.at<double>(0,0),Kright.at<double>(1,1),Kright.at<double>(0,2),Kright.at<double>(1,2),DistR.at<double>(0,0),DistR.at<double>(0,1),DistR.at<double>(0,2),DistR.at<double>(0,3),"CAMERA_CALIBRATION_RIGHT"); updateIntrinsics(imgL->width,imgL->height,Kleft.at<double>(0,0),Kleft.at<double>(1,1),Kleft.at<double>(0,2),Kleft.at<double>(1,2),DistL.at<double>(0,0),DistL.at<double>(0,1),DistL.at<double>(0,2),DistL.at<double>(0,3),"CAMERA_CALIBRATION_LEFT"); Mat Rot=Mat::eye(3,3,CV_64FC1); Mat Tr=Mat::zeros(3,1,CV_64FC1); updateExtrinsics(this->R,this->T,"STEREO_DISPARITY"); fprintf(stdout, "Calibration Results Saved in %s \n", camCalibFile.c_str()); startCalibration=0; count=1; imageListR.clear(); imageListL.clear(); imageListLR.clear(); } } mutex->post(); ImageOf<PixelRgb>& outimL=outPortLeft.prepare(); outimL=*imageL; outPortLeft.write(); ImageOf<PixelRgb>& outimR=outPortRight.prepare(); outimR=*imageR; outPortRight.write(); if(foundL && foundR && startCalibration==1) Time::delay(2.0); initL=initR=false; cout.flush(); } } delete imageL; delete imageR; }
extern "C" SEXP LC_CoxPH(SEXP R_L, SEXP R_R, SEXP R_x, SEXP R_b, SEXP R_actInds, SEXP move_X, SEXP AugL, SEXP AugR, SEXP covariates, SEXP R_LMAXIND, SEXP R_RMININD, SEXP R_MAXUNCENSBETAIND, SEXP R_MAXUNCENSOBSIND, SEXP R_HASUNCENSORED){ bool c_move_x = LOGICAL(move_X)[0] == TRUE; int n = LENGTH(R_L); int k = LENGTH(R_x); vector<double> x(k); vector<double> b(k); for(int i = 0; i < k; i++){ x[i] = REAL(R_x)[i]; b[i] = REAL(R_b)[i]; } vector<int> cL(n); vector<int> cR(n); vector<double> cRepVec(n); bool leftDone,rightDone; double leftval, rightval; for(int i = 0; i < n; i++){ leftval = REAL(R_L)[i]; rightval = REAL(R_R)[i]; leftDone = false; rightDone = false; for(int j = 0; j < k; j++){ if(leftDone == false){ if(leftval == x[j]){ cL[i] = j; leftDone = true; } } if(rightDone == false){ if(rightval == x[j]){ cR[i] = j; rightDone = true; } } } if(rightDone == false || leftDone == false){ Rprintf("problem: data does not match x! Quiting\n"); return(R_NilValue); } } SEXP dims = getAttrib(covariates, R_DimSymbol); PROTECT(dims); int num_cov = INTEGER(dims)[1]; int cov_n = INTEGER(dims)[0]; UNPROTECT(1); if(cov_n != n){ Rprintf("Number of covariates does not match number of observations\n"); return(R_NilValue); } QuadProgPP::Matrix<double> Covars(cov_n,num_cov); for(int i = 0; i < cov_n; i++){ for(int j = 0; j < num_cov; j++) Covars[i][j] = REAL(covariates)[i + j*cov_n]; } int ak = LENGTH(R_actInds); vector<int> actInds(ak); for(int i = 0; i < ak; i++) actInds[i] = INTEGER(R_actInds)[i] - 1; double augl = REAL(AugL)[0]; double augr = REAL(AugR)[0]; int LMAXIND = INTEGER(R_LMAXIND)[0] - 1; int RMININD = INTEGER(R_RMININD)[0] - 1; double LLAGRMIN = REAL(AugL)[0]; double RLAGRMIN = REAL(AugR)[0]; int MAXUNCENSBETAIND = INTEGER(R_MAXUNCENSBETAIND)[0] - 1; int MAXUNCENSOBSIND = INTEGER(R_MAXUNCENSOBSIND)[0] - 1; bool HASUNCENSORED = LOGICAL(R_HASUNCENSORED)[0] == TRUE; LogConCenPH optObj(0, x, b, cL, cR, actInds, c_move_x, augl, augr, Covars, num_cov, LMAXIND, RMININD, LLAGRMIN, RLAGRMIN, MAXUNCENSBETAIND, MAXUNCENSOBSIND, HASUNCENSORED); optObj.updateNu(); optObj.updateRegress(); cout << "starting llk = " <<optObj.llk() << "\n"; optObj.VEMstep(); optObj.ICMstep(); cout << "after VEM and ICM, llk = " << optObj.llk() << "\n"; cout << "k = " << k << " actInds[0] = " << optObj.actIndex[0] << " actInds[getAK()-1] = " << optObj.actIndex[optObj.getAK()-1] << "\n"; // double old_llk = R_NegInf; // double new_llk = optObj.llk(); int inner_it = 0; int outer_it = 0; int max_inner_its = 2; int max_outer_its = 2; double outer_tol = pow(10.0, -10); double inner_tol = pow(10.0, -12); double outer_error = outer_tol + 1; double reg_error = outer_tol + 1; double inner_error; double inner_llk, outer_llk; int loopcount = 0; bool start_move_x = false; Rprintf("Reminder to Cliff: move_x turned off until updates\n"); while( (outer_it < max_outer_its) && (loopcount < 2)){ outer_it++; outer_llk = optObj.llk(); cout << "beginning loop llk = " << outer_llk << "\n"; optObj.VEMstep(); cout << "after VEMstep, llk = " << optObj.llk() << "\n"; inner_error = inner_tol + 1; reg_error = outer_tol + 1; inner_it = 0; while(inner_it < max_inner_its && inner_error > inner_tol){ inner_it++; // if(start_move_x && c_move_x) // optObj.updateXs(); if(reg_error > outer_tol){ reg_error = optObj.updateRegress(); cout << "after updateRegress step, llk = " << optObj.llk() << "\n"; } inner_llk = optObj.llk(); optObj.ICMstep(); cout << "after ICM step, llk = " << optObj.llk() << "\n"; inner_error = optObj.llk() - inner_llk; if(inner_error != inner_error) break; } cout << "k = " << k << " actInds[0] = " << optObj.actIndex[0] << " actInds[getAK()-1] = " << optObj.actIndex[optObj.getAK()-1] << "\n"; cout << "before recenterBeta, llk = " << optObj.llk() <<"\n"; optObj.recenterBeta(); cout << "after recenterBeta, llk = " << optObj.llk() << "\n"; outer_error = optObj.llk() - outer_llk; if(outer_error != outer_error){ Rprintf("Warning: undefined error. Algorithm terminated at invalid estimate. Please contact Clifford Anderson-Bergman with this dataset!\n"); break; } if(outer_error < 0.0001) start_move_x = true; if(outer_error < outer_tol){ loopcount++; } else loopcount = 0; } optObj.makePropDist(); ak = optObj.getAK(); SEXP output = PROTECT(allocVector(VECSXP, 5) ); SEXP regressP = PROTECT(allocVector(REALSXP, num_cov) ); for(int i = 0; i < num_cov; i++) REAL(regressP)[i] = optObj.cov_b[i]; SEXP x_out = PROTECT(allocVector(REALSXP, ak) ); SEXP b_out = PROTECT(allocVector(REALSXP, ak) ); SEXP llk_out = PROTECT(allocVector(REALSXP, 1) ); for(int i = 0; i < ak; i++){ REAL(x_out)[i] = optObj.x[optObj.actIndex[i]]; REAL(b_out)[i] = optObj.b[optObj.actIndex[i]]; } int totValues = num_cov + ak; SEXP Hess_out = PROTECT(allocMatrix(REALSXP, totValues, totValues)); for(int i = 0; i < totValues; i++){ for(int j = 0; j <= i; j++){ REAL(Hess_out)[i + totValues * j] = optObj.partialDerCovOrBase(i,j); REAL(Hess_out)[j + totValues * i] = REAL(Hess_out)[i + totValues* j]; } } REAL(llk_out)[0] = optObj.llk(); SET_VECTOR_ELT(output, 0, x_out); SET_VECTOR_ELT(output, 1, b_out); SET_VECTOR_ELT(output, 2, llk_out); SET_VECTOR_ELT(output, 3, regressP); SET_VECTOR_ELT(output, 4, Hess_out); UNPROTECT(6); return(output); }
void many_plots2(int first = 5808, int last = 11688, int mask = 0x801E) { TH1D *h[12][2]; int i, j; char str[64]; TCanvas *cv[2]; TPaveStats *st; float y, dy; gROOT->SetStyle("Plain"); gStyle->SetOptStat(1000000); gStyle->SetOptFit(); TFile *fRoot = new TFile("many_plots.root", "RECREATE"); HPainter *p = new HPainter(mask, first, last); p->SetFile(fRoot); if (!p->IsOpen()) { printf("Something wrong with data files.\n"); return; } TCut cVeto("gtFromVeto > 60"); TCut cIso("(gtFromPrevious > 45 && gtToNext > 80 && EventsBetween == 0) || (gtFromPrevious == gtFromVeto)"); TCut cX("PositronX[0] < 0 || (PositronX[0] > 2 && PositronX[0] < 94)"); TCut cY("PositronX[1] < 0 || (PositronX[1] > 2 && PositronX[1] < 94)"); TCut cZ("PositronX[2] > 3.5 && PositronX[2] < 95.5"); TCut cXYZ = cX && cY && cZ; TCut cR("Distance < 100 && DistanceZ > -40 && DistanceZ < 40"); TCut cT10("gtDiff > 1"); TCut cT20("gtDiff > 2"); TCut cT200("gtDiff < 20"); // strong cut TCut cGamma("AnnihilationEnergy < 1.5 && AnnihilationGammas < 9"); TCut cPe("PositronEnergy > 1"); TCut cXY("PositronX[0]>=0 && PositronX[1]>=0"); TCut cN4("NeutronEnergy > 4 && NeutronHits >= 5"); for (i=0; i<2; i++) { sprintf(str, "hR%d", i); h[0][i] = new TH1D(str, "Distance between positron and neutron;R, cm;mHz", 40, 0, 160); sprintf(str, "hRZ%d", i); h[1][i] = new TH1D(str, "Distance between positron and neutron, projection Z;R_{z}, cm;mHz", 100, -100, 100); sprintf(str, "hT%d", i); h[2][i] = new TH1D(str, "Time between positron and neutron;T, us;mHz", 50, 0, 50); sprintf(str, "hX%d", i); h[3][i] = new TH1D(str, "Positron vertex X;X, cm;mHz", 25, 0, 100); sprintf(str, "hY%d", i); h[4][i] = new TH1D(str, "Positron vertex Y;Y, cm;mHz", 25, 0, 100); sprintf(str, "hZ%d", i); h[5][i] = new TH1D(str, "Positron vertex Z;Z, cm;mHz", 100, 0, 100); sprintf(str, "hNE%d", i); h[6][i] = new TH1D(str, "Energy detected in neutron capture;E_{n}, MeV;mHz", 50, 0, 10); sprintf(str, "hNN%d", i); h[7][i] = new TH1D(str, "Number of hits in SiPM for neutron capture;N_{n};mHz", 20, 0, 20); sprintf(str, "hGE%d", i); h[8][i] = new TH1D(str, "Energy beyond positron cluster;E_{#gamma}, MeV;mHz", 15, 0, 3); sprintf(str, "hGN%d", i); h[9][i] = new TH1D(str, "Number of SiPM hits out of positron cluster;N_{#gamma};mHz", 10, 0, 10); sprintf(str, "hE%d", i); h[10][i] = new TH1D(str, "Positorn kinetic energy;E, MeV;mHz", 40, 0, 8); sprintf(str, "hEC%d", i); h[11][i] = new TH1D(str, "Positorn kinetic energy, strong background cuts;E, MeV;mHz", 40, 0, 8); } printf("Histograms are created\n"); p->Project(h[0][0], "Distance", cVeto && cIso && cT20 && cGamma && cPe && cXYZ); p->Project(h[0][1], "Distance", !cVeto && cIso && cT20 && cGamma && cPe && cXYZ); printf("Distance.\n"); p->Project(h[1][0], "DistanceZ", cVeto && cIso && cT20 && cGamma && cPe && cXYZ); p->Project(h[1][1], "DistanceZ", !cVeto && cIso && cT20 && cGamma && cPe && cXYZ); printf("DistanceZ.\n"); p->Project(h[2][0], "gtDiff", cVeto && cIso && cT10 && cGamma && cPe && cXYZ && cR); p->Project(h[2][1], "gtDiff", !cVeto && cIso && cT10 && cGamma && cPe && cXYZ && cR); printf("gtDiff.\n"); p->Project(h[3][0], "PositronX[0]+2", cVeto && cIso && cT20 && cGamma && cPe && cY && cZ && cR && "PositronX[0] >= 0"); p->Project(h[3][1], "PositronX[0]+2", !cVeto && cIso && cT20 && cGamma && cPe && cY && cZ && cR && "PositronX[0] >= 0"); printf("X.\n"); p->Project(h[4][0], "PositronX[1]+2", cVeto && cIso && cT20 && cGamma && cPe && cX && cZ && cR && "PositronX[1] >= 0"); p->Project(h[4][1], "PositronX[1]+2", !cVeto && cIso && cT20 && cGamma && cPe && cX && cZ && cR && "PositronX[1] >= 0"); printf("Y.\n"); p->Project(h[5][0], "PositronX[2]+0.5", cVeto && cIso && cT20 && cGamma && cPe && cX && cY && cR); p->Project(h[5][1], "PositronX[2]+0.5", !cVeto && cIso && cT20 && cGamma && cPe && cX && cY && cR); printf("Z.\n"); p->Project(h[6][0], "NeutronEnergy", cVeto && cIso && cT20 && cGamma && cPe && cY && cZ && cR); p->Project(h[6][1], "NeutronEnergy", !cVeto && cIso && cT20 && cGamma && cPe && cY && cZ && cR); printf("NE.\n"); p->Project(h[7][0], "NeutronHits", cVeto && cIso && cT20 && cGamma && cPe && cXYZ && cR); p->Project(h[7][1], "NeutronHits", !cVeto && cIso && cT20 && cGamma && cPe && cXYZ && cR); printf("NN.\n"); p->Project(h[8][0], "AnnihilationEnergy", cVeto && cIso && cT20 && cPe && cXYZ && cR); p->Project(h[8][1], "AnnihilationEnergy", !cVeto && cIso && cT20 && cPe && cXYZ && cR); printf("AE.\n"); p->Project(h[9][0], "AnnihilationGammas", cVeto && cIso && cT20 && cPe && cXYZ && cR); p->Project(h[9][1], "AnnihilationGammas", !cVeto && cIso && cT20 && cPe && cXYZ && cR); printf("AG.\n"); p->Project(h[10][0], "PositronEnergy", cVeto && cIso && cT20 && cGamma && cPe && cXYZ && cR); p->Project(h[10][1], "PositronEnergy", !cVeto && cIso && cT20 && cGamma && cPe && cXYZ && cR); p->Project(h[11][0], "PositronEnergy", cVeto && cIso && cT20 && cGamma && cPe && cXYZ && cR && cN4 && cT200); p->Project(h[11][1], "PositronEnergy", !cVeto && cIso && cT20 && cGamma && cPe && cXYZ && cR && cN4 && cT200); printf("Projections are done\n"); for (i=0; i<12; i++) { for (j=0; j<2; j++) h[i][j]->SetLineWidth(4); h[i][0]->SetLineColor(kGreen); h[i][1]->SetLineColor(kRed); h[i][0]->SetMinimum(0); h[i][1]->SetMinimum(0); } // h[1][0]->Fit("gaus", "0"); // h[1][1]->Fit("gaus", "0"); // TF1 *fdec = new TF1("FDEC", "[0]*(exp(-x/[1]) - exp(-x/[2]))", 3); // fdec->SetParNames("Const", "t_{CAPTURE}", "t_{THERM}"); // fdec->SetParameters(h[2][0]->Integral()/4, 15, 5); // h[2][0]->Fit("FDEC", "0", "", 2, 50); for (i=0; i<2; i++) { sprintf(str, "CV%d", i); cv[i] = new TCanvas(str, "Plots", 1800, 1200); cv[i]->Divide(3, 2); for (j=0; j<6; j++) { cv[i]->cd(j+1); h[6*i+j][0]->Draw(); h[6*i+j][1]->Draw("sames"); gPad->Update(); if (i == 0 && j == 1) { st = (TPaveStats *) h[6*i+j][0]->FindObject("stats"); st->SetOptStat(1100); st->SetLineColor(kGreen); st->SetTextColor(kGreen); y = st->GetY1NDC(); dy = st->GetY2NDC() - y; st->SetX1NDC(0.72); st = (TPaveStats *) h[6*i+j][1]->FindObject("stats"); st->SetOptStat(1100); st->SetLineColor(kRed); st->SetTextColor(kRed); st->SetX1NDC(0.72); st->SetY2NDC(y); st->SetY1NDC(y - dy); } else { st = (TPaveStats *) h[6*i+j][0]->FindObject("stats"); st->SetLineColor(kGreen); st->SetTextColor(kGreen); y = st->GetY1NDC(); dy = st->GetY2NDC() - y; st->SetX1NDC(0.72); st->SetY1NDC(y + dy/2); st = (TPaveStats *) h[6*i+j][1]->FindObject("stats"); st->SetLineColor(kRed); st->SetTextColor(kRed); st->SetX1NDC(0.72); st->SetY2NDC(y + dy/2); } if (h[6*i+j][0]->GetMaximum() > h[6*i+j][1]->GetMaximum()) { h[6*i+j][0]->Draw(); h[6*i+j][1]->Draw("sames"); } else { h[6*i+j][1]->Draw(); h[6*i+j][0]->Draw("sames"); } gPad->Update(); } cv[i]->Update(); } fRoot->cd(); for (i=0; i<12; i++) for (j=0; j<2; j++) h[i][j]->Write(); fRoot->Close(); }
/// <summary> /// Calculates for each image patch the focus measure value. Result is a vector of Patches (see class Patch). /// If the image is binary, the relative foreground (foreground pixel / patchSize) and the weight is stored for each Patch. /// </summary> /// <param name="fm">The specified focuse measure method fm (e.g. Brenner).</param> /// <param name="fmImg">The image fmImg to calculate the focus measure on. If empty, the src image is taken.</param> /// <param name="binary">if set to <c>true</c> [binary] the input image is binary, specifying the foreground image. The foreground area and the weight is saved to the image patch</param> /// <returns>True if the focus measure could be computed, false otherwise.</returns> bool FocusEstimation::compute(FocusMeasure fm, cv::Mat fmImg, bool binary) { cv::Mat fImg = fmImg; if (fImg.empty()) fImg = mSrcImg; if (fImg.empty()) return false; if (fmImg.channels() != 1 || fImg.depth() != CV_32F) return false; BasicFM fmClass; double f; mFmPatches.clear(); for (int row = 0; row < fImg.rows; row += (mWindowSize+mSplitSize)) { for (int col = 0; col < fImg.cols; col += (mWindowSize+mSplitSize)) { cv::Range rR(row, cv::min(row + mWindowSize, fImg.rows)); cv::Range cR(col, cv::min(col + mWindowSize, fImg.cols)); cv::Mat tile = fImg(rR, cR); fmClass.setImg(tile); switch (fm) { case dsc::FocusEstimation::BREN: f = fmClass.computeBREN(); break; case dsc::FocusEstimation::GLVA: f = fmClass.computeGLVA(); break; case dsc::FocusEstimation::GLVN: f = fmClass.computeGLVN(); break; case dsc::FocusEstimation::GLLV: f = fmClass.computeGLLV(); break; case dsc::FocusEstimation::GRAT: f = fmClass.computeGRAT(); break; case dsc::FocusEstimation::GRAS: f = fmClass.computeGRAS(); break; case dsc::FocusEstimation::LAPE: f = fmClass.computeLAPE(); break; case dsc::FocusEstimation::LAPV: f = fmClass.computeLAPV(); break; case dsc::FocusEstimation::ROGR: f = fmClass.computeROGR(); break; default: f = -1; break; } Patch r(cv::Point(col, row), mWindowSize, mWindowSize, f); if (binary) { cv::Scalar relArea = cv::sum(tile); r.setArea(relArea[0]); relArea[0] = relArea[0] / (double)(mWindowSize * mWindowSize); //area completely written with text ~ 0.1 //normalize to 1 relArea[0] *= 10.0; r.setWeight(relArea[0]); //weight with sigmoid function //-6: shift sigmoid to the right //*10: scale normalized Area //double a = 10.0; //double b = -6.0; //double weight = 1.0 / (1 + std::exp(-(relArea[0] * a + b))); //r.setWeight(weight); } mFmPatches.push_back(r); } } return true; }