General utility functions.

Classes

struct  MT19937
 Useful wrapper for MT19937 random number generator class. More...
class  Kahan
 Class implementing the Kahan summation algorithm to allow accurate summation of very large numbers of doubles. More...

Typedefs

typedef std::pair
< CVD::ImageRef, CVD::ImageRef > 
BBox

Functions

double ln (double x)
Vector spots_to_Vector (const vector< Vector< 4 > > &s)
vector< Vector< 4 > > spots_to_vector (const Vector<> &s)
Image< byte > scale_to_bytes (const Image< float > &im, float lo, float hi)
Image< byte > scale_to_bytes (const Image< float > &im)
Image< float > average_image (const vector< Image< float > > &ims)
vector< string > split (const string &line)
template<class C >
string xtoa (const C &x)
template<class C >
atox (const string &s, const string &msg)
set< ImageRef > dilate_mask (const vector< ImageRef > &v, double r)
vector< int > SampledMultispot::sequence (int n)
double sign (double x)
float sq (float f)
const std::vector
< CVD::SubImage< float > > 
sub_images (const std::vector< CVD::Image< float > > &im, CVD::ImageRef pos, CVD::ImageRef size)
std::pair< CVD::ImageRef,
CVD::ImageRef > 
boundingbox (const std::vector< CVD::ImageRef > &all_spots)
template<class Stream >
void open_or_die (Stream &save_spots, const std::string &save_spots_file)

Typedef Documentation

typedef std::pair<CVD::ImageRef, CVD::ImageRef> BBox

Deffinition of a pixel aligned bounding box.

Definition at line 68 of file utility.h.


Function Documentation

double ln ( double  x  )  [inline]

Computes the natural logarithm, but returns -1e100 instead of inf for an input of 0.

This prevents trapping of FPU exceptions.

Parameters:
x x
Returns:
ln x

Definition at line 34 of file forward_algorithm.h.

Referenced by backward_sampling(), diff_log_log_normal(), forward_algorithm(), forward_algorithm_delta(), forward_algorithm_delta2(), forward_algorithm_hessian(), forward_backward_algorithm(), hess_log_log_normal(), log_log_normal(), and FitSpots::try_modifying_model().

00035 {
00036     if(x == 0)
00037         return -1e100;
00038     else
00039         return std::log(x);
00040 }

Vector spots_to_Vector ( const vector< Vector< 4 > > &  s  ) 

There are two sensible ways of storing the state vector of spot positions.

This function converts between them. See also spots_to_vector.

Parameters:
s list of spots to convert

Definition at line 96 of file multispot5.cc.

Referenced by fit_spots_historic(), FitSpots::optimize_each_spot_in_turn_for_several_passes(), FitSpots::run(), and FitSpots::try_modifying_model().

00097 {
00098     Vector<> r(s.size()*4);
00099     for(unsigned int i=0; i < s.size(); i++)
00100     {
00101         r[i*4+0] = s[i][0];
00102         r[i*4+1] = s[i][1];
00103         r[i*4+2] = s[i][2];
00104         r[i*4+3] = s[i][3];
00105     }
00106     return r;
00107 }

vector<Vector<4> > spots_to_vector ( const Vector<> &  s  ) 

There are two sensible ways of storing the state vector of spot positions.

This function converts between them. See also spots_to_Vector.

Parameters:
s list of spots to convert

Definition at line 113 of file multispot5.cc.

Referenced by NegativeFreeEnergy::compute_with_mask(), fit_spots_historic(), generate_state_parameters_ye_olde(), and NegativeFreeEnergy::operator()().

00114 {
00115     vector<Vector<4> > r(s.size()/4);
00116     for(unsigned int i=0; i < r.size(); i++)
00117         r[i] = s.slice<Dynamic, 4>(i*4, 4);
00118     return r;
00119 }

Image<byte> scale_to_bytes ( const Image< float > &  im,
float  lo,
float  hi 
)

Normalize an image for display purposes.

Definition at line 123 of file multispot5.cc.

Referenced by fit_spots_historic(), FitSpots::optimize_each_spot_in_turn_for_several_passes(), and FitSpots::try_modifying_model().

00124 {
00125         Image<byte> out(im.size());
00126         for(int r=0; r < out.size().y-0; r++)
00127                 for(int c=0; c < out.size().x-0; c++)
00128                         out[r][c] = (int)floor((im[r][c]-lo)*255/(hi-lo));
00129         return out;
00130 }

Image<byte> scale_to_bytes ( const Image< float > &  im  ) 

Normalize an image for display purposes.

Definition at line 134 of file multispot5.cc.

00135 {
00136         float lo = *min_element(im.begin(), im.end());
00137         float hi = *max_element(im.begin(), im.end());
00138         Image<byte> out(im.size());
00139         for(int r=0; r < out.size().y-0; r++)
00140                 for(int c=0; c < out.size().x-0; c++)
00141                         out[r][c] = (int)floor((im[r][c]-lo)*255/(hi-lo));
00142 
00143         return out;
00144 }

