void opticalFlow::occMatpEst( Mat_<Vec2f> &flow12, Mat_<Vec2f> &flow21, Mat_<uchar>&occMap) { int iy, ix; const float FLOW_PIXEL_THRESH = 2; occMap.setTo(255); for (iy=0; iy<height1; ++iy) { for (ix=0; ix<width1; ++ix) { Vec2f fFlow = flow12[iy][ix]; int ny, nx; ny = floor(iy+fFlow[1]+0.5); nx = floor(ix+fFlow[0]+0.5); if (ny>=0 && ny<height1 && nx>=0 && nx<width1) { cv::Vec2f bFlow = flow21[ny][nx]; if (fabs(bFlow[1]+ny-iy)<FLOW_PIXEL_THRESH && fabs(bFlow[0]+nx-ix)<FLOW_PIXEL_THRESH) { continue; } } occMap[iy][ix] = 0; } } Mat bw = occMap; Mat labelImage(occMap.size(), CV_32S); int nLabels = connectedComponents(bw, labelImage, 8); occMap[iy][ix] = 0; vector<int> hist(nLabels,0); for (iy=0; iy<height1; ++iy) for (ix=0; ix<width1; ++ix) hist[labelImage.at<int>(iy,ix)]++; vector<int> rmv_list; rmv_list.reserve(20); for (int i=0;i<nLabels;++i){ if (hist[i]<50) rmv_list.push_back(i); } for (iy=0; iy<height1; ++iy) { for (ix=0; ix<width1; ++ix) { for (int r=0; r<rmv_list.size(); ++r) if(labelImage.at<int>(iy,ix) == rmv_list[r]) occMap[iy][ix] = 0; } } }
//! Compute automatic stretch for a portion of the cube void ChipViewport::computeStretch(Stretch &stretch, bool force) { if (p_stretchLocked && !force) { stretch = *p_stretch; } else { Statistics stats; for (int line = 1; line < p_chip->Lines(); line++) { for (int samp = 1; samp < p_chip->Samples(); samp++) { double value = p_chip->GetValue(samp, line); stats.AddData(&value, 1); } } Histogram hist(stats.BestMinimum(), stats.BestMaximum()); for (int line = 1; line <= p_chip->Lines(); line++) { for (int samp = 1; samp <= p_chip->Samples(); samp++) { double value = p_chip->GetValue(samp, line); hist.AddData(&value, 1); } } stretch.ClearPairs(); if (hist.Percent(0.5) != hist.Percent(99.5)) { stretch.AddPair(hist.Percent(0.5), 0.0); stretch.AddPair(hist.Percent(99.5), 255.0); } else { stretch.AddPair(-DBL_MAX, 0.0); stretch.AddPair(DBL_MAX, 255.0); } *p_stretch = stretch; } }
::libmaus::util::Histogram::unique_ptr_type libmaus::util::Utf8String::getHistogram(::libmaus::autoarray::AutoArray<uint8_t> const & A) { #if defined(_OPENMP) uint64_t const numthreads = omp_get_max_threads(); #else uint64_t const numthreads = 1; #endif ::libmaus::autoarray::AutoArray<uint64_t> const partstarts = computePartStarts(A,numthreads); uint64_t const numparts = partstarts.size()-1; ::libmaus::util::Histogram::unique_ptr_type hist(new ::libmaus::util::Histogram); ::libmaus::parallel::OMPLock lock; #if defined(_OPENMP) #pragma omp parallel for #endif for ( int64_t t = 0; t < static_cast<int64_t>(numparts); ++t ) { ::libmaus::util::Histogram::unique_ptr_type lhist(new ::libmaus::util::Histogram); uint64_t codelen = 0; uint64_t const tcodelen = partstarts[t+1]-partstarts[t]; ::libmaus::util::GetObject<uint8_t const *> G(A.begin()+partstarts[t]); while ( codelen != tcodelen ) (*lhist)(::libmaus::util::UTF8::decodeUTF8(G,codelen)); lock.lock(); hist->merge(*lhist); lock.unlock(); } return UNIQUE_PTR_MOVE(hist); }
static void print_ahstats(const struct ahstat *ahstat) { #define p32(f, m) if (ahstat->f || sflag <= 1) \ printf("\t%u" m, (unsigned int)ahstat->f, plural(ahstat->f)) #define p64(f, m) if (ahstat->f || sflag <= 1) \ printf("\t%ju" m, (uintmax_t)ahstat->f, plural(ahstat->f)) #define hist(f, n, t) \ ipsec_hist_new((f), sizeof(f)/sizeof(f[0]), (n), (t)); p32(ahs_hdrops, " packet%s shorter than header shows\n"); p32(ahs_nopf, " packet%s dropped; protocol family not supported\n"); p32(ahs_notdb, " packet%s dropped; no TDB\n"); p32(ahs_badkcr, " packet%s dropped; bad KCR\n"); p32(ahs_qfull, " packet%s dropped; queue full\n"); p32(ahs_noxform, " packet%s dropped; no transform\n"); p32(ahs_wrap, " replay counter wrap%s\n"); p32(ahs_badauth, " packet%s dropped; bad authentication detected\n"); p32(ahs_badauthl, " packet%s dropped; bad authentication length\n"); p32(ahs_replay, " possible replay packet%s detected\n"); p32(ahs_input, " packet%s in\n"); p32(ahs_output, " packet%s out\n"); p32(ahs_invalid, " packet%s dropped; invalid TDB\n"); p64(ahs_ibytes, " byte%s in\n"); p64(ahs_obytes, " byte%s out\n"); p32(ahs_toobig, " packet%s dropped; larger than IP_MAXPACKET\n"); p32(ahs_pdrops, " packet%s blocked due to policy\n"); p32(ahs_crypto, " crypto processing failure%s\n"); p32(ahs_tunnel, " tunnel sanity check failure%s\n"); hist(ahstat->ahs_hist, ipsec_ahnames, "AH output"); #undef p32 #undef p64 #undef hist }
template<class Storage, class SrcType, class ThreshType, class DstType> static int foaCvBackProject(Storage, SrcType, ThreshType, DstType) { const S1 = 4; const S2 = 4; const S3 = 4; CvSize roi = {100, 100}; int step = roi.width * sizeof( SrcType ); SrcType* src[3]; src[0] = new SrcType[roi.width * roi.height]; src[1] = new SrcType[roi.width * roi.height]; src[2] = new SrcType[roi.width * roi.height]; DstType* measure = new DstType[roi.width * roi.height]; ThreshType _thresh[3][5] = {{1, 2, 3, 4, 5}, {2, 3, 4, 5, 6}, {5, 6, 7, 9, 10}}; ThreshType* thresh[3] = { _thresh[0], _thresh[1], _thresh[2] }; int Errors = 0; for( int i = 0; i < roi.width * roi.height; i++ ) src[0][i] = src[1][i] = src[2][i] = 0; for( i = 0; i < roi.width; i++ ) for( int j = 0; j < 3; j++ ) src[j][roi.width + i] = (SrcType)thresh[j][i%5]; CVHistogram<Storage> hist( S1, S2, S3 ); CvCalculateC1( hist, src, roi, step, thresh ); CvBackProject<CVHistogram<Storage>, SrcType, ThreshType, DstType> ( hist, src, roi, step, thresh, measure, roi.width * sizeof(DstType), 0 ); for( i = 0; i < roi.width; i++ ) if( measure[roi.width + i] != roi.width / 5 * (1 + (i%5 == 0) + (i%5 == 1))) { trsWrite( ATS_CON | ATS_LST, "Wrong destination value\n" ); Errors++; break; } for( int y = 0; y < roi.height; y++ ) for( int x = 0; x < roi.width; x++ ) if( y != 1 && measure[roi.width * y + x] != 0 ) { trsWrite( ATS_CON | ATS_LST, "Wrong destination value (non zero)\n" ); Errors++; goto _exit; } _exit:; delete src[0]; delete src[1]; delete src[2]; delete measure; return Errors == 0 ? TRS_OK : trsResult( TRS_FAIL, "Fixed %d errors", Errors ); }
void Detector::writeHistogram(){ cv::Mat hist(scale + 1, scale + 1, CV_32FC1); cv::Mat histN; hist.copyTo(histN); // cv::cvtColor(image, newImage, CV_Lab2BGR); //matrice à cv Mat for (int row = 0; row < scale; row++){ for (int col = 0; col < scale; col++){ hist.at<double>(row, col) = 1.0*histoS[row][col]/totalPixelSkinBase; } } for (int row = 0; row < scale; row++){ for (int col = 0; col < scale; col++){ histN.at<double>(row, col) = 1.0*histoNS[row][col]/totalPixelNonSkinBase; } } char histName[64]; char histNName[64]; sprintf(histName, "histogram%d.jpg", scale); sprintf(histNName, "histogramNonSkin%d.jpg", scale); // cv::normalize(hist, hist, 1, cv::NORM_MINMAX); cv::imwrite( histName, hist); cv::imwrite( histNName, histN); }
std::pair<float, float> calculate_mapping_function(std::list<TexturePatch::ConstPtr> const & texture_patches) { float min = std::numeric_limits<float>::max(); float max = std::numeric_limits<float>::lowest(); for (TexturePatch::ConstPtr texture_patch : texture_patches) { mve::FloatImage::ConstPtr image = texture_patch->get_image(); mve::ByteImage::ConstPtr validity_mask = texture_patch->get_validity_mask(); for (int i = 0; i < image->get_value_amount(); ++i) { if (validity_mask->at(i / 3) == 0) continue; min = std::min(min, image->at(i)); max = std::max(max, image->at(i)); } } Histogram hist(min, max, 10000); for (TexturePatch::ConstPtr texture_patch : texture_patches) { mve::FloatImage::ConstPtr image = texture_patch->get_image(); mve::ByteImage::ConstPtr validity_mask = texture_patch->get_validity_mask(); for (int i = 0; i < image->get_value_amount(); ++i) { if (validity_mask->at(i / 3) == 0) continue; hist.add_value(image->at(i)); } } min = hist.get_approx_percentile(0.005f); max = hist.get_approx_percentile(0.995f); return std::pair<float, float>(min, max); }
int maximalRectangle(vector<vector<char> > &matrix) { int n = matrix.size(); if(n<1) return 0; int m = matrix[0].size(); if(m<1) return 0; int ans = 0; vector<int> hist(m, 0); for(int i=0; i<n; i++){ for(int j=0; j<m; j++){ if(matrix[i][j]=='1') hist[j]++; else hist[j] = 0; } ans = max(ans, rectInHist(hist)); } return ans; }
void HistogramManager::createBJetSummedHistograms3D(DataType::value type) { for (unsigned short jetbinSum = 0; jetbinSum < BJetBinSummed::NUMBER_OF_SUMMED_BJET_BINS; ++jetbinSum) { for (unordered_map<std::string, TH3Array>::iterator iter = collection3D.begin(); iter != collection3D.end(); ++iter) { string collectionName = iter->first; TH3CollectionRef coll = iter->second[type]; unordered_map<std::string, TH3Ptr> histMap = coll->getAllHistograms(); for (unordered_map<std::string, TH3Ptr>::const_iterator histIter = histMap.begin(); histIter != histMap.end(); ++histIter) { string name = histIter->first; //check if it is a Bjet-binned histogram if (!boost::algorithm::ends_with(name, BJetBin::names[jetbinSum])) continue; string tmp_name(name); boost::algorithm::replace_last(tmp_name, BJetBin::names[jetbinSum], BJetBinSummed::names[jetbinSum]); TH3Ptr hist((TH3*) histIter->second->Clone(tmp_name.c_str())); string title(hist->GetTitle()); boost::algorithm::replace_last(title, BJetBin::names[jetbinSum], BJetBinSummed::names[jetbinSum]); hist->SetTitle(title.c_str()); for (unsigned short jetbin = jetbinSum + 1; jetbin < BJetBin::NUMBER_OF_BJET_BINS; ++jetbin) { string histName = name; //replace the suffix of the current <base> histogram with the value in the loop. boost::algorithm::replace_last(histName, BJetBin::names[jetbinSum], BJetBin::names[jetbin]); hist->Add(collection3D[collectionName][type]->get(histName).get()); } collection3D[collectionName][type]->add(tmp_name, hist); } } } }
void Control::drawHistogram(std::string image_name) { cv::Mat image = cv::imread(image_name); cv::Mat hist(200, 256, CV_8UC1, cv::Scalar(0)); Channel channel(image); channel.drawHistogram(hist, 255); cv::imwrite("hist.png", hist); }
int main(int argc, char *argv[]) { int NUM_RUNS = atoi(argv[1]); int TEST_RUNS = atoi(argv[2]); hist(NUM_RUNS,TEST_RUNS); }
void MainWindow::setImages() { Histogram hist(image); histogram = hist.getImage(); viewer->setImage(chargeImage()); histoViewer->setImage(chargeHisto()); }
HistPtr GetHist(const std::string& hist_name) const { HistPtr hist(dynamic_cast<Hist*>(file->Get(hist_name.c_str()))); if(!hist) throw exception("Can't read histogram '%1%' from model file '%2%'.") % hist_name % file->GetName(); return hist; }
void DrawPlot::scale(std::vector<TH1*>& v_hist, const double factor)const{ for(std::vector<TH1*>::const_iterator i_hist = v_hist.begin(); i_hist != v_hist.end(); ++i_hist){ TH1* hist(*i_hist); const double integral(hist->Integral(0,hist->GetNbinsX()+1)); if(integral>0.)hist->Scale(factor/integral); hist->SetYTitle(TString(hist->GetYaxis()->GetTitle()) + " (scaled)"); } }
void makePlots(std::string fname="runWithGun_Fix.root", std::string text="Fixed Depth Calculation", std::string prefix="Fix", bool save=false) { std::string name[4] = {"ECLL_EB", "ECLL_EBref", "ECLL_EE", "ECLL_EERef"}; double xrnglo[4] = {1200.0,1200.0,3100.0,3100.0}; double xrnghi[4] = {1600.0,1600.0,3600.0,3600.0}; std::string xtitl[4] = {"R_{Cyl} (mm)","R_{Cyl} (mm)","|z| (mm)", "|z| (mm)"}; std::string ytitl[4] = {"# X_{0} (*100)", "# X_{0} (*100)", "# X_{0} (*100)", "# X_{0} (*100)"}; std::string title[4] = {"EB (Normal)", "EB (Reflected)", "EE (Normal)", "EE (Reflected)"}; gStyle->SetCanvasBorderMode(0); gStyle->SetCanvasColor(kWhite); gStyle->SetPadColor(kWhite); gStyle->SetFillColor(kWhite); gStyle->SetOptStat(11110); TFile *file = new TFile(fname.c_str()); if (file) { char namep[100]; for (int k=0; k<4; ++k) { TH2D* hist(0); for (int i=0; i<4; ++i) { if (i == 0) sprintf (namep, "%s", name[k].c_str()); else sprintf (namep, "%s;%d", name[k].c_str(),i); hist = (TH2D*)file->FindObjectAny(name[k].c_str()); std::cout << namep << " read out at " << hist << std::endl; if (hist != 0) { std::cout << "Entries " << hist->GetEntries() << std::endl; if (hist->GetEntries() > 0) break; } } if (hist != 0) { sprintf (namep,"%s%s",name[k].c_str(),prefix.c_str()); TCanvas *pad = new TCanvas(namep,namep,500,500); pad->SetRightMargin(0.10); pad->SetTopMargin(0.10); hist->GetYaxis()->SetTitle(ytitl[k].c_str()); hist->GetXaxis()->SetTitle(xtitl[k].c_str()); hist->SetTitle(title[k].c_str()); hist->GetXaxis()->SetRangeUser(xrnglo[k],xrnghi[k]); hist->GetYaxis()->SetTitleOffset(1.4); hist->Draw(); pad->Update(); TPaveStats* st1 = (TPaveStats*)hist->GetListOfFunctions()->FindObject("stats"); if (st1 != NULL) { st1->SetY1NDC(0.70); st1->SetY2NDC(0.90); st1->SetX1NDC(0.65); st1->SetX2NDC(0.90); } TPaveText *txt1 = new TPaveText(0.50,0.60,0.90,0.65,"blNDC"); txt1->SetFillColor(0); txt1->AddText(text.c_str()); pad->Update(); if (save) { sprintf (namep, "c_%s%s.gif",name[k].c_str(),prefix.c_str()); pad->Print(namep); } } } } }
void MainWindow::equalization() { Histogram hist(image); histogram = hist.getImage(); image = histogramEqualization(image,hist); setImages(); }
void MainWindow::isodataSlot() { Histogram hist(image); histogram = hist.getImage(); image = isodata(image,hist,0,image.getLevel()+1); setImages(); }
::libmaus2::util::Histogram::unique_ptr_type libmaus2::util::OctetString::getHistogram() const { ::libmaus2::util::Histogram::unique_ptr_type hist(new ::libmaus2::util::Histogram); for ( uint64_t i = 0; i < A.size(); ++i ) (*hist)(A[i]); return UNIQUE_PTR_MOVE(hist); }
void MSLib_Material_Driver( State_t* state, const int* ndx, const int len, Domain_t* domain ) { MS_Matmodel* msModel = 0L; HistVarSet<real8> hist(msModel); HistVarSet<real8> hist_updt(msModel); HistVarSet<real8*> hist_list(msModel); HistVarSet<bool> log_flags(msModel); }
void LLGAnalysis::makeHist( string nametitle, int nbins, double xmin, double xmax, string xtitle, string ytitle, string drawOption, double xAxisOffset, double yAxisOffset ) { TH1D hist(nametitle.c_str(), nametitle.c_str(), nbins, xmin, xmax ); hist.GetXaxis()->SetTitle( xtitle.c_str() ); hist.GetYaxis()->SetTitle( ytitle.c_str() ); hist.GetYaxis()->SetTitleOffset( yAxisOffset ); hist.GetXaxis()->SetTitleOffset( xAxisOffset ); _histograms1D.insert( pair<string, TH1D>( nametitle, hist ) ); _histograms1DDrawOptions.insert( pair<string,string>( nametitle, drawOption ) ); }
static double iteration(int m0, int m1, int m2, int n0, int n1, int n2, double Alpha[], double Beta[], MAPTYPE *vol, double B0[], double B1[], double B2[], double f[], double mx, int nh, double h[], int *psh) { int j2, j1, j0, i2, i1, i0; double *dat, *wt0, *wt1, *Alpha1, *Beta1; double t2[MAXB*MAXB], t1[MAXB], ll; dat = (double *)mxCalloc(n1*n0, sizeof(double)); wt0 = (double *)mxCalloc(n1*n0, sizeof(double)); wt1 = (double *)mxCalloc(n1*n0, sizeof(double)); Alpha1 = (double *)mxCalloc(m1*m0*m1*m0, sizeof(double)); Beta1 = (double *)mxCalloc(m1*m0, sizeof(double)); hist(m0,m1,m2, n0,n1,n2, vol, B0,B1,B2,f, nh,(nh-1.0)/mx,h, dat, psh); ll = 0.0; for(j2=0;j2<n2; j2++) { get_slice(vol,j2,dat); for(i0=0; i0<m0*m1; i0++) { t2[i0] = 0.0; for(i2=0;i2<m2; i2++) t2[i0] += B2[j2+n2*i2]*f[i0+m0*m1*i2]; } for(j1=0; j1<n1; j1++) { for(i0=0; i0<m0; i0++) { t1[i0] = 0.0; for(i1=0;i1<m1; i1++) t1[i0] += B1[j1+n1*i1]*t2[i0+m0*i1]; } for(j0=0; j0<n0; j0++) { double sc = 0.0; for(i0=0; i0<m0; i0++) sc += B0[j0+n0*i0]*t1[i0]; weights(dat[j0+n0*j1], exp(sc), nh, (nh-1.0)/mx,h, &wt0[j0+n0*j1], &wt1[j0+n0*j1], &ll); } } kronutil(n0,n1,n2, m0,m1,m2, j2, wt0,wt1, B0,B1,B2, Alpha1,Beta1, Alpha,Beta); } mxFree((void *)dat); mxFree((void *)wt0); mxFree((void *)wt1); mxFree((void *)Alpha1); mxFree((void *)Beta1); return(ll); }
statistics::Histogram get_density_histogram(const em::DensityMap *dmap, float threshold,int num_bins) { statistics::Histogram hist(threshold-em::EPS,dmap->get_max_value()+.1, num_bins); for(long v_ind=0;v_ind<dmap->get_number_of_voxels();v_ind++) { if (dmap->get_value(v_ind) > threshold) { hist.add(dmap->get_value(v_ind)); } } return hist; }
void MainWindow::gamma() { Histogram hist(image); histogram = hist.getImage(); double gamma = QInputDialog::getDouble(this,"Gamma value","Gamma value"); image = applyContrast(image,gamma); setImages(); }
void MainWindow::manual() { Histogram hist(image); histogram = hist.getImage(); double thres = QInputDialog::getDouble(this,"Threshold value","Threshold value"); image = changeLUT(image,thres); setImages(); }
static ImpCompactNumberArray::unique_ptr_type constructFromArray(iterator_in it_in, uint64_t const n) { libmaus::util::Histogram hist; for ( iterator_in it_a = it_in; it_a != it_in+n; ++it_a ) hist ( libmaus::math::bitsPerNum(*it_a) ); ImpCompactNumberArrayGenerator gen(hist); ImpCompactNumberArray::unique_ptr_type ptr(gen.construct(it_in,n)); return UNIQUE_PTR_MOVE(ptr); }
virtual void generate_round(int round, nbgen &rng, histogram_c ¢er) { int_c board_card_sum{0, 3, 4, 5}; size_t round_size = ehslp->size(round); std::vector<datapoint_t> features = std::vector<datapoint_t>(round_size); // thread variables int per_block = round_size / nb_threads; std::vector<size_t> thread_block_size(nb_threads, per_block); thread_block_size.back() += round_size - nb_threads * per_block; std::vector<std::thread> eval_threads(nb_threads); size_t accumulator = 0; for (int t = 0; t < nb_threads; ++t) { accumulator += thread_block_size[t]; eval_threads[t] = std::thread([t, round, accumulator, &features, &board_card_sum, &thread_block_size, this] { uint8_t cards[7]; histogram_t hist(1); for (size_t i = (accumulator - thread_block_size[t]); i < accumulator; ++i) { hist[0] = ehslp->raw(round,i); features[i].histogram = hist; } }); } for (int t = 0; t < nb_threads; ++t) eval_threads[t].join(); std::cout << "clustering " << round_size << " holdings into " << nb_buckets[round] << " buckets...\n"; unsigned restarts = 100; // TODO: configurable kmeans_center_multiple_restarts(restarts, nb_buckets[round], kmeans_center_init_random, center, features, rng); kmeans(nb_buckets[round], features, l2_distance, center, nb_threads, err_bounds[round]); std::cout << "writing abstraction for round to file...\n"; dump_to->write(reinterpret_cast<const char *>(&round), sizeof(round)); dump_to->write(reinterpret_cast<const char *>(&nb_buckets[round]), sizeof(nb_buckets[round])); size_t nb_entries = ehslp->size(round); for (size_t i = 0; i < nb_entries; ++i) { dump_to->write(reinterpret_cast<const char *>(&features[i].cluster), sizeof(features[i].cluster)); } std::cout << "done.\n"; }
std::vector<unsigned int> ImgProcessing::histogramProcess(Mat src){ std::vector<unsigned int> hist (10,0); for (int i = 0; i < src.rows; i++) { for (int j = 0; j < src.cols; j++) { int n = (int) src.at<unsigned char>(i, j); hist[n] += 1; } } return hist; }
HistEncoding::FeatureType HistEncoding::computeFeatures(SampleType samples) const { if (_usePCA) { samples = samples * _pcaBasis; } FeatureType hist(_k, 1); hist.setZero(); for (int i = 0; i < samples.rows(); ++i) { hist(_tree->findNN(samples.row(i)), 0) += 1; } if (samples.rows() > 0) { hist = hist.normalized(); } return hist; }
int Data::calculate(cv::Mat ch, bool vertical){ int result = -1; cv::Point p; SimpleHistogram hist(vertical ? ch.size().width : ch.size().height); for (p.y = 0; p.y < ch.size().height; p.y++){ for (p.x = 0; p.x < ch.size().width; p.x++) { if (ch.at<uchar>(p) > 0) hist.add(vertical ? p.x : p.y); } } result = hist.indexOfMax(); return result; }
void MainWindow::otsuThresh() { Histogram hist(image); histogram = hist.getImage(); image = otsu(image,hist); setImages(); }