multispot5_headless.cc File Reference

FitSpots driver for entierly headless (batch) operation. More...

#include <tag/printf.h>
#include <tr1/tuple>
#include <algorithm>
#include <climits>
#include <iomanip>
#include <map>
#include <cvd/image_io.h>
#include <cvd/image_convert.h>
#include <cvd/morphology.h>
#include <cvd/connected_components.h>
#include <cvd/draw.h>
#include <cvd/vector_image_ref.h>
#include <gvars3/instances.h>
#include <gvars3/GStringUtil.h>
#include <gvars3/GUI_readline.h>
#include "storm_imagery.h"
#include "multispot5.h"
#include "multispot5_place_choice.h"
#include "utility.h"

Go to the source code of this file.

Functions

vector< vector< ImageRef > > get_regions (const SubImage< double > &log_ratios)
void mmain (int argc, char **argv)
int main (int argc, char **argv)

Detailed Description

FitSpots driver for entierly headless (batch) operation.

Definition in file multispot5_headless.cc.


Function Documentation

vector<vector<ImageRef> > get_regions ( const SubImage< double > &  log_ratios  ) 

Definition at line 52 of file multispot5_headless.cc.

Referenced by mmain().

00053 {
00054     gvar3<double> radius("radius", 0, 1);
00055 
00056     //Set the liklihood ratio threshold/spot density prior
00057     //same thing.
00058     double threshold = GV3::get<double>("threshold", 0, -1);
00059     int edge = GV3::get<int>("edge", 0, -1);
00060 
00061 
00062     //Threshold image
00063     Image<byte> thresholded(log_ratios.size(), 0);
00064     for(int r=0; r < thresholded.size().y; r++)
00065         for(int c=0; c < min(thresholded.size().x, edge); c++)
00066             thresholded[r][c] = 255 * (log_ratios[r][c] > threshold);
00067     
00068     //Dilate
00069     Image<byte> dilated = morphology(thresholded, getDisc(*radius), Morphology::BinaryDilate<byte>());
00070 
00071     transform(dilated.begin(), dilated.end(), dilated.begin(), bind1st(multiplies<int>(), 255));
00072     
00073     //Connected components of dilated image
00074     vector<ImageRef> fg;
00075     for(int r=0; r < thresholded.size().y; r++)
00076         for(int c=0; c < min(thresholded.size().x, edge); c++)
00077             if(dilated[r][c])
00078                 fg.push_back(ImageRef(c, r));
00079 
00080     vector<vector<ImageRef> > regions;
00081     connected_components(fg, regions);
00082 
00083     return regions;
00084 }

void mmain ( int  argc,
char **  argv 
)

Definition at line 86 of file multispot5_headless.cc.

References fit_spots_new(), get_regions(), load_and_normalize_images(), null_graphics(), open_or_die(), parse_log_file(), and LogFileParseError::what.

Referenced by main().

00087 {
00088     GUI.LoadFile("multispot5.cfg");
00089     int lastarg = GUI.parseArguments(argc, argv);
00090     if(lastarg >= argc)
00091     {   
00092         cerr << "Specify the images to load\n";
00093         exit(1);
00094     }
00095     vector<string> files(argv + lastarg, argv + argc);
00096     
00097     //Save this now since the de-checkpointing code will kl0bber it 
00098     //when it reloads the gvars
00099     string save_spots_file = GV3::get<string>("save_spots", "", -1);
00100 
00101     string checkpoint_file = GV3::get<string>("load_checkpoint", "", 1);
00102 
00103     if(checkpoint_file != "")
00104     {
00105         //Load and de-checkpointing
00106         ifstream chk;
00107         open_or_die(chk, checkpoint_file);
00108         
00109         StateParameters p;
00110 
00111         try{
00112             p = parse_log_file(chk);
00113         }
00114         catch(LogFileParseError e)
00115         {
00116             cerr << "SI TEH FUX0R11ONEone!oneleven: " << e.what << endl;
00117             exit(1);
00118         }
00119         
00120         vector<Image<float> > ims = load_and_normalize_images(files);
00121 
00122         //Restore kl0bbered variable
00123         GV3::get<string>("save_spots") = save_spots_file;
00124         
00125         ofstream save_spots;
00126         open_or_die(save_spots, save_spots_file);
00127         
00128         fit_spots_new(ims, p, save_spots, *null_graphics());
00129 
00130     }
00131      
00132     vector<Image<float> > ims = load_and_normalize_images(files);
00133 
00134     //Load the log_ratios image.
00135     //We will use this as a starting point for searching for spots.
00136     Image<double> log_ratios;
00137     try
00138     {
00139         log_ratios = img_load(GV3::get<string>("log_ratios", "", -1));
00140     }
00141     catch(Exceptions::All e)
00142     {
00143         cerr << "Error loading " << GV3::get<string>("log_ratios", "") << ": " << e.what << endl;
00144         exit(1);
00145     }
00146     
00147     
00148     gvar3<int> cluster_to_show("cluster_to_show", 0, -1);
00149     gvar3<int> use_largest("use_largest", 0, 1);
00150 
00151     vector<vector<ImageRef> > regions;
00152 
00153     regions = get_regions(log_ratios);
00154     if(regions.size() == 0)
00155     {
00156         cerr << "There are no regions!\n";
00157 
00158         ofstream save_spots;
00159         open_or_die(save_spots, save_spots_file);
00160         save_spots << "NOREGIONS\n";
00161 
00162         exit(1);
00163     }
00164     
00165     if(*use_largest && !regions.empty())
00166     {
00167         *cluster_to_show=0;
00168         for(unsigned int i=1; i < regions.size(); i++)
00169             if(regions[i].size() > regions[*cluster_to_show].size())
00170                 *cluster_to_show = i;
00171                 
00172     }
00173     else
00174         *cluster_to_show = max(min(*cluster_to_show, (int)regions.size() - 1), 0);
00175 
00176     
00177     auto_ptr<FitSpotsGraphics> gr = null_graphics();
00178     place_and_fit_spots(ims, regions[*cluster_to_show], log_ratios, save_spots_file, *gr);
00179 }

int main ( int  argc,
char **  argv 
)

Definition at line 182 of file multispot5_headless.cc.

References mmain().

00183 {
00184     try{
00185         mmain(argc, argv);
00186     }
00187     catch(Exceptions::All e)
00188     {
00189         cerr << "Fatal error: " << e.what << endl;
00190     }
00191 }

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