Image<float> average_image ( const vector< Image< float > > &  ims  ) 

Average the input image stack for display purposes.

Definition at line 148 of file multispot5.cc.

References assert_same_size().

Referenced by fit_spots_historic().

00149 {
00150     assert_same_size(ims);
00151     Image<float> r(ims[0].size(), 0);
00152 
00153     for(unsigned int i=0; i < ims.size(); i++)
00154         transform(r.begin(), r.end(), ims[i].begin(), r.begin(), plus<float>());
00155 
00156     transform(r.begin(), r.end(), r.begin(), bind2nd(multiplies<float>(), 1./ims.size()));
00157     return r;
00158 }

vector<string> split ( const string &  line  ) 

Tokenize a line.

Definition at line 913 of file multispot5.cc.

Referenced by parse_log_file().

00914 {
00915     vector<string> v;
00916     istringstream i(line);
00917     string s;
00918 
00919     while(!i.eof())
00920     {
00921         i >> s;
00922         if(i.fail())
00923             break;
00924         v.push_back(s);
00925     }
00926     return v;
00927 }

template<class C >
string xtoa ( const C &  x  )  [inline]

Generic version of itoa.

How many times has this been reimplemented??

Parameters:
x Value to convert to string

Definition at line 933 of file multispot5.cc.

Referenced by parse_log_file().

00934 {
00935     ostringstream os;
00936     os << x;
00937     return os.str();
00938 }

template<class C >
C atox ( const string &  s,
const string &  msg 
) [inline]

Inverse of xtoa() How many times has this been reimplemented??

Parameters:
s String to convert
msg Mesage to print on error

Definition at line 945 of file multispot5.cc.

00946 {
00947     C c;
00948     istringstream i(s);
00949     i >> c;
00950     if(i.fail())
00951         throw LogFileParseError("Error parsing " + msg + ". Text is `" + s + "'.");
00952     return c;
00953 }

set<ImageRef> dilate_mask ( const vector< ImageRef > &  v,
double  r 
)

Very simple and inefficient dilation function.

Definition at line 1317 of file multispot5.cc.

01318 {
01319     vector<ImageRef> m = getDisc(r);
01320 
01321     set<ImageRef> ret;
01322 
01323     for(unsigned int i=0; i < v.size(); i++)
01324         for(unsigned int j=0; j < m.size(); j++)
01325             ret.insert(v[i] + m[j]);
01326 
01327     return ret;
01328 }

vector<int> SampledMultispot::sequence ( int  n  )  [inline]

Create a sequence of integers.

These can be used as observations in an observation class by forward_algorithm() and etc.

Parameters:
n Length of sequence

Definition at line 188 of file sampled_multispot.h.

Referenced by fit_spots_historic(), and FitSpots::optimize_each_spot_in_turn_for_several_passes().

00189 {
00190     vector<int> v;
00191     for(int i=0; i < n; i++)
00192         v.push_back(i);
00193     return v;
00194 }

double sign ( double  x  )  [inline]

computes the sign of x

Parameters:
x x
Returns:
$ \begin{cases} 1 & x \ge 0\\ -1 & x < 0 \end{cases}$

Definition at line 38 of file utility.h.

00039 {
00040     return x>=0?1:-1;
00041 }

float sq ( float  f  )  [inline]
const std::vector<CVD::SubImage<float> > sub_images ( const std::vector< CVD::Image< float > > &  im,
CVD::ImageRef  pos,
CVD::ImageRef  size 
)

Cut sub images out of every member of a vector of images.

Parameters:
im Images to be cut
pos Top left corner
size Size of the patch
Returns:
subimages.
std::pair<CVD::ImageRef, CVD::ImageRef> boundingbox ( const std::vector< CVD::ImageRef > &  all_spots  ) 

Compute the bounding box of a set of points.

Parameters:
all_spots List of points

Referenced by fit_spots_historic(), FitSpots::optimize_each_spot_in_turn_for_several_passes(), and FitSpots::try_modifying_model().

template<class Stream >
void open_or_die ( Stream &  save_spots,
const std::string &  save_spots_file 
) [inline]
Parameters:
save_spots Stream
save_spots_file File to open

Definition at line 83 of file utility.h.

Referenced by mmain().

00084 {
00085     using std::cerr;
00086     using std::endl;
00087     using std::strerror;
00088     using std::exit;
00089     save_spots.open(save_spots_file.c_str());
00090     int err = errno;
00091 
00092     if(!save_spots.good())
00093     {
00094         cerr << "***********************************************************\n";
00095         cerr << "ERROR: failed to open " << save_spots_file << ": " <<strerror(err) << endl;
00096         cerr << "***********************************************************\n";
00097         exit(1);
00098     }
00099 }

Generated on Wed Nov 2 18:00:00 2011 for BCUBED by  doxygen 1.6.3