示例#1
0
void testGet_seg_size_feature(){
    int lablenum=5,nr=160,nc=160,i=0,j=0;
    int size=nr*nc;
    int* seglable=NEWA(int,size);
    fSegment_size feat;
    for(i=0;i<size;++i){
        if(i<size/10){
          seglable[i]=1;  
        }
        else if(i<2*size/10){
            seglable[i]=2;
        }
        else if(i<4*size/10){
            seglable[i]=3;
        }
        else if(i<6*size/10){
            seglable[i]=4;
        }
        else
            seglable[i]=5; 
    }
    feat=get_segsize_feature(seglable,nr,nc,lablenum);
    CU_ASSERT_DOUBLE_EQUAL(feat.rmaxsize, 0.4, 0.00001);
    CU_ASSERT_DOUBLE_EQUAL(feat.rcontrast, 0.3, 0.00001);
    free(seglable);
}
示例#2
0
void testGet_grayscale_simplicity_feautre() {
    image_gray* gray = image_gray_new(3, 3);
	
	gray->data[0] = 15;
	gray->data[1] = 15;
	gray->data[2] = 200;
	gray->data[3] = 180;
	gray->data[4] = 180;
	gray->data[5] = 100;
	gray->data[6] = 90;
	gray->data[7] = 85;
	gray->data[8] = 180;

	fgray_simplicity feature = get_grayscale_simplicity_feature(gray);
	CU_ASSERT_EQUAL(feature.contrast, 186);
	CU_ASSERT_EQUAL(feature.sig_pixels_num, 6);
	CU_ASSERT_DOUBLE_EQUAL(feature.stdev,  68.01870, 0.00001);

	//free(feature);
    
    image_gray* gray2 = image_gray_new(1, 1);
    gray2->data[0] = 1;
    feature = get_grayscale_simplicity_feature(gray2);
    CU_ASSERT_EQUAL(feature.contrast, 1);
	CU_ASSERT_EQUAL(feature.sig_pixels_num, 1);
	CU_ASSERT_DOUBLE_EQUAL(feature.stdev,  0, 0.00001);
	image_gray_delete(gray);
}
示例#3
0
extern void test_sagwrite_3x3_zero(void)
{
    bbox_t bbox = BBOX(0, 3, 0, 3);
    polyline_t p;
    CU_ASSERT_EQUAL(polyline_rect(bbox, &p), 0);

    domain_t *dom = domain_insert(NULL, &p);
    CU_ASSERT_PTR_NOT_NULL(dom);

    const char path[] = "tmp/sagwrite-3x3.txt";

    CU_ASSERT_EQUAL(sagwrite(path, dom, f0, NULL, 3, 3), 0);

    sagread_t sagread;

    CU_ASSERT_EQUAL(sagread_open(path, &sagread), 0);

    CU_ASSERT_EQUAL_FATAL(sagread.grid.dim, 2);
    CU_ASSERT_EQUAL_FATAL(sagread.vector.dim, 2);

    double eps = 1e-10;

    for (int i = 0 ; i < 2 ; i++)
    {
        CU_ASSERT_EQUAL_FATAL(sagread.grid.n[i], 3);
        CU_ASSERT_DOUBLE_EQUAL(sagread.grid.bnd[i].min, 0.5, eps);
        CU_ASSERT_DOUBLE_EQUAL(sagread.grid.bnd[i].max, 2.5, eps);
    }

    sagread_close(sagread);
    domain_destroy(dom);

    unlink(path);
}
示例#4
0
static void test_ptarray_signed_area() 
{
	LWLINE *line;
	double area;

	/* parallelogram */
	line = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(0 0,1 1, 2 1, 1 0, 0 0)"));
	area = ptarray_signed_area(line->points);
	CU_ASSERT_DOUBLE_EQUAL(area, 1.0, 0.0000001);
	lwline_free(line);

	/* square */
	line = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(0 0,0 2, 2 2, 2 0, 0 0)"));
	area = ptarray_signed_area(line->points);
	CU_ASSERT_DOUBLE_EQUAL(area, 4.0, 0.0000001);
	lwline_free(line);

	/* square backwares*/
	line = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(0 0,2 0, 2 2, 0 2, 0 0)"));
	area = ptarray_signed_area(line->points);
	//printf("%g\n",area);
	CU_ASSERT_DOUBLE_EQUAL(area, -4.0, 0.0000001);
	lwline_free(line);
	
}
示例#5
0
/*
* Can we read this example point value?
*/
static void
test_schema_xy()
{
	/*
	"Intensity", "ReturnNumber", "NumberOfReturns", "ScanDirectionFlag", "EdgeOfFlightLine", "Classification", "ScanAngleRank", "UserData", "PointSourceId", "Time", "Red", "Green", "Blue", "PointID", "BlockID", "X", "Y", "Z"
	25, 1, 1, 1, 0, 1, 6, 124, 7327, 246093, 39, 57, 56, 20, 0, -125.0417204, 49.2540081, 128.85
	*/
	static char *hexpt = "01010000000AE9C90307A1100522A5000019000101010001067C9F1C4953C474650A0E412700390038001400000000000000876B6601962F750155320000";

	uint8_t *bytes =  bytes_from_hexbytes(hexpt, strlen(hexpt));
	PCPOINT *pt;
	double val;

	pt = pc_point_from_wkb(lasschema, bytes, strlen(hexpt)/2);
	pc_point_get_double_by_name(pt, "x", &val);
	CU_ASSERT_DOUBLE_EQUAL(val, -125.0417204, 0.00001);
	pc_point_free(pt);

	pt = pc_point_from_wkb(lasschema, bytes, strlen(hexpt)/2);
	pc_point_get_double_by_name(pt, "y", &val);
	CU_ASSERT_DOUBLE_EQUAL(val, 49.2540081, 0.00001);
	pc_point_free(pt);

	pcfree(bytes);
}
示例#6
0
void test_vec_func2d(void)
{
    const unsigned long size_x = 8;
    const unsigned long size_y = 9;
    double *arg_x = malloc(sizeof(double) * size_x);
    double *arg_y = malloc(sizeof(double) * size_y);

    for (unsigned long k = 0; k < size_x; ++k)
        arg_x[k] = k;
    for (unsigned long k = 0; k < size_y; ++k)
        arg_y[k] = k;

    double *dst = malloc(sizeof(double) * size_x * size_y);
    double *arg = malloc(sizeof(double) * size_x * size_y);

    py_vec_func2d(dst, py_zero2d, arg_x, size_x, arg_y, size_y);
    for (unsigned long i = 0; i < size_x; ++i)
        for (unsigned long j = 0; j < size_y; ++j)
            CU_ASSERT_DOUBLE_EQUAL(dst[i + j * size_x], 0, TOL);

    py_vec_func2d(dst, py_identity2d, arg_x, size_x, arg_y, size_y);
    for (unsigned long i = 0; i < size_x; ++i)
        for (unsigned long j = 0; j < size_y; ++j)
            CU_ASSERT_DOUBLE_EQUAL(dst[i + j * size_x], arg_x[i], TOL);

    free(dst);
    free(arg);
}
示例#7
0
void testGet_color_coherence_feature() {
    image_hsv* hsv = image_hsv_new(6, 6);
    float data[][6] = {
                        {0.3, 0.2, 0.3, 0.3, 0.2, 0.2},
                        {0.3, 0.3, 0.2, 0.3, 0.2, 0.2},
                        {0.3, 0.2, 0.4, 0.3, 0.2, 0.2},
                        {0.3, 0.3, 0.3, 0.2, 0.2, 0.3},
                        {0.3, 0.3, 0.2, 0.2, 0.3, 0.3},
                        {0.3, 0.3, 0.2, 0.2, 0.3, 0.3}
                      };
    int i, j;
    for (i = 0; i < 6; ++i) {
        for (j = 0; j < 6; ++j) {
            hsv->h[6*i+j] = data[i][j];
            hsv->s[6*i+j] = data[i][j];
            hsv->v[6*i+j] = data[i][j];
        }
    }

    fcolor_coherence feature = get_color_coherence_feature(hsv);
    
    CU_ASSERT_EQUAL(feature.n_ccc, 3);
    CU_ASSERT_DOUBLE_EQUAL(feature.r_lc, 0.55556, 0.00001);
    CU_ASSERT_DOUBLE_EQUAL(feature.r_slc, 0.41667, 0.00001);
    CU_ASSERT_EQUAL(feature.rank, 2);
    CU_ASSERT_EQUAL(feature.s_rank, 1);
   // free(feature);
    image_hsv_delete(hsv);
}
示例#8
0
void testGet_color_harmony_feautre() {
    image_hsl* hsl1 = image_hsl_new(1, 1);
	fcolor_harmony feature;

    
	hsl1->h[0] = 0.39;
	hsl1->s[0] = 0.5;
	feature = get_color_harmony_feature(hsl1);	
	CU_ASSERT_DOUBLE_EQUAL(feature.bestfit, 0.1*2*PI*0.5, 0.00001);
	CU_ASSERT_DOUBLE_EQUAL(feature.first_two_dev, 0.2*2*PI*0.5, 0.00001);
	CU_ASSERT_DOUBLE_EQUAL(feature.avg_dev, 1.436, 0.001);
	//free(feature);
    
    /*
	image_hsl* hsl2 = image_hsl_new(1, 2);
	hsl2->h[0] = 0.11;
	hsl2->h[1] = 0.90;
	hsl2->s[0] = 1;
	hsl2->s[1] = 1;
	feature = get_color_harmony_feature(hsl2);
	CU_ASSERT_DOUBLE_EQUAL(feature.bestfit, 0, 0.00001);
	CU_ASSERT_DOUBLE_EQUAL(feature.first_two_dev, 0, 0.00001);
	CU_ASSERT_DOUBLE_EQUAL(feature.avg_dev, 1.1220, 0.02);
	//free(feature);
	*/
	image_hsl_delete(hsl1);
	//image_hsl_delete(hsl2);
}
示例#9
0
// Test statistics
static void test_statistics() {
  // Reseed the RNG
  gmcmc_rng_set(rng, 0);

  // Create the distribution
  gmcmc_prior * lognormal;
  CU_ASSERT(gmcmc_prior_create(&lognormal, gmcmc_prior_lognormal, 0.0, 1.0) == GMCMC_SUCCESS);

  double x[100000], mean = 0.0, var = 0.0;
  for (size_t i = 0; i < 100000; i++) {
    x[i] = gmcmc_prior_sample(lognormal, rng);

    // Knuth - The Art of Computer Programming (vol 2. 1998 p.232)
    double mprev = mean;
    mean += (x[i] - mean) / ((double)i + 1.0);
    var += (x[i] - mean) * (x[i] - mprev);
  }
  var /= 100000.0;

  // Test mean and variance
  CU_ASSERT_DOUBLE_EQUAL(mean, 1.64872127, 0.00531826);
  CU_ASSERT_DOUBLE_EQUAL(var, 4.67077427, 0.04173919);

  gmcmc_prior_destroy(lognormal);
}
示例#10
0
文件: cu_gdal.c 项目: ahinz/postgis
static void test_gdal_warp() {
	rt_pixtype pixtype = PT_64BF;
	rt_band band = NULL;

	rt_raster raster;
	rt_raster rast;
	uint32_t x;
	uint32_t width = 100;
	uint32_t y;
	uint32_t height = 100;
	double value = 0;

	char src_srs[] = "PROJCS[\"unnamed\",GEOGCS[\"unnamed ellipse\",DATUM[\"unknown\",SPHEROID[\"unnamed\",6370997,0]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433]],PROJECTION[\"Lambert_Azimuthal_Equal_Area\"],PARAMETER[\"latitude_of_center\",45],PARAMETER[\"longitude_of_center\",-100],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0],UNIT[\"Meter\",1],AUTHORITY[\"EPSG\",\"2163\"]]";

	char dst_srs[] = "PROJCS[\"NAD83 / California Albers\",GEOGCS[\"NAD83\",DATUM[\"North_American_Datum_1983\",SPHEROID[\"GRS 1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]],AUTHORITY[\"EPSG\",\"6269\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4269\"]],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],PROJECTION[\"Albers_Conic_Equal_Area\"],PARAMETER[\"standard_parallel_1\",34],PARAMETER[\"standard_parallel_2\",40.5],PARAMETER[\"latitude_of_center\",0],PARAMETER[\"longitude_of_center\",-120],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",-4000000],AUTHORITY[\"EPSG\",\"3310\"],AXIS[\"X\",EAST],AXIS[\"Y\",NORTH]]";

	raster = rt_raster_new(width, height);
	CU_ASSERT(raster != NULL); /* or we're out of virtual memory */

	band = cu_add_band(raster, pixtype, 1, 0);
	CU_ASSERT(band != NULL);

	rt_raster_set_offsets(raster, -500000, 600000);
	rt_raster_set_scale(raster, 1000, -1000);

	for (x = 0; x < width; x++) {
		for (y = 0; y < height; y++) {
			rt_band_set_pixel(band, x, y, (((double) x * y) + (x + y) + (x + y * x)) / (x + y + 1), NULL);
		}
	}

	rast = rt_raster_gdal_warp(
		raster,
		src_srs, dst_srs,
		NULL, NULL,
		NULL, NULL,
		NULL, NULL,
		NULL, NULL,
		NULL, NULL,
		GRA_NearestNeighbour, -1
	);
	CU_ASSERT(rast != NULL);
	CU_ASSERT_EQUAL(rt_raster_get_width(rast), 122);
	CU_ASSERT_EQUAL(rt_raster_get_height(rast), 116);
	CU_ASSERT_NOT_EQUAL(rt_raster_get_num_bands(rast), 0);

	band = rt_raster_get_band(rast, 0);
	CU_ASSERT(band != NULL);

	CU_ASSERT(rt_band_get_hasnodata_flag(band));
	rt_band_get_nodata(band, &value);
	CU_ASSERT_DOUBLE_EQUAL(value, 0., DBL_EPSILON);

	CU_ASSERT_EQUAL(rt_band_get_pixel(band, 0, 0, &value, NULL), ES_NONE);
	CU_ASSERT_DOUBLE_EQUAL(value, 0., DBL_EPSILON);

	cu_free_raster(rast);
	cu_free_raster(raster);
}
示例#11
0
void get_segcolor_harmony_feature_test(){
   int width=10,height=15;
   image_hsl* imagehsl=image_hsl_new(width,height);
   image_hsl* seghsl=image_hsl_new(1,50);
   int seglable[width*height];
   int lablenum=5;
   int i=0,j=0,k=0;
   
   for(i=0;i<height/3;++i){
       for(j=width/2;j<width;++j){
           imagehsl->l[i*width+j]=0.2;
           imagehsl->h[i*width+j]=0.2;
           imagehsl->s[i*width+j]=0.2;
           seglable[i*width+j]=2;
       }
   }
   
   for(i=height/3;i<2*height/3;++i){
       for(j=0;j<width/2;++j){
           imagehsl->l[i*width+j]=0.3;
           imagehsl->s[i*width+j]=0.3;
           imagehsl->h[i*width+j]=0.3;
           seglable[i*width+j]=3;
       }
   }

   for(i=height/3;i<2*height/3;++i){
       for(j=width/2;j<width;++j){
           imagehsl->l[i*width+j]=0.4;
           imagehsl->s[i*width+j]=0.4;
           imagehsl->h[i*width+j]=0.4;
           seglable[i*width+j]=4;
       }
   }
   
   for(i=2*height/3;i<height;++i){
       for(j=0;j<width;++j){
           imagehsl->l[i*width+j]=0.5;
           imagehsl->s[i*width+j]=0.5;
           imagehsl->h[i*width+j]=0.5;
           seghsl->l[k]=0.5;
           seghsl->h[k]=0.5;
           seghsl->s[k]=0.5;
           seglable[i*width+j]=5;
           k++;
       }
   } 
   
   fcolor_harmony feat=get_segcolor_harmony_feature(imagehsl,seglable,lablenum);
 
   fcolor_harmony feat_test=get_color_harmony_feature(seghsl);
   image_hsl_delete(imagehsl);
   image_hsl_delete(seghsl);
   CU_ASSERT_DOUBLE_EQUAL(feat.avg_dev,feat_test.avg_dev,0.00001);
   CU_ASSERT_DOUBLE_EQUAL(feat.bestfit,feat_test.bestfit,0.00001);
   CU_ASSERT_DOUBLE_EQUAL(feat.first_two_dev,feat_test.first_two_dev,0.00001);
   //free(feat_test);
   
}
示例#12
0
static void
test_patch_lazperf()
{
	PCPOINT *pt;
	int i;
	int npts = 400;
	PCPOINTLIST *pl;
	PCPATCH_LAZPERF *pal;
	PCPATCH_UNCOMPRESSED *paul, *pauref;

	// build a list of points
	pl = pc_pointlist_make(npts);

	for ( i = 0; i < npts; i++ )
	{
		pt = pc_point_make(simpleschema);
		pc_point_set_double_by_name(pt, "x", i*2.0);
		pc_point_set_double_by_name(pt, "y", i*1.9);
		pc_point_set_double_by_name(pt, "Z", i*0.34);
		pc_point_set_double_by_name(pt, "intensity", 10);
		pc_pointlist_add_point(pl, pt);
	}

	// compress the list in a lazperf patch
	pal = pc_patch_lazperf_from_pointlist( pl );

	// get an uncompressed patch from the lazperf patch
	paul = pc_patch_uncompressed_from_lazperf( pal );

	// get an uncompressed patch directly from the pointlist
	pauref = pc_patch_uncompressed_from_pointlist( pl );

	// test the number of points
	CU_ASSERT_EQUAL(pal->npoints, pauref->npoints);
	CU_ASSERT_EQUAL(paul->npoints, pauref->npoints);

	// test bounds
	CU_ASSERT_DOUBLE_EQUAL(pal->bounds.xmax, pauref->bounds.xmax, 0.0001);
	CU_ASSERT_DOUBLE_EQUAL(paul->bounds.ymax, pauref->bounds.ymax, 0.000001);

	// test type
	CU_ASSERT_EQUAL(pal->type, PC_LAZPERF);
	CU_ASSERT_EQUAL(paul->type, pauref->type);

	// test readonly
	CU_ASSERT_EQUAL(pauref->readonly, paul->readonly);
	CU_ASSERT_EQUAL(pauref->readonly, pal->readonly);

	// test datasize
	CU_ASSERT_EQUAL(paul->datasize, pauref->datasize);

	// free
	pc_pointlist_free(pl);
	pc_patch_free( (PCPATCH*) pal );
	pc_patch_free((PCPATCH*) paul);
	pc_patch_free((PCPATCH*) pauref);
}
示例#13
0
/*
Test that parallel spins have correct bond activation probability
(given by the action).
*/
void test_parallel_bond_act_probability() {
	double s1[1];
	double s2[1];
	double *r = create_spin(1);
	s1[0] = 1; s2[0] = 1;
	CU_ASSERT_DOUBLE_EQUAL(0.5507,bond_act_probability(s1, s2, r, 0.4, 1),0.0001);
	s1[0] = -1; s2[0] = -1;
	CU_ASSERT_DOUBLE_EQUAL(0.7981,bond_act_probability(s1, s2, r, 0.8, 1),0.0001);
	free(r);
}
示例#14
0
// Test evaluation
static void test_evaluation() {
  // Create the distribution
  gmcmc_prior * lognormal;
  CU_ASSERT(gmcmc_prior_create(&lognormal, gmcmc_prior_lognormal, 0.0, 1.0) == GMCMC_SUCCESS);

  CU_ASSERT_DOUBLE_EQUAL(gmcmc_prior_evaluate(lognormal, 1.0), 0.39894229, 1.e-8);
  CU_ASSERT_DOUBLE_EQUAL(gmcmc_prior_evaluate_1st_order(lognormal, 1.0), -1.0, 0.0);
  CU_ASSERT_DOUBLE_EQUAL(gmcmc_prior_evaluate_2nd_order(lognormal, 1.0),  0.0, 0.0);

  gmcmc_prior_destroy(lognormal);
}
示例#15
0
/**
* Pivot a pointlist into a dimlist and back.
* Test for data loss or alteration.
*/
static void
test_patch_dimensional()
{
	PCPOINT *pt;
	int i;
	int npts = 10;
	PCPOINTLIST *pl1, *pl2;
	PCPATCH_DIMENSIONAL *pdl;
	PCDIMSTATS *pds;

	pl1 = pc_pointlist_make(npts);

	for ( i = 0; i < npts; i++ )
	{
		pt = pc_point_make(simpleschema);
		pc_point_set_double_by_name(pt, "x", i*2.0);
		pc_point_set_double_by_name(pt, "y", i*1.9);
		pc_point_set_double_by_name(pt, "Z", i*0.34);
		pc_point_set_double_by_name(pt, "intensity", 10);
		pc_pointlist_add_point(pl1, pt);
	}

	pdl = pc_patch_dimensional_from_pointlist(pl1);
	pl2 = pc_pointlist_from_dimensional(pdl);

	for ( i = 0; i < npts; i++ )
	{
		pt = pc_pointlist_get_point(pl2, i);
		double v1, v2, v3, v4;
		pc_point_get_double_by_name(pt, "x", &v1);
		pc_point_get_double_by_name(pt, "y", &v2);
		pc_point_get_double_by_name(pt, "Z", &v3);
		pc_point_get_double_by_name(pt, "intensity", &v4);
		// printf("%g\n", v4);
		CU_ASSERT_DOUBLE_EQUAL(v1, i*2.0, 0.001);
		CU_ASSERT_DOUBLE_EQUAL(v2, i*1.9, 0.001);
		CU_ASSERT_DOUBLE_EQUAL(v3, i*0.34, 0.001);
		CU_ASSERT_DOUBLE_EQUAL(v4, 10, 0.001);
	}

	pds = pc_dimstats_make(simpleschema);
	pc_dimstats_update(pds, pdl);
	pc_dimstats_update(pds, pdl);


	pc_patch_free((PCPATCH*)pdl);
	pc_pointlist_free(pl1);
	pc_pointlist_free(pl2);
	pc_dimstats_free(pds);
}
示例#16
0
文件: cu_gdal.c 项目: ahinz/postgis
static void test_gdal_rasterize() {
	rt_raster raster;
	char srs[] = "PROJCS[\"unnamed\",GEOGCS[\"unnamed ellipse\",DATUM[\"unknown\",SPHEROID[\"unnamed\",6370997,0]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433]],PROJECTION[\"Lambert_Azimuthal_Equal_Area\"],PARAMETER[\"latitude_of_center\",45],PARAMETER[\"longitude_of_center\",-100],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0],UNIT[\"Meter\",1],AUTHORITY[\"EPSG\",\"2163\"]]";
	const char wkb_hex[] = "010300000001000000050000000000000080841ec100000000600122410000000080841ec100000000804f22410000000040e81dc100000000804f22410000000040e81dc100000000600122410000000080841ec10000000060012241";
	const char *pos = wkb_hex;
	unsigned char *wkb = NULL;
	int wkb_len = 0;
	int i;
	double scale_x = 100;
	double scale_y = -100;

	rt_pixtype pixtype[] = {PT_8BUI};
	double init[] = {0};
	double value[] = {1};
	double nodata[] = {0};
	uint8_t nodata_mask[] = {1};

	/* hex to byte */
	wkb_len = (int) ceil(((double) strlen(wkb_hex)) / 2);
	wkb = (unsigned char *) rtalloc(sizeof(unsigned char) * wkb_len);
	for (i = 0; i < wkb_len; i++) {
		sscanf(pos, "%2hhx", &wkb[i]);
		pos += 2;
	}

	raster = rt_raster_gdal_rasterize(
		wkb,
		wkb_len, srs,
		1, pixtype,
		init, value,
		nodata, nodata_mask,
		NULL, NULL,
		&scale_x, &scale_y,
		NULL, NULL,
		NULL, NULL,
		NULL, NULL,
		NULL
	);

	CU_ASSERT(raster != NULL);
	CU_ASSERT_EQUAL(rt_raster_get_width(raster), 100);
	CU_ASSERT_EQUAL(rt_raster_get_height(raster), 100);
	CU_ASSERT_NOT_EQUAL(rt_raster_get_num_bands(raster), 0);
	CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_offset(raster), -500000, DBL_EPSILON);
	CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_offset(raster), 600000, DBL_EPSILON);

	rtdealloc(wkb);
	cu_free_raster(raster);
}
示例#17
0
static void
test_affine()
{
	double a, b, c, d, e, f, g, h, i;
	double xoff, yoff, zoff;
	double angle;
	LIBOX4 ibox, *obox;

	// create the 4x3 affine matrix
	// rotation: pi/4 along x axis
	// scale: 2 along x axis
	// translation: 1 along x axis
	angle = M_PI_4;
	a = 2;
	b = 0;
	c = 0;
	xoff = 1;
	d = 0;
	e = cos(angle);
	f = -sin(angle);
	yoff = 0;
	g = 0;
	h = sin(angle);
	i = cos(angle);
	zoff = 0;

	// 3d box centered on (0, 0, 0)
	ibox[0][0] = -1.0;
	ibox[0][1] = -1.0;
	ibox[0][2] = 1.0;
	ibox[0][3] = 10.0;
	ibox[1][0] = 1.0;
	ibox[1][1] = 1.0;
	ibox[1][2] = -1.0;
	ibox[1][3] = 20.0;

	obox = li_box4d_affine(ibox, a, b, c, d, e, f, g, h, i, xoff, yoff, zoff);

	CU_ASSERT((*obox)[0][0] == -1.0);
	CU_ASSERT_DOUBLE_EQUAL((*obox)[0][1], -sqrt(2.0), 0.000001);
	CU_ASSERT_DOUBLE_EQUAL((*obox)[0][2], -sqrt(2.0), 0.000001);
	CU_ASSERT((*obox)[0][3] == 10.0);
	CU_ASSERT((*obox)[1][0] == 3.0);
	CU_ASSERT_DOUBLE_EQUAL((*obox)[1][1], sqrt(2.0), 0.000001);
	CU_ASSERT_DOUBLE_EQUAL((*obox)[1][2], sqrt(2.0), 0.000001);
	CU_ASSERT((*obox)[1][3] == 20.0);

	pcfree(obox);
}
示例#18
0
void get_seglightness_feature_test(){
   int width=10,height=15;
   image_hsl* imagehsl=image_hsl_new(width,height);
   int seglable[width*height];
   int lablenum=5;
   int i=0,j=0;
   fsegment_lightness feat;
   
   for(i=0;i<height/3;++i){
       for(j=0;j<width/2;++j){
           imagehsl->l[i*width+j]=0.1;
           seglable[i*width+j]=1;
       }
   }
   
   for(i=0;i<height/3;++i){
       for(j=width/2;j<width;++j){
           imagehsl->l[i*width+j]=0.2;
           seglable[i*width+j]=2;
       }
   }
   
   for(i=height/3;i<2*height/3;++i){
       for(j=0;j<width/2;++j){
           imagehsl->l[i*width+j]=0.3;
           seglable[i*width+j]=3;
       }
   }

   for(i=height/3;i<2*height/3;++i){
       for(j=width/2;j<width;++j){
           imagehsl->l[i*width+j]=0.4;
           seglable[i*width+j]=4;
       }
   }
   
   for(i=2*height/3;i<height;++i){
       for(j=0;j<width;++j){
           imagehsl->l[i*width+j]=0.5;
           seglable[i*width+j]=5;
       }
   }   
   feat=get_seglightness_feature(imagehsl,seglable,lablenum);
   image_hsl_delete(imagehsl);
   CU_ASSERT_DOUBLE_EQUAL(feat.mseg_ave,0.5,0.00001);
   CU_ASSERT_DOUBLE_EQUAL(feat.seg_ave_std,0.141421356,0.00001);
   CU_ASSERT_DOUBLE_EQUAL(feat.seg_ave_contrast,0.4,0.00001);
}
示例#19
0
static void test_raster_replace_band() {
	rt_raster raster;
	rt_band band;
	rt_band rband;
	void* mem;
	size_t datasize;
	uint16_t width;
	uint16_t height;
	double nodata;

	raster = rt_raster_new(10, 10);
	CU_ASSERT(raster != NULL); /* or we're out of virtual memory */
	band = cu_add_band(raster, PT_8BUI, 0, 0);
	CU_ASSERT(band != NULL);
	band = cu_add_band(raster, PT_8BUI, 1, 255);
	CU_ASSERT(band != NULL);

	width = rt_raster_get_width(raster);
	height = rt_raster_get_height(raster);

	datasize = rt_pixtype_size(PT_8BUI) * width * height;
	mem = rtalloc(datasize);
	band = rt_band_new_inline(width, height, PT_8BUI, 1, 1, mem);
	CU_ASSERT(band != NULL);
	rt_band_set_ownsdata_flag(band, 1);

	rband = rt_raster_replace_band(raster, band, 0);
	CU_ASSERT(rband != NULL);
	rt_band_get_nodata(rt_raster_get_band(raster, 0), &nodata);
	CU_ASSERT_DOUBLE_EQUAL(nodata, 1, DBL_EPSILON);

	rt_band_destroy(rband);
	cu_free_raster(raster);
}
示例#20
0
void testGet_sharpness_feautre() {
    image_hsl* hsl = image_hsl_new(4, 4);

	hsl->l[0] = 0.3;
	hsl->l[1] = 0.2;
	hsl->l[2] = 0.5;
	hsl->l[3] = 0.6;
	hsl->l[4] = 0.7;
	hsl->l[5] = 0.3;	
	hsl->l[6] = 0.5;
	hsl->l[7] = 0.4;
	hsl->l[8] = 0.1;	
	hsl->l[9] = 0.6;
	hsl->l[10] = 0.3;
	hsl->l[11] = 0.4;
	hsl->l[12] = 0.9;	
	hsl->l[13] = 0.5;
	hsl->l[14] = 0.2;
	hsl->l[15] = 0.1;	

	float feature = get_sharpness_feature(hsl);
	CU_ASSERT_DOUBLE_EQUAL(feature, -0.39758, 0.00001);

	image_hsl_delete(hsl);
}
示例#21
0
static void test_conv_angle_double(double expected, const struct nmea_angle_t * angle)
{
	double d;

	CU_ASSERT_EQUAL(nmea_angle_to_double(&d, angle), 0);
	CU_ASSERT_DOUBLE_EQUAL(d, expected, 1e-4);
}
示例#22
0
void testGet_rgb_simplicity_feautre() {
    image_rgb* rgb = image_rgb_new(2, 2);

	rgb->r[0] = 35;
	rgb->r[1] = 25;
	rgb->r[2] = 35;
	rgb->r[3] = 235;	
	
	rgb->g[0] = 39;
	rgb->g[1] = 85;
	rgb->g[2] = 45;
	rgb->g[3] = 115;	

	rgb->b[0] = 135;
	rgb->b[1] = 125;
	rgb->b[2] = 145;
	rgb->b[3] = 5;		

	frgb_simplicity feature = get_rgb_simplicity_feature(rgb);
	CU_ASSERT_EQUAL(feature.sig_pixels_num, 3);
	CU_ASSERT_DOUBLE_EQUAL(feature.ratio, 0.5, 0.00001);

	//free(feature);
	image_rgb_delete(rgb);	
    

}
void testMetodoCorrelacao() {
    int tempoCorrelacao = 21;
    double resultadoCorrelacao = metodoCorrelacao(tempoCorrelacao);
  
    CU_ASSERT_DOUBLE_EQUAL(0.748820,resultadoCorrelacao, 0.001 );
    
}
示例#24
0
void testGet_naturalness_feautre() {
    image_hsl* hsl = image_hsl_new(3, 2);
	hsl->h[0] = 0.15;
	hsl->h[1] = 0.1;
	hsl->h[2] = 0.7;
	hsl->h[3] = 0.3;
	hsl->h[4] = 0.1;
	hsl->h[5] = 0.8;

	hsl->s[0] = 0.2;
	hsl->s[1] = 0.1;
	hsl->s[2] = 0.7;
	hsl->s[3] = 0.8;	
	hsl->s[4] = 0.3;
	hsl->s[5] = 0.5;
	
	hsl->l[0] = 0.24;
	hsl->l[1] = 0.1;
	hsl->l[2] = 0.7;
	hsl->l[3] = 0.73;
	hsl->l[4] = 0.6;
	hsl->l[5] = 0.5;

	float feature = get_naturalness_feature(hsl);
	CU_ASSERT_DOUBLE_EQUAL(feature, 0.67678, 0.00001);

	image_hsl_delete(hsl);
}
示例#25
0
static void
test_sort_simple()
{
	// 00 endian (big)
	// 00000000 pcid
	// 00000000 compression
	// 00000002 npoints
	// 0000000800000003000000050006 pt1 (XYZi)
	// 0000000200000001000000040008 pt2 (XYZi)

	// init data
	PCPOINTLIST *lisort;
	PCPATCH *pasort;
	double d1;
	double d2;
	char *hexbuf = "0000000000000000000000000200000008000000030000000500060000000200000001000000040008";
	size_t hexsize = strlen(hexbuf);

	uint8_t *wkb = bytes_from_hexbytes(hexbuf, hexsize);
	PCPATCH *pa = pc_patch_from_wkb(schema, wkb, hexsize/2);
	PCPOINTLIST *li = pc_pointlist_from_patch(pa);
	const char *X[] = {"X"};

	// check that initial data are not sorted
	pc_point_get_double_by_name(pc_pointlist_get_point(li, 0), "X", &d1);
	pc_point_get_double_by_name(pc_pointlist_get_point(li, 1), "X", &d2);

	CU_ASSERT_DOUBLE_EQUAL(d1, 0.08, precision);
	CU_ASSERT_DOUBLE_EQUAL(d2, 0.02, precision);

	// sort on X attribute and check if data are well sorted
	pasort = pc_patch_sort(pa, X, 1);
	lisort = pc_pointlist_from_patch(pasort);

	pc_point_get_double_by_name(pc_pointlist_get_point(lisort, 0), "X", &d1);
	pc_point_get_double_by_name(pc_pointlist_get_point(lisort, 1), "X", &d2);

	CU_ASSERT_DOUBLE_EQUAL(d1, 0.02, precision);
	CU_ASSERT_DOUBLE_EQUAL(d2, 0.08, precision);

	// free
	pc_pointlist_free(li);
	pc_pointlist_free(lisort);
	pc_patch_free(pa);
	pc_patch_free(pasort);
	pcfree(wkb);
}
示例#26
0
void find_nearest_E12_test(float resistance_value, float expected_value)
{
  float actual_value = find_nearest_E12(resistance_value);

  printf("\nfind_nearest_E12_test::resistance: %.3f, actual value: %.3f, expected value: %.3f\n", resistance_value, actual_value, expected_value);
  //CU_ASSERT_STRING_EQUAL(actual_s, expected_s);
  CU_ASSERT_DOUBLE_EQUAL(actual_value, expected_value, GRANULARITY);
}
示例#27
0
void test_assign_and_get(void)
{
    double x[] = { 4, 7 };
    double y[] = { 3, 5 };
    unsigned long N = 8;
    struct py_field f = py_init_acoustic_field(N, N, x, y);
    unsigned long i, j;
    double val;

    /* used by macro indexing */
    double *p = f.p.value;
    double *u = f.u.value;
    double *v = f.v.value;
    unsigned long nx = N;

    for (unsigned n = 0; n < 1000; ++n) {
        i = rand() % N;
        j = rand() % N;
        val = (double) rand();
        py_assign_to(f.p, i, j, val);
        CU_ASSERT_DOUBLE_EQUAL(f.p.value[i + j * N], val, TOL);
        CU_ASSERT_DOUBLE_EQUAL(f.p.value[i + j * N],
                               py_get_from(f.p, i, j), TOL);
        CU_ASSERT_DOUBLE_EQUAL(P(i, j), val, TOL);
    }

    for (unsigned n = 0; n < 1000; ++n) {
        i = rand() % (N + 1);
        j = rand() % N;
        val = (double) rand();
        py_assign_to(f.u, i, j, val);
        CU_ASSERT_DOUBLE_EQUAL(f.u.value[i + j * (N + 1)], val, TOL);
        CU_ASSERT_DOUBLE_EQUAL(f.u.value[i + j * (N + 1)],
                               py_get_from(f.u, i, j), TOL);
        CU_ASSERT_DOUBLE_EQUAL(U(i, j), val, TOL);
    }

    for (unsigned n = 0; n < 1000; ++n) {
        i = rand() % N;
        j = rand() % (N + 1);
        val = (double) rand();
        py_assign_to(f.v, i, j, val);
        CU_ASSERT_DOUBLE_EQUAL(f.v.value[i + j * N], val, TOL);
        CU_ASSERT_DOUBLE_EQUAL(f.v.value[i + j * N],
                               py_get_from(f.v, i, j), TOL);
        CU_ASSERT_DOUBLE_EQUAL(V(i, j), val, TOL);
    }

    py_free_acoustic_field(f);
}
示例#28
0
static void
test_endian_flip()
{
	PCPOINT *pt;
	double a1, a2, a3, a4, b1, b2, b3, b4;
	int rv;
	uint8_t *ptr;

	/* All at once */
	pt = pc_point_make(schema);
	a1 = 1.5;
	a2 = 1501500.12;
	a3 = 19112;
	a4 = 200;
	rv = pc_point_set_double_by_name(pt, "X", a1);
	CU_ASSERT_EQUAL(rv, PC_SUCCESS);
	rv = pc_point_set_double_by_name(pt, "Z", a2);
	CU_ASSERT_EQUAL(rv, PC_SUCCESS);
	rv = pc_point_set_double_by_name(pt, "Intensity", a3);
	CU_ASSERT_EQUAL(rv, PC_SUCCESS);
	rv = pc_point_set_double_by_name(pt, "UserData", a4);
	CU_ASSERT_EQUAL(rv, PC_SUCCESS);
	rv = pc_point_get_double_by_name(pt, "X", &b1);
	CU_ASSERT_EQUAL(rv, PC_SUCCESS);
	rv = pc_point_get_double_by_name(pt, "Z", &b2);
	CU_ASSERT_EQUAL(rv, PC_SUCCESS);
	rv = pc_point_get_double_by_name(pt, "Intensity", &b3);
	CU_ASSERT_EQUAL(rv, PC_SUCCESS);
	rv = pc_point_get_double_by_name(pt, "UserData", &b4);
	CU_ASSERT_EQUAL(rv, PC_SUCCESS);
	CU_ASSERT_DOUBLE_EQUAL(a1, b1, 0.0000001);
	CU_ASSERT_DOUBLE_EQUAL(a2, b2, 0.0000001);
	CU_ASSERT_DOUBLE_EQUAL(a3, b3, 0.0000001);
	CU_ASSERT_DOUBLE_EQUAL(a4, b4, 0.0000001);

	ptr = uncompressed_bytes_flip_endian(pt->data, schema, 1);
	pcfree(pt->data);
	pt->data = uncompressed_bytes_flip_endian(ptr, schema, 1);
	pcfree(ptr);

	rv = pc_point_get_double_by_name(pt, "X", &b1);
	CU_ASSERT_EQUAL(rv, PC_SUCCESS);
	rv = pc_point_get_double_by_name(pt, "Z", &b2);
	CU_ASSERT_EQUAL(rv, PC_SUCCESS);
	rv = pc_point_get_double_by_name(pt, "Intensity", &b3);
	CU_ASSERT_EQUAL(rv, PC_SUCCESS);
	rv = pc_point_get_double_by_name(pt, "UserData", &b4);
	CU_ASSERT_EQUAL(rv, PC_SUCCESS);
	CU_ASSERT_DOUBLE_EQUAL(a1, b1, 0.0000001);
	CU_ASSERT_DOUBLE_EQUAL(a2, b2, 0.0000001);
	CU_ASSERT_DOUBLE_EQUAL(a3, b3, 0.0000001);
	CU_ASSERT_DOUBLE_EQUAL(a4, b4, 0.0000001);

	pc_point_free(pt);
}
示例#29
0
void test_create_2x2_n3_lattice() {
	lattice *lat = create_lattice(2,2,3,2.1);
	CU_ASSERT_EQUAL(lat->l1,2);
	CU_ASSERT_EQUAL(lat->l2,2);
	CU_ASSERT_EQUAL(lat->n,3);
	CU_ASSERT_DOUBLE_EQUAL(lat->beta,2.1,0);
	/* Lattice configuration not tested since they are random */
	destroy_lattice(lat);
}
示例#30
0
void check_dgemm(double *a, double *b, double *result, double *expected, int n)
{
    int i;
    cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, n, n, n,
        1.0, a, n, b, n, 0.0, result, n);
    for(i = 0; i < n * n; ++i) {
        CU_ASSERT_DOUBLE_EQUAL(expected[i], result[i], CHECK_EPS);
    }
}