| TerraLib 4.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

E:/Projetos_Primeiro_Semestre_2012/TerraView/terralib/src/terralib/image_processing/TePDIBaatz.hpp
Go to the documentation of this file.

    00001 /*
    00002 TerraLib - a library for developing GIS applications.
    00003 Copyright  2001, 2002, 2003 INPE and Tecgraf/PUC-Rio.
    00004
    00005 This code is part of the TerraLib library.
    00006 This library is free software; you can redistribute it and/or
    00007 modify it under the terms of the GNU Lesser General Public
    00008 License as published by the Free Software Foundation; either
    00009 version 2.1 of the License, or (at your option) any later version.
    00010
    00011 You should have received a copy of the GNU Lesser General Public
    00012 License along with this library.
    00013
    00014 The authors reassure the license terms regarding the warranties.
    00015 They specifically disclaim any warranties, including, but not limited to,
    00016 the implied warranties of merchantability and fitness for a particular
    00017 purpose. The library provided hereunder is on an "as is" basis, and the
    00018 authors have no obligation to provide maintenance, support, updates,
    00019 enhancements, or modifications.
    00020 In no event shall INPE be held liable to any party
    00021 for direct, indirect, special, incidental, or consequential damages arising
    00022 out of the use of this library and its documentation.
    00023 */
    00024
    00025 #ifndef TEPDIBAATZ_HPP
    00026   #define TEPDIBAATZ_HPP
    00027
    00028   // Internal defines
    00029   #define MAX_STEPS 20 /* maximum number of segmentation steps */
    00030   #define NUM_BANDS 10 /* number of image bands */
    00031   #define POSITION_SEARCH 0.00 /* minimum percentage of unused segments for segment selection by pixel position */
    00032   #define OUTLINE_COLOR_0 255 /* segments' outline color for output image */
    00033   #define OUTLINE_COLOR_1 000
    00034   #define OUTLINE_COLOR_2 000
    00035
    00036   // TerraLib includes
    00037   #include "TePDIAlgorithm.hpp"
    00038   #include "TePDITypes.hpp"
    00039   #include "TePDIPIManager.hpp"
    00040   #include "TePDIUtils.hpp"
    00041   #include "../kernel/TeSharedPtr.h"
    00042
    00075 /**********************************************************************************/
    00076 /* TerraLib main class for Baatz Segmentation                                     */
    00077 /**********************************************************************************/
    00078
    00079   class PDI_DLL TePDIBaatz : public TePDIAlgorithm {
    00080     public :
    00081
    00086       TePDIBaatz();
    00087
    00091              ~TePDIBaatz() {};
    00092
    00102       bool CheckParameters( const TePDIParameters& parameters ) const;
    00103
    00104   protected:
    00110       void ResetState( const TePDIParameters& );
    00111
    00117       bool RunImplementation();
    00118
    00119   };
    00120
    00126 /**********************************************************************************/
    00127 /* Internal definitions Baatz Segmentation                                        */
    00128 /**********************************************************************************/
    00129
    00130 /**********************************************************************************/
    00131 /* type definitions                                                               */
    00132 /**********************************************************************************/
    00133
    00134 /* node of list of segments' pixels */
    00135 struct segment_pixel
    00136 {
    00137   unsigned long int pixel_id; /* pixel id */
    00138   bool borderline; /* indicates if the pixel belongs to the border of the segment */
    00139   struct segment_pixel *next_pixel; /* next pixel */
    00140 };
    00141
    00142 /* node of segment list */
    00143 struct segment
    00144 {
    00145   unsigned long int id; /* segment id */
    00146   float area; /* number of pixels in segment */
    00147   float perimeter; /*number of border pixels */
    00148   float b_box[4]; /* bounding box of the segment, relative to rows and cols */
    00149   float avg_color[NUM_BANDS]; /* average colors of pixels, one for each band */
    00150   float std_color[NUM_BANDS]; /* std of pixel colors, one for each band */
    00151   float avg_color_square[NUM_BANDS];
    00152   float color_sum[NUM_BANDS];
    00153   int used; /* indicate if segment has been used in segmentation step */
    00154   struct segment_pixel *pixel_list; /* list of indexes of the segment's pixels */
    00155   struct segment_pixel *last_pixel; /* pointer to the last pixel in the pixel list */
    00156   struct segment_pixel *original_pixel; /* pointer to original pixel of the segment */
    00157   struct segment *previous_segment; /* previous not deleted segment */
    00158   struct segment *next_segment; /* next not deleted segment */
    00159   struct segment *previous_unused_segment; /* previous unused segment */
    00160   struct segment *next_unused_segment; /* next unused segment */
    00161   struct segment *next_original_segment; /* next original segment */
    00162 };
    00163
    00164 /* node of segments' neighbours */
    00165 struct segment_neighbor
    00166 {
    00167   float area; /* number of pixels in merged segment, neighbour plus original */
    00168   float perimeter; /*number of border pixels in merged segment, neighbour plus original */
    00169   float b_box[4]; /* bounding box of the segment of merged segment, neighbour plus original */
    00170   float avg_color[NUM_BANDS]; /* average colors of pixels of merged segment, one for each band */
    00171   float std_color[NUM_BANDS]; /* std of pixel colors of merged segment, one for each band */
    00172   float avg_color_square[NUM_BANDS];
    00173   float color_sum[NUM_BANDS];
    00174   unsigned long int neighbor_id; /* id of neighbor segment */
    00175   struct segment *neighbor; /* neighbor segment */
    00176   struct segment_neighbor *next_neighbor; /* next neighbor */
    00177 };
    00178
    00179 /* record of segmentation parameters */
    00180 struct segmentation_parameters
    00181 {
    00182   float sp; /* scale parameter */
    00183   float wband[NUM_BANDS]; /* weight of image bands, between 0 and 1 */
    00184   float wcolor; /* factor of color/shape, between 0 and 1 */
    00185   float wcmpt; /* factor of compactness/smothness, between 0 and 1 */
    00186   int bands; /* number of bands */
    00187 };
    00188
    00189 /**********************************************************************************/
    00190 /* function prototypes                                                            */
    00191 /**********************************************************************************/
    00192
    00193 /* returns random number between low and high */
    00194 float randval(float low,
    00195         float high);
    00196
    00197 /* read parameter file */
    00198 int read_seg_parameters(char *parameter_file_name,
    00199             struct segmentation_parameters *parameters);
    00200
    00201 /* creates one segment for each pixel of input image */
    00202 int initialize_segments(struct segment ***segments_ptr_vector,
    00203             struct segment **first_segment,
    00204             struct segment **last_segment,
    00205             // float **input_image,
    00206             TePDITypes::TePDIRasterPtrType input_image,
    00207             vector<unsigned> input_channels,
    00208             long int nrows,
    00209             long int ncols,
    00210             bool progress_enabled_);
    00211
    00212 /* performs the segmentation, returns (num.segments + segmentation steps/100) */
    00213 float segmentation(// float **input_image,
    00214            struct segment **segments_ptr_vector,
    00215            struct segment *initial_segment,
    00216            struct segment *final_segment,
    00217            long int nrows,
    00218            long int ncols,
    00219            struct segmentation_parameters parameters,
    00220            bool progress_enabled_);
    00221
    00222 /* write output image */
    00223 void write_segments(// float **input_image,
    00224           TePDITypes::TePDIRasterPtrType output_image,
    00225           struct segment *initial_segment,
    00226           int write_type,
    00227           bool progress_enabled_);
    00228
    00229 /* remove segments from memory */
    00230 void free_segment_list(struct segment **initial_segment,
    00231              struct segment ***segments_ptr_vector);
    00232
    00233 #endif

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines