static void stat1(int row, uint64_t difference, uint64_t total) { double dtime; if (total > 0) dtime = 100.0 * difference / total; else dtime = 0; wmove(wnd, row, INSET); #define CPUSCALE 0.5 histogram(dtime, 50, CPUSCALE); }
int KHistogram::histogram(const char *filename) { // open file using GDAL GDALDataset *dataset = (GDALDataset *)GDALOpen(filename, GA_ReadOnly); if (dataset == NULL) return 1; // compute histogram of file contents int ret = histogram(dataset); // close file delete dataset; return ret; }
void mexFunction(int nlhs, /* number of arguments on lhs */ mxArray *plhs[], /* Matrices on lhs */ int nrhs, /* no. of mat on rhs */ const mxArray *prhs[] /* Matrices on rhs */ ) { register const double *data; /* pointer to input data */ mxArray *xArray; /* pointer to output x */ register double *h, *x; /* pointers to histogram and intensity values */ register int npoints; /* number of points in the input array */ int Nbins; /* number of bins in the histogram */ double *NbinsPtr; /* pointer to the number of bins input argument */ int Outdims[2]; /* dimensions of the output arrays */ /* Check for proper number of arguments */ if (nrhs<1) { /* help */ printf("[h, x] = regHistogram(A, <Nbins>);\n"); printf(" Computes the histogram of a N-dimensional array (A), \n"); printf(" using Nbins intervals (default = 256). \n"); } /* reading input parameters */ data = mxGetPr(prhs[0]); npoints = mxGetNumberOfElements(prhs[0]); if (nrhs==2) { NbinsPtr = mxGetPr(prhs[1]); Nbins = (int)(*NbinsPtr);} else { Nbins = 256;} /* creating output array for histogram and intensity values, with room for one more value (corresponding to Max */ Outdims[0] = 1; Outdims[1] = Nbins+1; plhs[0] = mxCreateNumericArray(2, Outdims, mxDOUBLE_CLASS, mxREAL); xArray = mxCreateNumericArray(2, Outdims, mxDOUBLE_CLASS, mxREAL); h = mxGetPr(plhs[0]); x = mxGetPr(xArray); /* main routine */ histogram(data, npoints, h, x, Nbins); /* returning arrays with the actual number of bins */ Outdims[0] = 1; Outdims[1] = Nbins; mxSetDimensions(plhs[0], Outdims, 2); mxSetDimensions(xArray, Outdims, 2); /* returning bin centers if requested */ if (nlhs == 2) { plhs[1] = xArray; } }
float otsu_threshold(const ImageType& src) { std::pair<typename ImageType::value_type,typename ImageType::value_type> min_max = min_max_value(src.begin(),src.end()); std::vector<unsigned int> hist; histogram(src,hist,min_max.first,min_max.second); if(hist.empty()) return min_max.first; std::vector<unsigned int> w(hist.size()); std::vector<float> sum(hist.size()); w[0] = hist[0]; sum[0] = 0.0; for (unsigned int index = 1,last_w = hist[0],last_sum = 0.0; index < hist.size(); ++index) { w[index] = last_w + hist[index]; sum[index] = last_sum + hist[index]*index; last_w = w[index]; last_sum = sum[index]; } float total_sum = sum.back(); float total_w = w.back(); float max_sig_b = 0.0; unsigned int optimal_threshold = 0; for (unsigned int index = 0; index < hist.size()-1; ++index) { if (!w[index]) continue; unsigned int w2 = (total_w-w[index]); if (!w2) continue; float d = sum[index]*(float)total_w; d -= total_sum*(float)w[index]; d *= d; d /= w[index]; d /= w2; if (d > max_sig_b) { max_sig_b = d; optimal_threshold = index; } } float optimal_threshold_value = optimal_threshold; optimal_threshold_value /= hist.size(); optimal_threshold_value *= min_max.second - min_max.first; optimal_threshold_value += min_max.first; return optimal_threshold_value; }
void histogram(cv::Mat *image,int *histo, int convert){ if (!image || !histo) return; unsigned char *im = (unsigned char*)(image->data); int im_step = image->step; int im_cols = image->cols; int im_rows = image->rows; histogram(im,im_step,im_cols,im_rows,histo); if (convert) { otsu(im,im_step,im_cols,im_rows,histo); } }
static int devstats(int row, int _col, int dn) { long double transfers_per_second; long double kb_per_transfer, mb_per_second; long double busy_seconds; int di; di = dev_select[dn].position; busy_seconds = cur.snap_time - last.snap_time; if (devstat_compute_statistics(&cur.dinfo->devices[di], &last.dinfo->devices[di], busy_seconds, DSM_KB_PER_TRANSFER, &kb_per_transfer, DSM_TRANSFERS_PER_SECOND, &transfers_per_second, DSM_MB_PER_SECOND, &mb_per_second, DSM_NONE) != 0) errx(1, "%s", devstat_errbuf); if (numbers) { mvwprintw(wnd, row, _col, " %5.2Lf %3.0Lf %5.2Lf ", kb_per_transfer, transfers_per_second, mb_per_second); return(row); } wmove(wnd, row++, _col); histogram(mb_per_second, 50, .5); wmove(wnd, row++, _col); histogram(transfers_per_second, 50, .5); if (kbpt) { wmove(wnd, row++, _col); histogram(kb_per_transfer, 50, .5); } return(row); }
void recordHist() const{ histogram(&unknownA,1); histogram(unknownB,sizeof(unknownB)); histogram(unknownC,sizeof(unknownC)); histogram(unknownD,sizeof(unknownD)); histogram(unknownE,sizeof(unknownE)); histogram(unknownF,sizeof(unknownF)); }
int main(int argc, char** argv) { //the options struct holds all run-time options. options opt; opt.overwrite = false ; opt.gaussBool = false ; //Initialize --overwrite flag to false. Probably should handle //this in read_options. opt.polyFit = false ; vector<double> data ; double avg, std ; vector <vector<double> > hist ; read_options(argc, argv, opt) ; //Print run-time parameters cout << "inFile : " << opt.inFile << endl ; cout << "outFile: " << opt.outFile << endl ; cout << "numBins: " << opt.numBins << endl ; cout << "overwrite : " ; if (opt.overwrite) { cout << "True" << endl ; } else { cout << "False" << endl; } if ( opt.gaussBool ) { cout << "Gaussian fit file : " << opt.gaussFile << endl; } if ( opt.polyFit ) { cout << "Polynomial fit file : " << opt.polyfitFile << endl; cout << "Number of terms : " << opt.numTerms << endl ; } //Begin program data = read_data(opt.inFile) ; cout << endl; avg = average(data) ; cout << "average = " << avg << endl; std = stdDev(data,avg) ; cout << "std = " << std << endl ; hist = histogram(data, opt.numBins) ; print(hist,opt.outFile); if (opt.gaussBool) print_gauss(hist, opt.gaussFile, std, avg) ; if (opt.polyFit) fit_polynomial(hist,avg, opt.numTerms, opt.polyfitFile) ; return 0; }
static void stat1(int row, int o) { int i; double dtime; dtime = 0.0; for (i = 0; i < CPUSTATES; i++) dtime += cur.cp_time[i]; if (dtime == 0.0) dtime = 1.0; wmove(wnd, row, INSET); #define CPUSCALE 0.5 histogram(100.0 * cur.cp_time[o] / dtime, 50, CPUSCALE); }
static int devstats(int row, int _col, int dn) { long double transfers_per_second; long double kb_per_transfer, mb_per_second; long double busy_seconds; int di; di = dev_select[dn].position; busy_seconds = compute_etime(cur.busy_time, last.busy_time); if (compute_stats(&cur.dinfo->devices[di], &last.dinfo->devices[di], busy_seconds, NULL, NULL, NULL, &kb_per_transfer, &transfers_per_second, &mb_per_second, NULL, NULL) != 0) errx(1, "%s", devstat_errbuf); if (numbers) { mvwprintw(wnd, row, _col, " %5.2Lf %3.0Lf %5.2Lf ", kb_per_transfer, transfers_per_second, mb_per_second); return(row); } wmove(wnd, row++, _col); histogram(mb_per_second, 50, .5); wmove(wnd, row++, _col); histogram(transfers_per_second, 50, .5); if (kbpt) { wmove(wnd, row++, _col); histogram(kb_per_transfer, 50, .5); } return(row); }
int Compute( int _ymin, int _ymax ) const { int d = sizeof(unsigned short) * m_width; if ( !m_pSrc || !m_pDst || m_srcStride < d || m_dstStride < d ) return 0; if ( _ymin < 0 ) _ymin = 0; if ( _ymax > m_height ) _ymax = m_height; int _xmax = m_width; d = m_R; int ymin = _ymin + d; int ymax = _ymax - d; int xmin = d+1; int xmax = _xmax - d; unsigned short * p; int x,y; std::vector< unsigned short > vec( (2*m_R+1)*(2*m_R+1) ); Histogram histogram( m_N ); int _where = 0; for (y =_ymin;y<_ymax;++y) { p = TCV_GET_LINE_PTR( unsigned short, m_pDst, m_dstStride, y ); if ( y>=ymin && y<ymax ) { for (x=0;x<d;++x) *(p+x) = compute_boundscheck( x, y, vec ); FillHistogram( d, y, histogram ); *(p+d) = histogram.getmedian(); for (x=xmin;x<xmax;++x) { UpdateHistogram( x, y, histogram ); *(p+x) = histogram.getmedian(); } for (x=xmax;x<_xmax;++x) *(p+x) = compute_boundscheck( x, y, vec ); } else { for (x=0;x<_xmax;++x) *(p+x) = compute_boundscheck( x, y, vec ); } } return 1; }
inline QVector<int> histogram(const QImage &image) { QVector<int> histogram(256, 0); for (int y = 0; y < image.height(); y++) { const quint8 *line = reinterpret_cast<const quint8 *>(image.constScanLine(y)); for (int x = 0; x < image.width(); x++) histogram[line[x]]++; } // Since we use sum tables add one more to avoid unexistent colors. for (int i = 0; i < histogram.size(); i++) histogram[i]++; return histogram; }
// Display the count images in bgr and compute their HSV histograms. // Then compare each histogram to the first one and report results. // static void showHistogramComparisons(int count, const char *name[], const cv::Mat bgr[]) { std::vector<cv::Mat> hsv(count); std::vector<cv::Mat> histogram(count); for (int i = 0; i < count; ++i) { makeWindow(name[i], bgr[i]); cv::cvtColor(bgr[i], hsv[i], cv::COLOR_BGR2HSV); } for (int i = 0; i < histogram.size(); ++i) { histogram[i] = calculateHistogram(hsv[i]); } compareHistograms(histogram, name); std::cout << "Press a key to quit." << std::endl; cv::waitKey(0); }
void printasciihist(struct fitsstatsparams *p) { size_t j, tnum=p->histnumbins; int i, h0c1=0, height=p->asciihisth; int tbzero=p->binonzero, tnorm=p->normhist, tmaxone=p->maxhistone; /* Find the histogram for the ASCII plot: */ p->normhist=0; p->binonzero=0; p->maxhistone=1; p->histnumbins=p->asciihistnb; setbins(p, h0c1); histogram(p); /* It's maximum value is set to one. Multiply that by the desired height in pixels. */ for(j=0;j<p->asciihistnb;++j) p->bins[j*2+1]*=height; /* Plot the ASCII histogram: */ printf(" -- ASCII histogram in the range: %f - %f:\n\n", p->histmin, p->histmax); for(i=height;i>=0;--i) { printf(" |"); for(j=0;j<p->asciihistnb;++j) { if(p->bins[j*2+1]>=((float)i-0.5) && p->bins[j*2+1]>0.0f) printf("*"); else printf(" "); } printf("\n"); } printf(" |"); for(j=0;j<p->asciihistnb;++j) printf("-"); printf("\n\n"); /* Free the allocated array and set the parameters back to what they were. */ free(p->bins); p->normhist=tnorm; p->histnumbins=tnum; p->binonzero=tbzero; p->maxhistone=tmaxone; }
void hmap_print_stats(HMAP_PTR map) { printf("######## TABLE STATS ##########\n"); printf(" hash-func: %s \n", map->hfunc_desc); printf(" tsize-policy: %s \n", map->tsize_policy); printf(" tblsize: %i \n", map->tsize); printf(" numkeys: %i \n", map->n); printf(" max-collisions: %i \n", max_len(map)); printf(" avg-cmps-good-lookup: %f \n", avg_cmps(map)); histogram(map); printf("###### END TABLE STATS ##########\n"); }
int main(){ int wordLength[30]; int wl = 0, i, j; char c; for(i = 0; i < 30; i++) wordLength[i] = 0; while((c = getchar()) != EOF){ if(c == '\n' || c == ' ' || c == '\t'){ if(wl > 0){ wordLength[wl]++; wl = 0; } }else{ wl++; } } histogram(wordLength); vhistogram(wordLength); }
void main () { int numValues = 100000; srandom (17); apvector<int> vector = randomVector (numValues); apvector<int> histogram (10, 0); for (int i = 0; i<numValues; i++) { int index = vector[i]; histogram[index]++; } for (int i = 0; i<10; i++) { cout << i << "\t" << histogram[i] << endl; } }
void WeightMatrix::Debug2D(const char* msg) { STATS histogram(0, kHistogramBuckets); if (int_mode_) { for (int i = 0; i < wi_.dim1(); ++i) { for (int j = 0; j < wi_.dim2(); ++j) { HistogramWeight(wi_[i][j] * scales_[i], &histogram); } } } else { for (int i = 0; i < wf_.dim1(); ++i) { for (int j = 0; j < wf_.dim2(); ++j) { HistogramWeight(wf_[i][j], &histogram); } } } tprintf("%s\n", msg); histogram.print(); }
int main(int argc, char **argv) { int argn; int do_huffman, do_hist; int cnt; cnt = 0; argn = tino_getopt(argc, argv, 1, 0, TINO_GETOPT_VERSION(HISTOGRAM_VERSION) TINO_GETOPT_LLOPT " file [..]\n" " Use - as filename to read stdin", TINO_GETOPT_USAGE "help this help" , TINO_GETOPT_FLAG TINO_GETOPT_COUNT "huff print huffman tree" , &cnt , &do_huffman, TINO_GETOPT_FLAG TINO_GETOPT_COUNT "hist print histogram (default if nothing else given)" , &cnt , &do_hist, NULL ); if (argn<=0) return 1; for (; argn<argc; argn++) readfile(argv[argn]); if (do_huffman) huffman(); if (do_hist || !cnt) histogram(); return 0; }
double distribution(int slot, short *data, int bits, double *p) { double mean, std, skew, kurt; int i, j, n, nsimple; double *simple; double *herror; short *ndata; n = bits / DCTSIZE2; if ((ndata = malloc(n * sizeof(short))) == NULL) err(1, "malloc"); for (j = 0; j < n; j++) ndata[j] = data[j*DCTSIZE2 + slot]; histogram(ndata, n, &simple, &nsimple); free(ndata); if ((herror = calloc(nsimple, sizeof(double))) == NULL) err(1, "malloc"); for (i = 2; i < nsimple - 2; i++) { if (simple[i] != 0) herror[i] = esterror2(simple, i, nsimple-1)/simple[i]; else herror[i] = 0; /* fprintf(stderr, "%d %f\n", i, herror[i]); */ } compute_stats(herror, nsimple, &mean, &std, &skew, &kurt); free(simple); free(herror); *p++ = mean; *p++ = std; *p++ = skew; *p++ = kurt; return (0); }
vector<float> OpenImProLib_OpenCvImpl::getDensityFunction(ImageImPro* ptrInput, ImageImPro* ptrMask, int layer){ vector<float> histogram(180); int histSize = 180; /// Set the ranges ( for H ) float range[] = { 0, 180} ; const float* histRange = { range }; Mat h_hist; /// Compute the histogram: calcHist( ptrInput->getMat(), 1, 0, *(ptrMask->getMat()), h_hist, 1, &histSize, &histRange);//, uniform, accumulate ); cout << "FILAS MAT HIST" << h_hist.rows << " COLS MAT HIST " << h_hist.cols << endl; for(int i = 0; i < h_hist.rows; ++i){ histogram[i] = h_hist.at<int>(i, 0); } return histogram; }
void Index::indexHistogram(vector<uint16_t> &idxs) { vector<int> histogram(8192,0); for (int i = 0; i < idxs.size(); ++i) { histogram[idxs[i]]++; } int count = 0; for (int i = 0; i < 8192; ++i) { if (histogram[i]) count++; } cout << count <<endl; for (int i = 0; i < 8192; ++i) { if (histogram[i]) cout << histogram[i] << " , " ; } cout << endl; }
void lbp::spatial_histogram(const Mat& src, Mat& hist, int numPatterns, const Size& window, int overlap) { int width = src.cols; int height = src.rows; vector<Mat> histograms; for(int x=0; x < width - window.width; x+=(window.width-overlap)) { for(int y=0; y < height-window.height; y+=(window.height-overlap)) { Mat cell = Mat(src, Rect(x,y,window.width, window.height)); histograms.push_back(histogram(cell, numPatterns)); } } hist.create(1, histograms.size()*numPatterns, CV_32SC1); // i know this is a bit lame now... feel free to make this a bit more efficient... for(int histIdx=0; histIdx < histograms.size(); histIdx++) { for(int valIdx = 0; valIdx < numPatterns; valIdx++) { int y = histIdx*numPatterns+valIdx; hist.at<int>(0,y) = histograms[histIdx].at<int>(valIdx); } } }
static void cascade(void* context) { uintptr_t idx, *idxptr = (uintptr_t*)context; if (done) return; idx = *idxptr + 1; if (idx < QUEUES) { *idxptr = idx; dispatch_async_f(queues[idx], context, cascade); } if (dispatch_atomic_dec(&iterations) == 0) { done = 1; histogram(); MU_PASS("Please check histogram to be sure"); } }
int main() { int a[]={1, 2, 3, 4,5,6,7,8,9 }; int b[]={1, 4, 2, 3,5,6,7,9,8 }; int n=8; printf("\nis_sorted returned:%d\n\n",is_sorted(a,n)); unsigned int data[]={1, 5, 2, 13,1,7,5,2,9 };//unsigned is used for ASCII histogram(data, n); printf("\nnum_distinct returned:%d\n\n",num_distinct(a, n)); printf("same_contents returned:%d\n\n",same_contents(a,b,n)); rotate_right(a, n); }
std::vector<double> HistogramFeatureExtractor::computeHistogram(const Slice& slice) { std::vector<double> histogram(_numBins, 0); unsigned int section = slice.getSection(); Image& image = *(*_sections)[section]; foreach (const util::point<unsigned int>& pixel, slice.getComponent()->getPixels()) { double value = image(pixel.x, pixel.y); unsigned int bin = std::min(_numBins - 1, (unsigned int)(value*_numBins)); histogram[bin]++; } return histogram; }
void main(){ int arr[5]; //if this array is smaller that the max given then the histogram function will override un-allocated memory, namly the arr pointer and ns[0], ns[1] and so on... int ns[7]; ns[0] = 1; ns[1] = 2; ns[2] = 1; ns[3] = 1; ns[4] = 1; ns[5] = 2; ns[6] = 0; histogram(7,ns, 3, arr); int i; for(i = 0; i < 5; ++i){ print arr[i]; println; } }
void main() { int arr[5]; arr[0] = 0; arr[1] = 1; arr[2] = 1; arr[3] = 2; arr[4] = 3; int freq[4]; freq[0] = 0; freq[1] = 0; freq[2] = 0; freq[3] = 0; int max; max = 3; histogram(5, arr, max, freq); int i; for (i = 0; i <= max; i = i + 1) { print freq[i]; } }
float EMFit::estimate_density_threshold(float object_volume) const { // compute density values histogram // get min/max density values float min_value = std::numeric_limits<float>::max(); float max_value = -std::numeric_limits<float>::max(); for (long l = 0; l < map_->get_number_of_voxels(); l++) { float value = map_->get_value(l); if (value > max_value) max_value = value; if (value < min_value) min_value = value; } // std::cerr << "min = " << min_value << " max = " << max_value << std::endl; float bins_number = 1000; // Ensure that value=max_value ends up in histogram[bins_number-1], // not histogram[bins_number] float delta = (max_value - min_value) / (bins_number - 1); std::vector<int> histogram(bins_number, 0); for (long l = 0; l < map_->get_number_of_voxels(); l++) { float value = map_->get_value(l); int index = static_cast<int>((value - min_value) / delta); histogram[index]++; } // print histogram // for(unsigned int i=0; i<bins_number; i++) // std::cerr << i << " " << histogram[i] << std::endl; float curr_volume = 0.0; float bin_volume = IMP::cube(map_->get_spacing()); float threshold = 0.0; for (int i = bins_number - 1; i >= 0; i--) { if (curr_volume >= object_volume) { threshold = min_value + i * delta; std::cout << "Threshold= " << threshold << " protein_volume= " << object_volume << " curr_volume= " << curr_volume << std::endl; return threshold; } curr_volume += bin_volume * histogram[i]; } return threshold; }
/* out: emin, emax */ void edrc(pix_type *in, int w, int h, int *pemin, int *pemax, int cop) { int *histo; int i; int rmin,rmax; /* dynamic range of image */ int emin,emax; /* effective dynamic range */ int cutoff; /* find maximum dynamic range of image */ rmin=in[0]; rmax=in[0]; for(i=0;i<w*h;i++){ if(in[i] < rmin) rmin = in[i]; if(in[i] > rmax) rmax = in[i]; } /* rmax+1 because we want the rmax'th element to be available. * without this it gives nasty memory stack corruption errors */ histo = (int *)malloc((rmax+1) * sizeof(int)); if(!histo){ /* in case of failure, fall back */ (*pemin) = rmin; (*pemax) = rmax; return; } histogram(in, w, h, rmax, histo); /* determine effective dynamic range */ cutoff = (((w*h)/(rmax-rmin))*cop)/256; /* TODO: make user-selectable */ emin=rmin; emax=rmax; for(i=rmin;i<rmax;i++) if(histo[i] > cutoff) {emin=i; break;} for(i=rmax;i>emin;i--) if(histo[i] > cutoff) {emax=i; break;} #ifdef DEBUG_PRINT printf("dynamic:[%d,%d] effective dynamic:[%d,%d]\n",rmin,rmax,emin,emax); printf("cutoff:%d histo[emax]:%d\n",cutoff,histo[emax]); #endif (*pemin) = emin; (*pemax) = emax; free(histo); }