Home > Back-end > C function transformation is the function of Delphi, the source code is given
C function transformation is the function of Delphi, the source code is given
Time:10-04
Image int otsu (IplImage * and an int rows, int cols, int x0, int y0, int dx, int dy, int VVV) { Unsigned char * np;//image pointer Int thresholdValue=https://bbs.csdn.net/topics/1;//threshold Int ihist [256].//image histogram, 256 points int i, j, k;//various counters Int n, n1, and n2, gmin, gmax; Double m1, m2, sum, csum fmax, sb; //the histogram zero Memset (ihist, 0, sizeof (ihist)); Gmin=255; Gmax=0; //generated histogram /* For (I=y0 + 1; I & lt; Y0 + dy - 1; I++) { Np=& amp; Image [I * cols + x0 + 1]; For (j=x0 + 1; J & lt; X0 + dx - 1; J++) { Np ihist [*] + +; If (* np & gt; Gmax) gmax=* np; If (* np & lt; Gmin) gmin=* np; Np++;/* next pixel } } */ For (j=y0; j{ for(i=0; i{ Unsigned char temp=CV_IMAGE_ELEM (image, uchar, j, I); Ihist [temp] + +; } } //set up everything Sum=csum=0.0; N=0; For (k=0; K & lt;=255; K++) { The sum +=(double) k * (double) ihist [k].//x * f (x) mass moment N +=ihist [k].//f (x) quality } if (! N) { //if n has no value, there is the problems Fprintf (stderr, "NOT NORMAL thresholdValue=https://bbs.csdn.net/topics/160/n"); Return (160); } //do the otsu global thresholding method Fmax=1.0; N1=0; For (k=0; K & lt; 255; K++) { N1 +=ihist [k]. if (! N1) {continue; } - n1 n2=n; {if (n==0) break; } Csum +=(double) k * ihist [k]. M1=csum/n1; M2=(sum - csum)/n2; Sb=(double) n1 * (double) n2 * (m1, m2) * (m1, m2); ///* * * BBG: note: can be optimized. */ If (sb & gt; Fmax) { Fmax=sb; ThresholdValue=https://bbs.csdn.net/topics/k; } } //at this point we have our thresholding value, the debug code to display thresholding values If (VVV & amp; 1) Fprintf (stderr, "# OTSU: thresholdValue=https://bbs.csdn.net/topics/%d gmin gmax==% d % d/n", thresholdValue, gmin, gmax); Return (thresholdValue); }