@@ -36,21 +36,29 @@ float RoundToNearestTieToEven(float in, int precisionDigits)
3636
3737const double ROCKLIST_FILE_VERSION = 2.0 ;
3838
39- int write_rocklist_header (FILE * fp_out , RD_PARMS * rd_parms )
40- {
39+ static void write_header_float (FILE * fp_out , const char * name , float val , const char * negative ) {
40+ if (val >=0 ) fprintf (fp_out , "%%%s %f\n" , name , val );
41+ else fprintf (fp_out , "%%%s %s\n" , name , negative );
42+ }
4143
44+ static void write_header_int (FILE * fp_out , const char * name , int val , const char * negative ) {
45+ if (val >=0 || negative == NULL ) fprintf (fp_out , "%%%s %d\n" , name , val );
46+ else fprintf (fp_out , "%%%s %s\n" , name , negative );
47+ }
48+ int write_rocklist_header (FILE * fp_out , RD_PARMS * rd_parms , const char * negative )
49+ {
4250 fprintf (fp_out , "version %f\n" , ROCKLIST_FILE_VERSION );
43- fprintf (fp_out , "%% GSD_resolution %f\n " , rd_parms -> ground_resolution );
44- fprintf (fp_out , "%% gamma %f\n " , rd_parms -> gamma );
45- fprintf (fp_out , "%% sun_azimuth_angle %f\n " , rd_parms -> sun_azimuth_angle );
46- fprintf (fp_out , "%% sun_incidence_angle %f\n " , rd_parms -> sun_incidence_angle );
47- fprintf (fp_out , "%% min_shadow_size %f\n " , rd_parms -> min_shadow_size );
48- fprintf (fp_out , "%% max_shadow_size %f\n " , rd_parms -> max_shadow_size );
49- fprintf (fp_out , "%% confidence_threshold %f\n " , rd_parms -> confidence_threshold );
50- fprintf (fp_out , "%% min_split_shadow_size %f\n " , rd_parms -> min_shadow_size_split );
51- fprintf (fp_out , "%% mean_gradient %f\n " , rd_parms -> mean_gradient_threshold );
52- fprintf (fp_out , "%%shadow excentricity %f\n " , rd_parms -> rock_elongate_ratio );
53- fprintf (fp_out , "%% gamma_threshold_override %d\n " , rd_parms -> gamma_threshold_override );
51+ write_header_float (fp_out , "GSD_resolution" , rd_parms -> ground_resolution , negative );
52+ write_header_float (fp_out , "gamma" , rd_parms -> gamma , negative );
53+ write_header_float (fp_out , "sun_azimuth_angle" , rd_parms -> sun_azimuth_angle , negative );
54+ write_header_float (fp_out , "sun_incidence_angle" , rd_parms -> sun_incidence_angle , negative );
55+ write_header_float (fp_out , "min_shadow_size" , rd_parms -> min_shadow_size , negative );
56+ write_header_float (fp_out , "max_shadow_size" , rd_parms -> max_shadow_size , negative );
57+ write_header_float (fp_out , "confidence_threshold" , rd_parms -> confidence_threshold , negative );
58+ write_header_float (fp_out , "min_split_shadow_size" , rd_parms -> min_shadow_size_split , negative );
59+ write_header_float (fp_out , "mean_gradient" , rd_parms -> mean_gradient_threshold , negative );
60+ write_header_float (fp_out , "shadow_eccentricity " , rd_parms -> rock_elongate_ratio , negative );
61+ write_header_int (fp_out , "gamma_threshold_override" , rd_parms -> gamma_threshold_override , negative );
5462 fprintf (fp_out , "id, tileR, tileC, shaX, shaY, rockX, rockY, tileShaX, tileShaY, shaArea, shaLen, rockWidth, rockHeight, score, gradMean, Compact, Exent, Class, gamma\n" );
5563 fflush (stdout );
5664
@@ -84,13 +92,13 @@ int read_rocklist_header_v1(FILE* fp_in, RD_PARMS* rd_parms)
8492 read = fscanf (fp_in , "%%confidence_threshold %f\n" , & rd_parms -> confidence_threshold );
8593 if (read != 1 ) { printf ("error reading file. quitting. \n" ); fclose (fp_in ); return FALSE; }
8694
87- read = fscanf (fp_in , "%%min_split_shadow_size %f\n" , & rd_parms -> min_shadow_size_split );
95+ read = fscanf (fp_in , "%%min_split_shadow_size %f\n" , & rd_parms -> min_shadow_size_split );
8896 if (read != 1 ) { printf ("error reading file. quitting. \n" ); fclose (fp_in ); return FALSE; }
8997
90- read = fscanf (fp_in , "%%mean_gradient %f\n" , & rd_parms -> mean_gradient_threshold );
98+ read = fscanf (fp_in , "%%mean_gradient %f\n" , & rd_parms -> mean_gradient_threshold );
9199 if (read != 1 ) { printf ("error reading file. quitting. \n" ); fclose (fp_in ); return FALSE; }
92100
93- read = fscanf (fp_in , "%%shadow excentricity %f\n" , & rd_parms -> rock_elongate_ratio );
101+ read = fscanf (fp_in , "%%shadow_eccentricity %f\n" , & rd_parms -> rock_elongate_ratio );
94102 if (read != 1 ) { printf ("error reading file. quitting. \n" ); fclose (fp_in ); return FALSE; }
95103
96104 read = fscanf (fp_in , "%%gamma_threshold_override %d\n" , & rd_parms -> gamma_threshold_override );
@@ -150,13 +158,13 @@ int read_rocklist_header(FILE* fp_in, RD_PARMS* rd_parms)
150158 read = fscanf (fp_in , "%%confidence_threshold %f\n" , & rd_parms -> confidence_threshold );
151159 if (read != 1 ) { printf ("error reading file. quitting. \n" ); fclose (fp_in ); return FALSE; }
152160
153- read = fscanf (fp_in , "%%min_split_shadow_size %f\n" , & rd_parms -> min_shadow_size_split );
161+ read = fscanf (fp_in , "%%min_split_shadow_size %f\n" , & rd_parms -> min_shadow_size_split );
154162 if (read != 1 ) { printf ("error reading file. quitting. \n" ); fclose (fp_in ); return FALSE; }
155163
156- read = fscanf (fp_in , "%%mean_gradient %f\n" , & rd_parms -> mean_gradient_threshold );
164+ read = fscanf (fp_in , "%%mean_gradient %f\n" , & rd_parms -> mean_gradient_threshold );
157165 if (read != 1 ) { printf ("error reading file. quitting. \n" ); fclose (fp_in ); return FALSE; }
158166
159- read = fscanf (fp_in , "%%shadow excentricity %f\n" , & rd_parms -> rock_elongate_ratio );
167+ read = fscanf (fp_in , "%%shadow_eccentricity %f\n" , & rd_parms -> rock_elongate_ratio );
160168 if (read != 1 ) { printf ("error reading file. quitting. \n" ); fclose (fp_in ); return FALSE; }
161169
162170 read = fscanf (fp_in , "%%gamma_threshold_override %d\n" , & rd_parms -> gamma_threshold_override );
@@ -563,50 +571,52 @@ int detect_per_tile_settings(char* inputImagePath, char* outputRockListPath, int
563571 }
564572
565573 RD_PARMS params ;
566- params .gamma = 0 .0f ;
567- params .sun_incidence_angle = 0 .0f ;
568- params .sun_azimuth_angle = 0 .0f ;
569- params .min_shadow_size = 0 .0f ;
570- params .ground_resolution = 0 .0f ;
571- params .confidence_threshold = 0 .0f ;
572- params .min_shadow_size_split = 0 .0f ;
573- params .spliting_ratio = 0 .0f ;
574- params .rock_elongate_ratio = 0 .0f ;
575- params .mean_gradient_threshold = 0 .0f ;
576- params .max_shadow_size = 0 .0f ;
577- params .gamma_threshold_override = 0 ;
574+ params .gamma = -1 .0f ;
575+ params .sun_incidence_angle = -1 .0f ;
576+ params .sun_azimuth_angle = -1 .0f ;
577+ params .min_shadow_size = -1 .0f ;
578+ params .ground_resolution = -1 .0f ;
579+ params .confidence_threshold = -1 .0f ;
580+ params .min_shadow_size_split = -1 .0f ;
581+ params .spliting_ratio = -1 .0f ;
582+ params .rock_elongate_ratio = -1 .0f ;
583+ params .mean_gradient_threshold = -1 .0f ;
584+ params .max_shadow_size = -1 .0f ;
585+ params .gamma_threshold_override = -1 ;
578586
579587 if (numSettings > 0 ) {
580- RD_PARMS * first = NULL ;
581- int all_same = 1 ;
582- for (int i = 0 ; i < numSettings ; i ++ ) {
588+ RD_PARMS * first = & settingsArray [0 ];
589+ params .gamma = first -> gamma ;
590+ params .sun_incidence_angle = first -> sun_incidence_angle ;
591+ params .sun_azimuth_angle = first -> sun_azimuth_angle ;
592+ params .min_shadow_size = first -> min_shadow_size ;
593+ params .ground_resolution = first -> ground_resolution ;
594+ params .confidence_threshold = first -> confidence_threshold ;
595+ params .min_shadow_size_split = first -> min_shadow_size_split ;
596+ params .spliting_ratio = first -> spliting_ratio ;
597+ params .rock_elongate_ratio = first -> rock_elongate_ratio ;
598+ params .mean_gradient_threshold = first -> mean_gradient_threshold ;
599+ params .max_shadow_size = first -> max_shadow_size ;
600+ params .gamma_threshold_override = first -> gamma_threshold_override ;
601+
602+ for (int i = 1 ; i < numSettings ; i ++ ) {
583603 RD_PARMS * p = & settingsArray [i ];
584- if (p -> max_shadow_size <= 0 ) continue ;
585- if (first == NULL ) first = p ;
586- else if (p -> gamma != first -> gamma ||
587- p -> sun_incidence_angle != first -> sun_incidence_angle ||
588- p -> sun_azimuth_angle != first -> sun_azimuth_angle ||
589- p -> min_shadow_size != first -> min_shadow_size ||
590- p -> ground_resolution != first -> ground_resolution ||
591- p -> confidence_threshold != first -> confidence_threshold ||
592- p -> min_shadow_size_split != first -> min_shadow_size_split ||
593- p -> spliting_ratio != first -> spliting_ratio ||
594- p -> rock_elongate_ratio != first -> rock_elongate_ratio ||
595- p -> mean_gradient_threshold != first -> mean_gradient_threshold ||
596- p -> max_shadow_size != first -> max_shadow_size ||
597- p -> gamma_threshold_override != first -> gamma_threshold_override ) {
598- // this tile has different settings per tile, can't write a meaningful header
599- all_same = 0 ;
600- break ;
601- }
602- }
603- if (all_same && first != NULL ) {
604- printf ("All tiles have same settings.\n" );
605- params = * first ;
604+ if (p -> gamma != params .gamma ) params .gamma = -1 ; //different per tile
605+ if (p -> sun_incidence_angle != params .sun_incidence_angle ) params .sun_incidence_angle = -1 ;
606+ if (p -> sun_azimuth_angle != params .sun_azimuth_angle ) params .sun_azimuth_angle = -1 ;
607+ if (p -> min_shadow_size != params .min_shadow_size ) params .min_shadow_size = -1 ;
608+ if (p -> ground_resolution != params .ground_resolution ) params .ground_resolution = -1 ;
609+ if (p -> confidence_threshold != params .confidence_threshold ) params .confidence_threshold = -1 ;
610+ if (p -> min_shadow_size_split != params .min_shadow_size_split ) params .min_shadow_size_split = -1 ;
611+ if (p -> spliting_ratio != params .spliting_ratio ) params .spliting_ratio = -1 ;
612+ if (p -> rock_elongate_ratio != params .rock_elongate_ratio ) params .rock_elongate_ratio = -1 ;
613+ if (p -> mean_gradient_threshold != params .mean_gradient_threshold ) params .mean_gradient_threshold = -1 ;
614+ if (p -> max_shadow_size != params .max_shadow_size ) params .max_shadow_size = -1 ;
615+ if (p -> gamma_threshold_override != params .gamma_threshold_override ) params .gamma_threshold_override = -1 ;
606616 }
607617 }
608618
609- write_rocklist_header (fp_out , & params );
619+ write_rocklist_header (fp_out , & params , "varies" );
610620
611621 //intialize rock pixel output file
612622 char outputPixelPath [1024 ];
@@ -1071,7 +1081,7 @@ int detect_from_files(char* inputImagePath, char* paramsPath, char* outputRockLi
10711081 return 0 ;
10721082 }
10731083
1074- write_rocklist_header (fp_out , & rd_parms );
1084+ write_rocklist_header (fp_out , & rd_parms , NULL );
10751085
10761086 //intialize rock pixel output file
10771087 char outputPixelPath [1024 ];
0 commit comments