QVis RegionService::createHistogram(const MatSet& matSet, QLP region) { QVis histograms(9); for(int i=0; i<9; i++) { int BITE = 256; QVi channelHistogram(matSet.bgr().elemSize1()*BITE, 0); histograms[i] = channelHistogram; } for(Point point : region) { histograms.value(0)[B(matSet.bgr(), point.x, point.y)]++; histograms.value(1)[G(matSet.bgr(), point.x, point.y)]++; histograms.value(2)[R(matSet.bgr(), point.x, point.y)]++; histograms.value(3)[B(matSet.hsv(), point.x, point.y)]++; histograms.value(4)[G(matSet.hsv(), point.x, point.y)]++; histograms.value(5)[R(matSet.hsv(), point.x, point.y)]++; histograms.value(6)[B(matSet.ycrcb(), point.x, point.y)]++; histograms.value(7)[G(matSet.ycrcb(), point.x, point.y)]++; histograms.value(8)[R(matSet.ycrcb(), point.x, point.y)]++; } return histograms; }
int main( int argc, char* argv[] ) { if( argc != 4) { std::cerr << "Usage: " << argv[0] << " <InputImage>" << std::endl; return EXIT_FAILURE; } cv::Mat image = cv::imread( argv[1] ); if(!image.data) { return EXIT_FAILURE; } cv::Mat image_gray = cv::imread( argv[1],0 ); if(!image_gray.data) { return EXIT_FAILURE; } cv::Mat mask = cv::imread( argv[2],0 ); if(!mask.data) { return EXIT_FAILURE; } std::vector<cv::Mat> channels; cv::cvtColor( image, image, CV_BGR2YCrCb ); cv::split( image, channels ); //cv::Mat hist=histogram(channels[0],cv::Mat()); // cv::Mat histmask=histogram(channels[0],mask); cv::Mat hist=channelHistogram(image,cv::Mat(),16,240,235); cv::Mat histmask=channelHistogram(image,mask,16,240,235); cv::namedWindow( "histogram", CV_WINDOW_AUTOSIZE ); cv::imshow( "histogram", hist ); cv::namedWindow( "mask histogram", CV_WINDOW_AUTOSIZE ); cv::imshow( "mask histogram", histmask ); cv::waitKey(0); cv::imwrite(argv[3],histmask); return 0; }
// inputs data file and event in file to display (default is to integrate all) void dqmDisplay(TString fdat, int ndisplay = -1){ gStyle->SetOptStat(0); TFile *f = new TFile(fdat); if (f->IsZombie()){ cout << "Cannot open file: " << fdat << endl; return; } TBEvent *event = new TBEvent(); TTree *t1041 = (TTree*)f->Get("t1041"); TBranch *bevent = t1041->GetBranch("tbevent"); bevent->SetAddress(&event); Bool_t singleEvent = (ndisplay >= 0); Mapper * mapper = Mapper::Instance(); TH2F * hModU = (TH2F*)moduleHistogram(true, "RO", threshold, 2500, singleEvent); TH2F * hModD = (TH2F*)moduleHistogram(false, "RO", threshold, 2500, singleEvent); TH2F * hChanU = (TH2F*)channelHistogram(true, "RO", threshold, 2500, singleEvent); TH2F * hChanD = (TH2F*)channelHistogram(false, "RO", threshold, 2500, singleEvent); TH2F * hModU_time = (TH2F*)moduleHistogram(true, "Timing", 0, -1, singleEvent); TH2F * hModD_time = (TH2F*)moduleHistogram(false, "Timing", 0, -1, singleEvent); TH2F * hChanU_time = (TH2F*)channelHistogram(true, "Timing", 0, -1, singleEvent); TH2F * hChanD_time = (TH2F*)channelHistogram(false, "Timing", 0, -1, singleEvent); int nPerMod = t1041->GetEntries() / 16; int nPerFiber = t1041->GetEntries() / 64; TH2F * hModU_nhits = (TH2F*)moduleHistogram(true, "nHits", nPerMod * .85, nPerMod * 1.1, singleEvent); TH2F * hModD_nhits = (TH2F*)moduleHistogram(false, "nHits", nPerMod * .85, nPerMod * 1.1, singleEvent); TH2F * hChanU_nhits = (TH2F*)channelHistogram(true, "nHits", nPerFiber * .25, nPerFiber * 1.1, singleEvent); TH2F * hChanD_nhits = (TH2F*)channelHistogram(false, "nHits", nPerFiber * .25, nPerFiber * 1.1, singleEvent); TH2F * hModU_ntriggers = (TH2F*)moduleHistogram(true, "nTriggers", nPerMod * .95, nPerMod * 1.3, singleEvent); TH2F * hModD_ntriggers = (TH2F*)moduleHistogram(false, "nTriggers", nPerMod * .95, nPerMod * 1.3, singleEvent); TH2F * hChanU_ntriggers = (TH2F*)channelHistogram(true, "nTriggers", nPerFiber * .95, nPerFiber * 1.3, singleEvent); TH2F * hChanD_ntriggers = (TH2F*)channelHistogram(false, "nTriggers", nPerFiber * .95, nPerFiber * 1.3, singleEvent); Int_t start = 0; Int_t end = t1041->GetEntries(); if (singleEvent) { start = ndisplay; end = ndisplay + 1; } for (Int_t i=start; i < end; i++) { t1041->GetEntry(i); for (Int_t j = 0; j < event->NPadeChan(); j++){ PadeChannel pch = event->GetPadeChan(j); UShort_t max = pch.GetMax(); Int_t maxTime = pch.GetPeak(); if (max>MAXADC) continue; // skip channels with bad adc readings (should be RARE) int channelID=pch.GetChannelID(); // boardID*100+channelNum in PADE int moduleID,fiberID; mapper->ChannelID2ModuleFiber(channelID,moduleID,fiberID); // get module and fiber IDs float xm,ym,xf,yf; mapper->ModuleXY(moduleID,xm,ym); mapper->FiberXY(fiberID, xf, yf); if(moduleID < 0) { hModU_ntriggers->Fill(xm, ym); hChanU_ntriggers->Fill(xf, yf); } else { hModD_ntriggers->Fill(xm, ym); hChanD_ntriggers->Fill(xf, yf); } if(max <= threshold) continue; if (moduleID < 0) { hModU->Fill(xm, ym, max); hModU_time->Fill(xm, ym, maxTime); hModU_nhits->Fill(xm, ym); hChanU->Fill(xf, yf, max); hChanU_time->Fill(xf, yf, maxTime); hChanU_nhits->Fill(xf, yf); } else { hModD->Fill(xm, ym, max); hModD_time->Fill(xm, ym, maxTime); hModD_nhits->Fill(xm, ym); hChanD->Fill(xf, yf, max); hChanD_time->Fill(xf, yf, maxTime); hChanD_nhits->Fill(xf, yf); } } } hModD->Divide(hModD_nhits); hModU->Divide(hModU_nhits); hChanD->Divide(hChanD_nhits); hChanU->Divide(hChanU_nhits); hModD_time->Divide(hModD_nhits); hModU_time->Divide(hModU_nhits); hChanD_time->Divide(hChanD_nhits); hChanU_time->Divide(hChanU_nhits); drawCalorimeterPlot("AvgPeakHeight", hModU, hModD, hChanU, hChanD, t1041->GetEntries(), ndisplay); drawCalorimeterPlot("AvgPeakTiming", hModU_time, hModD_time, hChanU_time, hChanD_time, t1041->GetEntries(), ndisplay); drawCalorimeterPlot("NHits", hModU_nhits, hModD_nhits, hChanU_nhits, hChanD_nhits, t1041->GetEntries(), ndisplay); drawCalorimeterPlot("NTriggers", hModU_ntriggers, hModD_ntriggers, hChanU_ntriggers, hChanD_ntriggers, t1041->GetEntries(), ndisplay); }