storm_imagery.cc File Reference

Code dealing with storm imagery (low level). More...

#include <gvars3/instances.h>
#include <cvd/image_io.h>
#include <cvd/convolution.h>
#include <TooN/wls.h>
#include <TooN/SVD.h>
#include <tr1/tuple>
#include "storm_imagery.h"
#include "debug.h"
#include "utility.h"

Go to the source code of this file.

Functions

vector< Image< float > > load_and_preprocess_images2 (const vector< string > &names)
Image< float > preprocess_image (const Image< float > &im)
vector< Image< float > > load_and_preprocess_images (const vector< string > &names)
pair< float, float > mean_and_variance (const vector< Image< float > > &images)
pair< double, double > auto_fixed_scaling (const vector< Image< float > > &ims, double frac)
vector< Image< float > > load_and_normalize_images (const vector< string > &files)

Detailed Description

Code dealing with storm imagery (low level).

Definition in file storm_imagery.cc.


Function Documentation

pair<double, double> auto_fixed_scaling ( const vector< Image< float > > &  ims,
double  frac 
)

Compute the mean and variance of the (on average) darkest pixels, in order to find the correct scaling, by examining hte background.

Definition at line 276 of file storm_imagery.cc.

References assert_same_size(), and sq().

Referenced by load_and_normalize_images().

00277 {
00278     assert_same_size(ims);
00279     
00280     //Compute the mean image (ish)
00281     Image<double> ave(ims[0].size());
00282     ave.fill(0);
00283     for(unsigned int i=0; i < ims.size(); i++)
00284         for(int y=0; y < ave.size().y; y++)
00285             for(int x=0; x < ave.size().x; x++)
00286                 ave[y][x] += ims[i][y][x];
00287     
00288     //Find the smallest N% of the pixels...
00289     vector<pair<double, ImageRef> > pixels;
00290     for(int y=0; y < ave.size().y; y++)
00291         for(int x=0; x < ave.size().x; x++)
00292             pixels.push_back(make_pair(ave[y][x], ImageRef(x,y)));
00293 
00294     int npix = (int) floor(frac *pixels.size() + 0.5);
00295     npix = max(0, min(npix, (int) pixels.size()));
00296 
00297     nth_element(pixels.begin(), pixels.begin() + npix, pixels.end());
00298 
00299     pixels.resize(npix);
00300     
00301     //Now compute the mean and variance of those pixels.
00302     double sum=0, sum2=0;
00303 
00304     for(unsigned int i=0; i < ims.size(); i++)
00305     {   
00306         for(unsigned int j=0; j < pixels.size(); j++)
00307         {
00308             sum += ims[i][pixels[j].second];
00309             sum2 += sq(ims[i][pixels[j].second]);
00310         }
00311     }
00312 
00313     double num = 1.0 * pixels.size() * ims.size();
00314     double mean = sum / num;
00315     double std  = sqrt(((sum2/num) - mean*mean) * num / (num-1));
00316 
00317     cout << "Automatic determination of fixed scaling:" << endl
00318          << "mean       = " << mean << endl
00319          << "std        = " << std << endl
00320          << "sqrt(mean) = " << sqrt(mean*255)/255 << endl;
00321     
00322     return make_pair(mean, std);
00323 }

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