interimage:creating_operators
Diferenças
Aqui você vê as diferenças entre duas revisões dessa página.
Ambos lados da revisão anteriorRevisão anteriorPróxima revisão | Revisão anterior | ||
interimage:creating_operators [2009/10/08 14:16] – tkorting | interimage:creating_operators [2009/12/03 19:35] (atual) – gilson | ||
---|---|---|---|
Linha 1: | Linha 1: | ||
- | ====== Creating an operator ====== | + | [[interimage: |
+ | ====== | ||
TerraAIDA project aims to build InterIMAGE operators using the TerraLib library following the GNU LGLP license model. More information at http:// | TerraAIDA project aims to build InterIMAGE operators using the TerraLib library following the GNU LGLP license model. More information at http:// | ||
Linha 18: | Linha 19: | ||
The operator main file will call the operator function, which checks the parameters and produces the output. The operator function header can also communicate with InterIMAGE GUI in order to be called directly. Here we create a simple operator, which gets an image by input, and outputs the regions according a certain threshold defined by the user. | The operator main file will call the operator function, which checks the parameters and produces the output. The operator function header can also communicate with InterIMAGE GUI in order to be called directly. Here we create a simple operator, which gets an image by input, and outputs the regions according a certain threshold defined by the user. | ||
+ | Download source-code {{interimage: | ||
+ | |||
+ | ===== Operator .op file ===== | ||
+ | |||
+ | The following code represents the .op file to be loaded into InterIMAGE GUI. | ||
+ | |||
+ | <code xml> | ||
+ | < | ||
+ | cmd=" | ||
+ | runglobal=false tip=" | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | The resultant set of parameters will appear in InterIMAGE like the next figure. | ||
+ | |||
+ | {{interimage: | ||
===== Operator Main File ===== | ===== Operator Main File ===== | ||
Linha 45: | Linha 67: | ||
<code c++> | <code c++> | ||
+ | #ifndef TAEXECTHRESHOLD_HPP | ||
+ | #define TAEXECTHRESHOLD_HPP | ||
+ | | ||
+ | namespace TerraAIDA | ||
+ | { | ||
+ | /** | ||
+ | * @brief TerraAIDA threshold operator function. | ||
+ | * @param argc Arguments count. | ||
+ | * @param argv Arguments strings. | ||
+ | * @return EXIT_FAILURE or EXIT_SUCCESS | ||
+ | | ||
+ | int execTAThreshold( int argc, char ** argv ); | ||
+ | } | ||
+ | | ||
+ | # | ||
</ | </ | ||
Linha 50: | Linha 87: | ||
<code c++> | <code c++> | ||
+ | #include " | ||
+ | #include " | ||
+ | |||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | namespace TerraAIDA | ||
+ | { | ||
+ | int execTAThreshold( int argc, char ** argv ) | ||
+ | { | ||
+ | try | ||
+ | { | ||
+ | // read input | ||
+ | // process input | ||
+ | // generate output | ||
+ | } | ||
+ | catch( const TeException& | ||
+ | TEAGN_LOGERR( e.message() ) | ||
+ | return EXIT_FAILURE; | ||
+ | } | ||
+ | catch( ... ) { | ||
+ | TEAGN_LOGERR( " | ||
+ | return EXIT_FAILURE; | ||
+ | } | ||
+ | | ||
+ | TEAGN_LOGMSG( " | ||
+ | return EXIT_SUCCESS; | ||
+ | } | ||
+ | |||
+ | } | ||
</ | </ | ||
+ | ==== Reading Input ==== | ||
+ | |||
+ | <code c++> | ||
+ | /* Extracting system default parameters */ | ||
+ | | ||
+ | int param_index = 1; | ||
+ | | ||
+ | const double geoWest = atof( argv[ param_index ] ); | ||
+ | ++param_index; | ||
+ | | ||
+ | const double geoNorth = atof( argv[ param_index ] ); | ||
+ | ++param_index; | ||
+ | | ||
+ | const double geoEast = atof( argv[ param_index ] ); | ||
+ | ++param_index; | ||
+ | | ||
+ | const double geoSouth = atof( argv[ param_index ] ); | ||
+ | ++param_index; | ||
+ | | ||
+ | const std::string output = argv[ param_index ]; | ||
+ | ++param_index; | ||
+ | | ||
+ | const std::string class_str = argv[ param_index ]; | ||
+ | ++param_index; | ||
+ | | ||
+ | const std::string tmpdir = argv[ param_index ]; | ||
+ | ++param_index; | ||
+ | | ||
+ | bool use_mask = true; | ||
+ | const std::string mask_file = argv[ param_index ]; | ||
+ | if( mask_file.empty() ) use_mask = false; | ||
+ | ++param_index; | ||
+ | | ||
+ | /* Extracting user parameters */ | ||
+ | | ||
+ | const std::string image_name = argv[ param_index ]; | ||
+ | ++param_index; | ||
+ | TEAGN_TRUE_OR_THROW( image_name.find( ";" | ||
+ | image_name.npos, | ||
+ | | ||
+ | const int image_channel = atoi( argv[ param_index ] ); | ||
+ | ++param_index; | ||
+ | | ||
+ | const double treshold_min = atof( argv[ param_index ] ); | ||
+ | ++param_index; | ||
+ | | ||
+ | const double treshold_max = atof( argv[ param_index ] ); | ||
+ | ++param_index; | ||
+ | | ||
+ | const double node_weight = atof( argv[ param_index ] ); | ||
+ | ++param_index; | ||
+ | | ||
+ | </ | ||
+ | |||
+ | ==== Processing Input ==== | ||
+ | |||
+ | <code c++> | ||
+ | /* output image file names */ | ||
+ | | ||
+ | const std::string output_image_file_name = output + | ||
+ | " | ||
+ | |||
+ | /* Initiating image_name image */ | ||
+ | | ||
+ | TePDITypes:: | ||
+ | TePDITypes:: | ||
+ | { | ||
+ | image_ptr.reset( | ||
+ | new TeRaster( image_name, ' | ||
+ | TEAGN_TRUE_OR_THROW( image_ptr-> | ||
+ | " | ||
+ | | ||
+ | TEAGN_TRUE_OR_THROW( | ||
+ | ( image_channel < image_ptr-> | ||
+ | " | ||
+ | | ||
+ | std:: | ||
+ | image_channels_vec.push_back( image_channel ); | ||
+ | | ||
+ | TEAGN_TRUE_OR_THROW( OpSupportFunctions:: | ||
+ | image_ptr, image_channels_vec, | ||
+ | geoWest, geoNorth, geoEast, geoSouth, image_clip_ptr ), | ||
+ | "Error clipping raster" | ||
+ | } | ||
+ | | ||
+ | /* Initiating mask image */ | ||
+ | |||
+ | TePDITypes:: | ||
+ | if( use_mask ) { | ||
+ | TEAGN_TRUE_OR_THROW( OpSupportFunctions:: | ||
+ | mask_file, geoWest, geoNorth, geoEast, geoSouth, | ||
+ | mask_raster_ptr ), " | ||
+ | } | ||
+ | | ||
+ | /* Bring all rasters to match dimentions */ | ||
+ | | ||
+ | { | ||
+ | TePDITypes:: | ||
+ | input_rasters_vec.push_back( image_clip_ptr ); | ||
+ | TePDITypes:: | ||
+ | | ||
+ | if( use_mask ) | ||
+ | { | ||
+ | TEAGN_TRUE_OR_THROW( OpSupportFunctions:: | ||
+ | mask_raster_ptr-> | ||
+ | mask_raster_ptr-> | ||
+ | input_rasters_vec, | ||
+ | "Error resampling rasters" | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | TEAGN_TRUE_OR_THROW( OpSupportFunctions:: | ||
+ | input_rasters_vec, | ||
+ | "Error resampling rasters" | ||
+ | } | ||
+ | | ||
+ | image_clip_ptr = output_rasters_vec[ 0 ]; | ||
+ | } | ||
+ | |||
+ | /* allocating threshold raster */ | ||
+ | | ||
+ | TePDITypes:: | ||
+ | { | ||
+ | TeRasterParams thres_raster_params = | ||
+ | image_clip_ptr-> | ||
+ | thres_raster_params.nBands( 1 ); | ||
+ | thres_raster_params.setDataType( TeUNSIGNEDCHAR, | ||
+ | | ||
+ | TEAGN_TRUE_OR_THROW( OpSupportFunctions:: | ||
+ | thres_raster_params, | ||
+ | "Error creating threshold ram raster" | ||
+ | } | ||
+ | | ||
+ | /* limiarizing | ||
+ | value 0 - no-data | ||
+ | value 1 - data | ||
+ | */ | ||
+ | | ||
+ | { | ||
+ | const unsigned int lines = (unsigned int)image_clip_ptr-> | ||
+ | const unsigned int cols = (unsigned int)image_clip_ptr-> | ||
+ | unsigned int line = 0; | ||
+ | unsigned int col = 0; | ||
+ | double mask_value = 1.0; | ||
+ | double thr_value = 0; | ||
+ | double arith_value = 0; | ||
+ | | ||
+ | for( ; line < lines ; ++line ) { | ||
+ | for( col = 0 ; col < cols ; ++col ) { | ||
+ | if( use_mask ) { | ||
+ | mask_raster_ptr-> | ||
+ | | ||
+ | if( mask_value != 0 ) | ||
+ | { | ||
+ | thr_value = 0; | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | if( image_clip_ptr-> | ||
+ | arith_value, | ||
+ | { | ||
+ | if( ( arith_value > treshold_min ) && | ||
+ | ( arith_value < treshold_max ) ) | ||
+ | { | ||
+ | thr_value = 1; | ||
+ | } else { | ||
+ | thr_value = 0; | ||
+ | } | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | thr_value = 0; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | else // there is no mask | ||
+ | { | ||
+ | if( image_clip_ptr-> | ||
+ | 0 ) ) | ||
+ | { | ||
+ | if( ( arith_value > treshold_min ) && | ||
+ | ( arith_value < treshold_max ) ) | ||
+ | { | ||
+ | thr_value = 1; | ||
+ | } else { | ||
+ | thr_value = 0; | ||
+ | } | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | thr_value = 0; | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | thres_raster_ptr-> | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | /* Free unused resources */ | ||
+ | | ||
+ | mask_raster_ptr.reset(); | ||
+ | | ||
+ | /* Vectorizing the thres_raster_ptr */ | ||
+ | | ||
+ | OpSupportFunctions:: | ||
+ | { | ||
+ | // Preparing vector | ||
+ | | ||
+ | const std::string nClassStr = " | ||
+ | | ||
+ | regions_data_vector.push_back( OpSupportFunctions:: | ||
+ | regions_data_vector.push_back( OpSupportFunctions:: | ||
+ | | ||
+ | OpSupportFunctions:: | ||
+ | classNode.class_id_ = class_str; | ||
+ | classNode.class_value_ = 1; | ||
+ | | ||
+ | OpSupportFunctions:: | ||
+ | nClassNode.class_id_ = nClassStr; | ||
+ | nClassNode.class_value_ = 2; | ||
+ | | ||
+ | // Vectorizing | ||
+ | | ||
+ | TePDITypes:: | ||
+ | new TePDITypes:: | ||
+ | | ||
+ | TePDIParameters algo_params; | ||
+ | | ||
+ | algo_params.SetParameter( " | ||
+ | thres_raster_ptr ); | ||
+ | | ||
+ | algo_params.SetParameter( " | ||
+ | algo_params.SetParameter( " | ||
+ | | ||
+ | TePDIRaster2Vector vectorizer_instance; | ||
+ | | ||
+ | TEAGN_TRUE_OR_THROW( vectorizer_instance.Reset( algo_params ), | ||
+ | " | ||
+ | | ||
+ | TEAGN_TRUE_OR_THROW( vectorizer_instance.Apply(), | ||
+ | " | ||
+ | | ||
+ | /* re-ordering polygons and filtering out polygons with area smaller | ||
+ | than area_min */ | ||
+ | |||
+ | unsigned int curr_pol_nmb = 1; | ||
+ | | ||
+ | TePDITypes:: | ||
+ | aux_output_polsets-> | ||
+ | TePDITypes:: | ||
+ | aux_output_polsets-> | ||
+ | TePolygonSet:: | ||
+ | TePolygonSet:: | ||
+ | | ||
+ | while( map_it != map_it_end ) { | ||
+ | if( map_it-> | ||
+ | ps_it = map_it-> | ||
+ | ps_it_end = map_it-> | ||
+ | |||
+ | while( ps_it != ps_it_end ) { | ||
+ | TePolygon& | ||
+ | classNode.pols_.add( curr_pol ); | ||
+ | ++curr_pol_nmb; | ||
+ | ++ps_it; | ||
+ | } | ||
+ | } else if( map_it-> | ||
+ | ps_it = map_it-> | ||
+ | ps_it_end = map_it-> | ||
+ | |||
+ | while( ps_it != ps_it_end ) { | ||
+ | TePolygon& | ||
+ | nClassNode.pols_.add( curr_pol ); | ||
+ | ++curr_pol_nmb; | ||
+ | ++ps_it; | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | ++map_it; | ||
+ | } | ||
+ | | ||
+ | /* Updating the polygons indexed boxes */ | ||
+ | |||
+ | | ||
+ | | ||
+ | " | ||
+ | |||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Generating the Output ==== | ||
+ | |||
+ | <code c++> | ||
+ | /* Generating the output labeled image */ | ||
+ | TEAGN_TRUE_OR_THROW( OpSupportFunctions:: | ||
+ | output_image_file_name, | ||
+ | "Error saving label image" ) | ||
+ | | ||
+ | /* Generating output polygons file */ | ||
+ | TEAGN_TRUE_OR_THROW( OpSupportFunctions:: | ||
+ | output, regions_data_vector, | ||
+ | node_weight, | ||
+ | geoWest, geoNorth, geoEast, geoSouth ), | ||
+ | " | ||
+ | </ |
interimage/creating_operators.1255011415.txt.gz · Última modificação: 2009/10/08 14:16 por tkorting