1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
47 // #include "HighGUI.h"
51 static char cTestName[] = "Image Adaptive Thresholding";
52 static char cTestClass[] = "Algorithm";
53 static char cFuncName[] = "cvAdaptThreshold";
54 static int aAdaptThreshold()
59 double parameter2 = 10;
69 double pi = 3.1415926;
76 long diff_binary, diff_binary_inv;
80 IplImage *imBinary, *imBinary_inv, *imTo_zero, *imTo_zero_inv, *imInput, *imOutput;
86 if(!trsiRead( &width, "128", "image width" ))
88 if(!trsiRead( &height, "128", "image height" ))
92 l = width*height*sizeof(uchar);
94 cp = (CvPoint*) trsmAlloc(nPoints2*sizeof(CvPoint));
96 xc = (int)( width/2.);
97 yc = (int)( height/2.);
102 size.height = height;
110 for(i=0;i<nPoints2;i++)
112 cp[i].x = (int)(a2*cos(2*pi*i/nPoints2)*cos(2*pi*fi/360.))-
113 (int)(b2*sin(2*pi*i/nPoints2)*sin(2*pi*fi/360.))+xc;
114 if(xmin> cp[i].x) xmin = cp[i].x;
115 if(xmax< cp[i].x) xmax = cp[i].x;
116 cp[i].y = (int)(a2*cos(2*pi*i/nPoints2)*sin(2*pi*fi/360.))+
117 (int)(b2*sin(2*pi*i/nPoints2)*cos(2*pi*fi/360.))+yc;
118 if(ymin> cp[i].y) ymin = cp[i].y;
119 if(ymax< cp[i].y) ymax = cp[i].y;
122 if(xmax>width||xmin<0||ymax>height||ymin<0) return TRS_FAIL;
124 // IPL image moment calculation
126 imBinary = cvCreateImage( size, 8, 1 );
127 imBinary_inv = cvCreateImage( size, 8, 1 );
128 imTo_zero = cvCreateImage( size, 8, 1 );
129 imTo_zero_inv = cvCreateImage( size, 8, 1 );
130 imOutput = cvCreateImage( size, 8, 1 );
131 imInput = cvCreateImage( size, 8, 1 );
136 memset(imInput->imageData,bgrn,l);
138 cvFillPoly(imInput, &cp, &kp, 1, cvScalarAll(signal));
144 atsRandInit( &state, lower, upper, seed );
146 uchar *input = (uchar*)imInput->imageData;
147 uchar *binary = (uchar*)imBinary->imageData;
148 uchar *binary_inv = (uchar*)imBinary_inv->imageData;
149 uchar *to_zero = (uchar*)imTo_zero->imageData;
150 uchar *to_zero_inv = (uchar*)imTo_zero_inv->imageData;
151 double *parameter = (double*)trsmAlloc(2*sizeof(double));
153 int step = imInput->widthStep;
155 for(i = 0; i<size.height; i++, input+=step, binary+=step, binary_inv+=step, to_zero+=step,to_zero_inv+=step)
157 for(j = 0; j<size.width; j++)
159 atsbRand8s( &state, &rand, 1);
162 binary[j] = to_zero[j] = (uchar)0;
163 binary_inv[j] = (uchar)255;
164 to_zero_inv[j] = input [j] = (uchar)(bgrn + rand);
168 binary[j] = (uchar)255;
169 binary_inv[j] = to_zero_inv[j] = (uchar)0;
170 to_zero[j] = input[j] = (uchar)(signal + rand);
178 cvAdaptiveThreshold( imInput, imOutput, (double)255, CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY, parameter1, parameter2 );
179 diff_binary = atsCompare1Db( (uchar*)imOutput->imageData, (uchar*)imBinary->imageData, l, 5);
181 cvAdaptiveThreshold( imInput, imOutput, (double)255, CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY_INV, parameter1, parameter2 );
182 diff_binary_inv = atsCompare1Db( (uchar*)imOutput->imageData, (uchar*)imBinary_inv->imageData, l, 5);
184 if( diff_binary > 5 || diff_binary_inv > 5 )
187 cvReleaseImage(&imInput);
188 cvReleaseImage(&imOutput);
189 cvReleaseImage(&imBinary);
190 cvReleaseImage(&imBinary_inv);
191 cvReleaseImage(&imTo_zero);
192 cvReleaseImage(&imTo_zero_inv);
194 trsWrite( ATS_CON | ATS_LST | ATS_SUM, "diff_binary =%ld \n", diff_binary);
195 trsWrite( ATS_CON | ATS_LST | ATS_SUM, "diff_binary_inv =%ld \n", diff_binary_inv);
203 void InitAAdaptThreshold( void )
205 /* Test Registartion */
206 trsReg(cFuncName,cTestName,cTestClass,aAdaptThreshold);
207 } /* InitAAdaptThreshold */