00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00047
00048
00049
00050
00051
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
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
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,
00200 double xrelpos,
00201 double yrelpos,
00202 double zrelpos = 0);
00203
00204
00205
00206
00207
00208
00209
00210
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,
00250 int num_regions,
00251 bool three_d = false);
00252
00270 void random_scattered_voronoi(LevelSetFunction* regs,
00271 int num_regs,
00272 int num_fragments);
00273
00288 void multiregion_bands(LevelSetFunction* regs,
00289 int num_regs,
00290 int pixel_bandwidth);
00291
00292
00293
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
00344
00345
00346
00360 template<typename ImgType>
00361 void resample_into(const ImgType& src, ImgType& target, bool linear = true);
00362
00363
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);
00424
00430 double positive_ratio(const Image<double>& img);
00431
00436 unsigned long int negatives(const Image<double>& img);
00437
00443 double negative_ratio(const Image<double>& img);
00444
00446 inline double compute_nu_Brox(unsigned int domain_size, double nu_factor)
00447 {
00448
00449 return 1.0e-3 * nu_factor * pow(domain_size, 0.7);
00450 }
00452
00453
00454 };
00455
00456 #include "simple_tools_templates.h"
00457
00458 #endif // _SIMPLE_TOOLS_H
00459