cnct_comp.h

00001 /*----------------------------------------------------------------------------
00002  *                            E.S.O.
00003  *----------------------------------------------------------------------------
00004  * File name   :    cnct_comp.h
00005  * Author      :    Thomas Rogon 
00006  * Created on  :    April 28, 1999
00007  * Hardware    :    Sun Sparc 20
00008  * Software    :    ANSI C under Solaris Unix
00009  *                  Part of ECLIPSE library for Adonis
00010  * Description :    Connected components:
00011  *                      - detection & classification
00012  *                      - private features (specific to the labeled image alone)
00013  *--------------------------------------------------------------------------*/
00014 
00015 
00016 /*
00017 
00018         $Id: cnct_comp.h,v 1.1 2003/09/03 12:50:47 amodigli Exp $
00019         $Author: amodigli $
00020         $Date: 2003/09/03 12:50:47 $
00021         $Revision: 1.1 $
00022 
00023 */
00024 
00025 #ifndef _CNCT_COMP_H_
00026 #define _CNCT_COMP_H_
00027 
00028 /*---------------------------------------------------------------------------
00029                                 Includes
00030  ---------------------------------------------------------------------------*/
00031 #include <stdlib.h>
00032 
00033 #include "image_handling.h"
00034 #include "pixelmaps.h"
00035 
00036 /*---------------------------------------------------------------------------
00037                                 Defines
00038  ---------------------------------------------------------------------------*/
00039 
00040 /* hack to retrieve largest unsigned integer */
00041 /* with the size of label_pix (255 8bit, 65535 16bit, etc.)  */
00042 
00043 #define MAX_LABEL      (65535)    
00044 #define MAX_CLASSNUM   (MAX_LABEL -2) 
00045 
00046 /* CNCTCMP_WHITE might in fact be 255 on some systems; 
00047  * DO NOT assume it to have any specific 
00048  * value and refrain from doing any arithmetic based upon it 
00049  * (the algorithm avoids labelling with this value)
00050  * Label CNCTCMP_WHITE is for implementational reasons 
00051  * reserved for temporary unlabelled objects between passes*/
00052 #define CNCTCMP_WHITE           (ONE)   
00053 #define CNCTCMP_BLACK            (ZERO)
00054 
00055 
00056 
00057 #define FIRST_LABEL     2 /* Assumed different from WHITE (see cnct_comp.c) */
00058 
00059 /*---------------------------------------------------------------------------
00060                                                                 New types
00061  ---------------------------------------------------------------------------*/
00062 
00063 typedef ushort16 label_pix ;
00064 
00065 typedef struct _LABEL_IMAGE_T_ {
00066     size_t      lx ;
00067     size_t      ly ;
00068     label_pix  *buf ;
00069     int         nrealobj; /* objects of interest (without black and white */
00070     int         nobjtot;  /* total number of objects */
00071 } label_image_t ;
00072 
00073 
00074 
00075 /* private features specific to the connected components in the labeled image 
00076     alone needing no information from the "original" grey image...*/
00077 typedef struct _CC_STATS_T_ {
00078 /* The size in pixels */ 
00079    size_t           numpix; 
00080 /* gravity center (unweighted, i.e. all pixels contribute equally) */
00081    double       gcx;        
00082    double       gcy;        
00083 /* std. dev. (error) on gravity center */
00084    double       egcx;       
00085    double       egcy;       
00086 /* wet surface:  */
00087    unsigned long int wetsrf;    
00088 /* perimeter:  - not implemented
00089     unsigned long int prmtr;*/
00090     pixel_position  top;
00091     pixel_position  bot;
00092     pixel_position  left;
00093     pixel_position  right;
00094 } cc_stats_t ;
00095 /* Wet surface:
00096                       111               W=pixel belonging to object
00097                      2WWW1          1= single contribution to wet surface
00098                     1WW4W1          2= two contributions to wet surface
00099                     1WWWW1          4= four contributions to wet surface
00100                      1111               The wet surface is here 18
00101 
00102     Perimeter:
00103                      11111          W=pixel belonging to object
00104                     11WWW1          1= single contribution to perimeter
00105                     1WW W1          
00106                     1WWWW1
00107                     111111          The perimeter is here 18
00108 */
00109 
00110 /*---------------------------------------------------------------------------
00111                                                         Function prototypes
00112 O V E R V I E W:
00113 
00114 allocation/deallocation:
00115     new_label_image()       allocates a label image + pixel buffer
00116     free_label_image()      deallocates label image + pixel buffer
00117 
00118 loading/saving:
00119     load_label_image_from_pixelmap()    loads a labelimage from a pixel map
00120     load_label_image()                  loads a labelimage from a labelimage
00121     dump_labelimage()                   stores a labelimage as a FITS file
00122 
00123 calculation:
00124     labelize_binary()           main labelization routine
00125 
00126 printing/debugging:
00127     print_ccfeaturestable()     prints a formatted cc features table
00128                                 into a text file
00129     output_ccfeaturestable()    creates a text file with a cc features table
00130 
00131  ---------------------------------------------------------------------------*/
00132 
00133 /*---------------------------------------------------------------------------
00134  * Function :   new_label_image()
00135  * In       :   dimensions, bytes per pixel 
00136  * Out      :   Pointer to newly allocated structure
00137  * Job      :   Allocates space for a new label image 
00138  * Notice   :   number of objects is cleared
00139  *--------------------------------------------------------------------------*/
00140 label_image_t *new_label_image(size_t lx, size_t ly);
00141 
00142 /*---------------------------------------------------------------------------
00143  * Function :   free_label_image ()
00144  * In       :   label_image pointer
00145  * Out      :   void
00146  * Job      :   frees all memory associated to a label_image
00147  *--------------------------------------------------------------------------*/
00148 void free_label_image( label_image_t *to_destroy);
00149 
00150 /*---------------------------------------------------------------------------
00151  * Function :   load_label_image_from_pixelmap()
00152  * In       :   file name
00153  * Out      :   pixel_map
00154  * Job      :   loads a pixel_map into a label_image
00155  * Notice   :   pixel map is assumed 8bit/pel
00156  *--------------------------------------------------------------------------*/
00157 label_image_t* load_label_image_from_pixelmap(char * filename);
00158 
00159 /*---------------------------------------------------------------------------
00160  * Function :   load_label_image()
00161  * In       :   file name
00162  * Out      :   pixel_map
00163  * Job      :   loads a label_image
00164  *--------------------------------------------------------------------------*/
00165 label_image_t* load_label_image(char * filename);
00166 
00167 /*---------------------------------------------------------------------------
00168  * Function :   dump_labelimage()
00169  * In       :   label_image, filename
00170  * Out      :   0 if OK, -1 if error
00171  * Job      :   dumps a label image on a file in FITS format
00172  * Notice   :   The number of objects found is stored in the
00173  *              OBJECTS fits header keyword
00174  *--------------------------------------------------------------------------*/
00175 int dump_labelimage( label_image_t *to_dump, char *filename);
00176 
00177 /*---------------------------------------------------------------------------
00178    Function :   pixelmap_2_label_image()
00179    In       :   allocated pixel map
00180    Out      :   newly allocated label image, with all pixels set to 0
00181                 or 1, reflecting the input pixel map.
00182    Job      :   transforms a pixel map into a label_image
00183  ---------------------------------------------------------------------------*/
00184 label_image_t * pixelmap_2_label_image(pixel_map *pm);
00185 
00186 /*---------------------------------------------------------------------------
00187  * Function :   labelize_binary()
00188  * In       :   binary label_image
00189  * Out      :   table of computed cc features if OK, NULL otherwise
00190  * Job      :   labelize connected components 
00191  * Notice   :   A non-recursive algorithm using 2 passes is used.
00192  *              A partial labeling with equivalence classes is generated 
00193  *              during the first pass, the second pass merges the equivalent
00194  *              classes (clusters) and produces a feature table in return
00195  *              The labels assigned are consecutive, but start at FIRST_LABEL
00196  *              The generated feature table contains the 2 more entries than
00197  *              the number of objects found:
00198  *                  - for the background BLACK; the feature values should
00199  *                    "complement" the values found for all valid objects
00200  *                  - for the reserved value WHITE (which is the reserved value
00201  *                    for non-labelised objects; all feature values should be
00202  *                    zero
00203  *              The 8 bit mode saturates at 253 objects, but the
00204  *              intermediate equivalence tables tend to saturate 
00205  *              somewhat earlier necessitating a large number of cycles.
00206  *              If more than about 200 objects are anticipated,
00207  *              the label image should be 16bits/pel.
00208  *--------------------------------------------------------------------------*/
00209 cc_stats_t *labelize_binary(label_image_t *label_image);
00210 
00211 /*---------------------------------------------------------------------------
00212  * Function :  print_ccfeaturestable()
00213  * In       :  FILE pointer, array of connected component stats,
00214  *              name of input file
00215  * Out      :  0 if OK, -1 if not OK 
00216  * Job      :  prints Connected component features (see cc_stats_t)
00217  *--------------------------------------------------------------------------*/
00218 int print_ccfeaturestable( cc_stats_t *cs, unsigned long numentries, 
00219                             FILE *f, char* fin_name);
00220 
00221 /*---------------------------------------------------------------------------
00222  * Function :   output_ccfeaturestable()
00223  * In       :   FILE name string, array of connected component stats,
00224  *              number of objects reported by labelize_binary
00225  *              name of input file
00226  * Out      :   0 if OK, -1 if not OK 
00227  * Notice   :   File name==NULL implies stdout
00228  *--------------------------------------------------------------------------*/
00229 int output_ccfeaturestable( char *fn, cc_stats_t *cs, 
00230                         unsigned long numobj,  char* fin_name);
00231 
00232 /*---------------------------------------------------------------------------
00233  * Function :   select_objs()
00234  * In       :   a label image, 
00235                 a list of objects to keep, the number of them
00236  * Out      :   0 if OK -1 if not
00237  * Job      :   deletes (i.e. sets to 0) objects not occuring
00238  *              in objlist
00239  *--------------------------------------------------------------------------*/
00240 int select_objs(label_image_t* l, int *objlist, int nobjs);
00241 
00242 
00243 /*---------------------------------------------------------------------------
00244  * Function :   get_extreme_obj_coor()
00245  * In       :   a cc_stats table 
00246                 the total number of objects
00247  * Out      :   the corrdinates of the box bounding all objects in list
00248  * Job      :   
00249  *--------------------------------------------------------------------------*/
00250 int get_extreme_obj_coor(cc_stats_t *cs, int nobjs,
00251         int *selected_objlist, int nselectedobjs,
00252         int *left, int *right, int *top, int *bot);
00253 
00254 #endif

Generated on Wed Oct 26 13:08:51 2005 for SINFONI Pipeline Reference Manual by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001