/home/oan/prosjekt/gotools/segmentation/gpl_distro/lsseg_1.0_gpl/include/simple_tools.h

Go to the documentation of this file.
00001 //===========================================================================
00002 // The Level-Set Segmentation Library (LSSEG)
00003 //
00004 //
00005 // Copyright (C) 2000-2005 SINTEF ICT, Applied Mathematics, Norway.
00006 //
00007 // This program is free software; you can redistribute it and/or          
00008 // modify it under the terms of the GNU General Public License            
00009 // as published by the Free Software Foundation version 2 of the License. 
00010 //
00011 // This program is distributed in the hope that it will be useful,        
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of         
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          
00014 // GNU General Public License for more details.                           
00015 //
00016 // You should have received a copy of the GNU General Public License      
00017 // along with this program; if not, write to the Free Software            
00018 // Foundation, Inc.,                                                      
00019 // 59 Temple Place - Suite 330,                                           
00020 // Boston, MA  02111-1307, USA.                                           
00021 //
00022 // Contact information: e-mail: tor.dokken@sintef.no                      
00023 // SINTEF ICT, Department of Applied Mathematics,                         
00024 // P.O. Box 124 Blindern,                                                 
00025 // 0314 Oslo, Norway.                                                     
00026 // 
00027 //
00028 // Other licenses are also available for this software, notably licenses
00029 // for:
00030 // - Building commercial software.                                        
00031 // - Building software whose source code you wish to keep private.        
00032 //
00033 //===========================================================================
00034 //===========================================================================
00035 //                                                                           
00036 // File: simple_tools.h                                                      
00037 //                                                                           
00038 // Created: Tue Oct 25 13:56:00 2005                                         
00039 //                                                                           
00040 // Author: Odd A. Andersen <Odd.Andersen@sintef.no>
00041 //                                                                           
00042 // Revision: $Id: simple_tools.h,v 1.25 2006/11/16 23:40:17 oan Exp $
00043 //                                                                           
00044 // Description:
00047 //                                                                           
00048 //===========================================================================
00049 
00050 // recent changes:
00051 // 2006/03/30:  added function read_image_sequence_multichn() (kgre)
00052 
00053 #ifndef _SIMPLE_TOOLS_H
00054 #define _SIMPLE_TOOLS_H
00055 
00056 #include "Image.h"
00057 #include "LevelSetFunction.h"
00058 #include "Mask.h"
00059 #include "ParzenDistributionForce.h"
00060 
00061 namespace lsseg {
00062 
00063 enum SEG_REGION {SEG_NEGATIVE = 0, SEG_POSITIVE};
00064 
00065 //===========================================================================
00066 // image transform functions
00067 //===========================================================================
00068 
00076 void negate(Image<double>& img, double min = 0, double max = 255);
00077 
00092 void rescale(Image<double>& img, double cur_min, double cur_max, double to_min = 0, double to_max = 255);
00093 
00101 void rescale_channels(Image<double>& img, double to_min = 0, double to_max = 255);
00102 
00110 void clip(Image<double>& img, double min, double max);
00111 
00117 template<typename T>
00118 void to_grayscale(Image<T>& img);
00119 
00125 void transpose(Image<double>& img);
00126 
00133 void transpose(const Image<double>& img, Image<double>& target);
00134 
00135 //===========================================================================
00136 // syntetic image generation functions - generate test images, etc.
00137 //===========================================================================
00138 
00153 void horizontal_sinusoidal_bands(LevelSetFunction& img, int num_bands, double phase=0);
00154 
00155 
00176 void rectangle(LevelSetFunction& img, 
00177                double xmin_ratio, 
00178                double xmax_ratio,
00179                double ymin_ratio,
00180                double ymax_ratio,
00181                double zmin_ratio = 0,
00182                double zmax_ratio = 1);
00183 
00198 void sphere(LevelSetFunction& img,
00199             double relrad,  //between 0 and 1
00200             double xrelpos, // between 0 and 1
00201             double yrelpos, // between 0 and 1
00202             double zrelpos = 0);
00203             
00204 // // @@ document this or remove it....   Is it superfluous given the sphere() function above???
00205 // void distance_from_point(LevelSetFunction& img,
00206 //                       double zero_level, // which distance is considered zero (as ratio of longest
00207 //                                          // dimension
00208 //                       double point_x_relpos, // from 0 to 1
00209 //                       double point_y_relpos, // from 0 to 1
00210 //                       double point_z_relpos = 0); // from 0 to 
00211 
00225 void set_from_parzen(LevelSetFunction& img, 
00226                       const ParzenDistributionForce pf,
00227                       const Mask* m = 0);
00228 
00248 void init_voronoi_regions(LevelSetFunction* regs,
00249                           const double* center_coords, // each between 0 and 1
00250                           int num_regions,
00251                           bool three_d = false); // true if 3D
00252 
00270 void random_scattered_voronoi(LevelSetFunction* regs,
00271                               int num_regs,
00272                               int num_fragments); // per region
00273 
00288 void multiregion_bands(LevelSetFunction* regs,
00289                        int num_regs,
00290                        int pixel_bandwidth);
00291 
00292 //===========================================================================
00293 // other functions
00294 //===========================================================================
00295 
00309 void make_border_mask(const LevelSetFunction& phi, 
00310                       Mask& target, 
00311                       int width = 2,
00312                       const Mask* geom_mask = 0);
00313 
00325 void mask_from_segmentation(const LevelSetFunction& phi, Mask& target, SEG_REGION reg);
00326 
00338 void read_image_sequence(std::istream& image_list, 
00339                          Image<double>& result, 
00340                          bool convert_to_grayscale = false);
00341 
00342 
00343 // void read_image_sequence_multichn(std::istream& image_list, 
00344 //                       Image<double>& result,
00345 //                       bool convert_to_grayscale = false);
00346 
00360 template<typename ImgType>
00361 void resample_into(const ImgType& src, ImgType& target, bool linear = true);
00362 
00363 // if not linear, then piecewise constant
00364 
00397 template<typename ImgType>
00398 void downsample_series(const ImgType& input, 
00399                        std::vector<ImgType >& result,
00400                        int min_num_pixels,
00401                        bool downscale_z = false,
00402                        double downscale_factor = 2,
00403                        bool to_grayscale = false,
00404                        bool linear = true);
00405 
00410 unsigned long int nonzeroes(const Image<int>& img);
00411 
00417 double nonzero_ratio(const Image<int>& img);
00418 
00423 unsigned long int positives(const Image<double>& img); // positive or zero
00424 
00430 double positive_ratio(const Image<double>& img); // positive or zero ratio
00431 
00436 unsigned long int negatives(const Image<double>& img); // negative
00437 
00443 double negative_ratio(const Image<double>& img); // negative ratio
00444 
00446 inline double compute_nu_Brox(unsigned int domain_size, double nu_factor) 
00447 {
00448     // as proposed by Brox
00449     return 1.0e-3 * nu_factor * pow(domain_size, 0.7);
00450 }
00452 
00453 
00454 }; // end namespace lsseg
00455 
00456 #include "simple_tools_templates.h"
00457 
00458 #endif // _SIMPLE_TOOLS_H
00459 

Generated on Tue Nov 28 18:35:47 2006 for lsseg by  doxygen 1.4.7