CImageSegmentationIndexFile.h

00001 #ifndef __CImageSegmentationIndexFile_h_2005_03_23_15_04_W_AI__
00002 #define __CImageSegmentationIndexFile_h_2005_03_23_15_04_W_AI__
00003 
00004 #include "TImageSegmentation.h"
00005 
00006 namespace segmentation {
00007 
00008 // input/ouput filter for image segmentations (a segment index for each pixel)
00009 class CImageSegmentationIndexFile
00010 {
00011 public:
00012         // extentions of file read+written
00013         static const char segFileExt[2][9];
00014 
00015         enum FILE_FORMAT
00016         {
00017                 unknown_format = -1,
00018                 bsi_format = 0,
00019                 martin_seg_format = 1, // David Martin - Berkley Image Database
00020                 format_count = 2
00021         };
00022 
00023         // read image segment index falues from specified file
00024         // - if the indexArray pointer is NULL or the width & height do not match the information
00025         //   in the file, the values of width and height are corrected and 0 is returned
00026         // - if some file error appears -1 is returned
00027         // - if the dimensions match, width*height values are written to indexArray and 1 is returned
00028         static
00029         long Load(const char *filename, long & width, long & height, long * indexArray = NULL);
00030 
00031 
00032         // reads the segmentation to the supplied segmentation object
00033         // - modifies oject (reallocates) if necessary
00034         // - only file error (-1) or 1 are possible return values
00035         static
00036         long Load(const char *filename, TImageSegmentation<long> &segmentation);
00037 
00038         // write the image segment index to the specified file
00039         // - width*height values are written from indexArray
00040         // - returns true on success
00041         // - false means file error
00042         static
00043         bool Save(const char *filename, const long width, const long height, const long * indexArray, FILE_FORMAT format = bsi_format);
00044 
00045         // write the image segment index to the specified file
00046         // - width*height values are written from indexArray
00047         // - returns true on success
00048         // - false means file error
00049         static
00050         bool Save(const char *filename, const TImageSegmentation<long> &segmentation, FILE_FORMAT format = bsi_format);
00051 
00052         // returns the format if the filename specifies a known segmentation file
00053         // unknown_format otherwise
00054         static
00055         FILE_FORMAT WhichSegmentationIndexFile(const char * filename);
00056 
00057 
00058 protected:
00059         // reads the file header (file format specified)
00060         static 
00061         FILE * ReadFileHeader(FILE_FORMAT fileFormat, const char *filename, long & width, long & height);
00062 
00063         // reads the file data (file format specified)
00064         static
00065         bool ReadFileData(FILE_FORMAT fileFormat, FILE *f, long * indexArray, long width, long height);
00066 
00067         // read header of BSI files and get width and height
00068         static
00069         FILE * ReadBSIFileHeader(const char *filename, long & width, long & height);
00070 
00071         // read segmentation data from BSI files
00072         static
00073         bool ReadBSIFileData(FILE *f, long * indexArray, long width, long height);
00074 
00075         // read header of Martin's SEG files and get width and height
00076         static
00077         FILE * ReadSEGFileHeader(const char *filename, long & width, long & height);
00078 
00079         // read segmentation data from Martin's SEG files
00080         static
00081         bool ReadSEGFileData(FILE *f, long * indexArray, long width, long height);
00082 
00083 };
00084 
00085 } // namespace segmentation
00086 
00087 #endif
00088 

Generated on Thu Jun 22 14:47:19 2006 for ncut.kdevelop by  doxygen 1.4.6