\hypertarget{multispot5__headless_8cc}{
\subsection{multispot5\_\-headless.cc File Reference}
\label{multispot5__headless_8cc}\index{multispot5\_\-headless.cc@{multispot5\_\-headless.cc}}
}


\hyperlink{classFitSpots}{FitSpots} driver for entierly headless (batch) operation.  


{\ttfamily \#include $<$tag/printf.h$>$}\par
{\ttfamily \#include $<$tr1/tuple$>$}\par
{\ttfamily \#include $<$algorithm$>$}\par
{\ttfamily \#include $<$climits$>$}\par
{\ttfamily \#include $<$iomanip$>$}\par
{\ttfamily \#include $<$map$>$}\par
{\ttfamily \#include $<$cvd/image\_\-io.h$>$}\par
{\ttfamily \#include $<$cvd/image\_\-convert.h$>$}\par
{\ttfamily \#include $<$cvd/morphology.h$>$}\par
{\ttfamily \#include $<$cvd/connected\_\-components.h$>$}\par
{\ttfamily \#include $<$cvd/draw.h$>$}\par
{\ttfamily \#include $<$cvd/vector\_\-image\_\-ref.h$>$}\par
{\ttfamily \#include $<$gvars3/instances.h$>$}\par
{\ttfamily \#include \char`\"{}storm\_\-imagery.h\char`\"{}}\par
{\ttfamily \#include \char`\"{}multispot5.h\char`\"{}}\par
{\ttfamily \#include \char`\"{}multispot5\_\-place\_\-choice.h\char`\"{}}\par
{\ttfamily \#include \char`\"{}utility.h\char`\"{}}\par
\subsubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
vector$<$ vector$<$ ImageRef $>$ $>$ \hyperlink{multispot5__headless_8cc_ae02d12637df540cbfaba847bc0652211}{get\_\-regions} (const SubImage$<$ double $>$ \&log\_\-ratios)
\item 
void \hyperlink{multispot5__headless_8cc_a760ab99c4eca79d376e1be1a74ce1464}{mmain} (int argc, char $\ast$$\ast$argv)
\item 
int \hyperlink{multispot5__headless_8cc_a3c04138a5bfe5d72780bb7e82a18e627}{main} (int argc, char $\ast$$\ast$argv)
\end{DoxyCompactItemize}


\subsubsection{Detailed Description}
\hyperlink{classFitSpots}{FitSpots} driver for entierly headless (batch) operation. 

Definition in file \hyperlink{multispot5__headless_8cc_source}{multispot5\_\-headless.cc}.



\subsubsection{Function Documentation}
\hypertarget{multispot5__headless_8cc_ae02d12637df540cbfaba847bc0652211}{
\index{multispot5\_\-headless.cc@{multispot5\_\-headless.cc}!get\_\-regions@{get\_\-regions}}
\index{get\_\-regions@{get\_\-regions}!multispot5_headless.cc@{multispot5\_\-headless.cc}}
\paragraph[{get\_\-regions}]{\setlength{\rightskip}{0pt plus 5cm}vector$<$vector$<$ImageRef$>$ $>$ get\_\-regions (
\begin{DoxyParamCaption}
\item[{const SubImage$<$ double $>$ \&}]{log\_\-ratios}
\end{DoxyParamCaption}
)}}
\label{multispot5__headless_8cc_ae02d12637df540cbfaba847bc0652211}


Definition at line 50 of file multispot5\_\-headless.cc.



Referenced by mmain().


\begin{DoxyCode}
{
    gvar3<double> radius("radius", 0, 1);

    //Set the liklihood ratio threshold/spot density prior
    //same thing.
    double threshold = GV3::get<double>("threshold", 0, -1);
    int edge = GV3::get<int>("edge", 0, -1);


    //Threshold image
    Image<byte> thresholded(log_ratios.size(), 0);
    for(int r=0; r < thresholded.size().y; r++)
        for(int c=0; c < min(thresholded.size().x, edge); c++)
            thresholded[r][c] = 255 * (log_ratios[r][c] > threshold);
    
    //Dilate
    Image<byte> dilated = morphology(thresholded, getDisc(*radius), Morphology::B
      inaryDilate<byte>());

    transform(dilated.begin(), dilated.end(), dilated.begin(), bind1st(multiplies
      <int>(), 255));
    
    //Connected components of dilated image
    vector<ImageRef> fg;
    for(int r=0; r < thresholded.size().y; r++)
        for(int c=0; c < min(thresholded.size().x, edge); c++)
            if(dilated[r][c])
                fg.push_back(ImageRef(c, r));

    vector<vector<ImageRef> > regions;
    connected_components(fg, regions);

    return regions;
}
\end{DoxyCode}
\hypertarget{multispot5__headless_8cc_a760ab99c4eca79d376e1be1a74ce1464}{
\index{multispot5\_\-headless.cc@{multispot5\_\-headless.cc}!mmain@{mmain}}
\index{mmain@{mmain}!multispot5_headless.cc@{multispot5\_\-headless.cc}}
\paragraph[{mmain}]{\setlength{\rightskip}{0pt plus 5cm}void mmain (
\begin{DoxyParamCaption}
\item[{int}]{argc, }
\item[{char $\ast$$\ast$}]{argv}
\end{DoxyParamCaption}
)}}
\label{multispot5__headless_8cc_a760ab99c4eca79d376e1be1a74ce1464}


Definition at line 84 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().


\begin{DoxyCode}
{
    GUI.LoadFile("multispot5.cfg");
    int lastarg = GUI.parseArguments(argc, argv);
    if(lastarg >= argc)
    {   
        cerr << "Specify the images to load\n";
        exit(1);
    }
    vector<string> files(argv + lastarg, argv + argc);
    
    //Save this now since the de-checkpointing code will kl0bber it 
    //when it reloads the gvars
    string save_spots_file = GV3::get<string>("save_spots", "", -1);

    string checkpoint_file = GV3::get<string>("load_checkpoint", "", 1);

    if(checkpoint_file != "")
    {
        //Load and de-checkpointing
        ifstream chk;
        open_or_die(chk, checkpoint_file);
        
        StateParameters p;

        try{
            p = parse_log_file(chk);
        }
        catch(LogFileParseError e)
        {
            cerr << "SI TEH FUX0R11ONEone!oneleven: " << e.what << endl;
            exit(1);
        }
        
        vector<Image<float> > ims = load_and_normalize_images(files);

        //Restore kl0bbered variable
        GV3::get<string>("save_spots") = save_spots_file;
        
        ofstream save_spots;
        open_or_die(save_spots, save_spots_file);
        
        fit_spots_new(ims, p, save_spots, *null_graphics());

    }
     
    vector<Image<float> > ims = load_and_normalize_images(files);

    //Load the log_ratios image.
    //We will use this as a starting point for searching for spots.
    Image<double> log_ratios;
    try
    {
        log_ratios = img_load(GV3::get<string>("log_ratios", "", -1));
    }
    catch(Exceptions::All e)
    {
        cerr << "Error loading " << GV3::get<string>("log_ratios", "") << ": " <<
       e.what << endl;
        exit(1);
    }
    
    
    gvar3<int> cluster_to_show("cluster_to_show", 0, -1);
    gvar3<int> use_largest("use_largest", 0, 1);

    vector<vector<ImageRef> > regions;

    regions = get_regions(log_ratios);
    if(regions.size() == 0)
    {
        cerr << "There are no regions!\n";

        ofstream save_spots;
        open_or_die(save_spots, save_spots_file);
        save_spots << "NOREGIONS\n";

        exit(1);
    }
    
    if(*use_largest && !regions.empty())
    {
        *cluster_to_show=0;
        for(unsigned int i=1; i < regions.size(); i++)
            if(regions[i].size() > regions[*cluster_to_show].size())
                *cluster_to_show = i;
                
    }
    else
        *cluster_to_show = max(min(*cluster_to_show, (int)regions.size() - 1), 0)
      ;

    
    auto_ptr<FitSpotsGraphics> gr = null_graphics();
    place_and_fit_spots(ims, regions[*cluster_to_show], log_ratios, save_spots_fi
      le, *gr);
}
\end{DoxyCode}
\hypertarget{multispot5__headless_8cc_a3c04138a5bfe5d72780bb7e82a18e627}{
\index{multispot5\_\-headless.cc@{multispot5\_\-headless.cc}!main@{main}}
\index{main@{main}!multispot5_headless.cc@{multispot5\_\-headless.cc}}
\paragraph[{main}]{\setlength{\rightskip}{0pt plus 5cm}int main (
\begin{DoxyParamCaption}
\item[{int}]{argc, }
\item[{char $\ast$$\ast$}]{argv}
\end{DoxyParamCaption}
)}}
\label{multispot5__headless_8cc_a3c04138a5bfe5d72780bb7e82a18e627}


Definition at line 180 of file multispot5\_\-headless.cc.



References mmain().


\begin{DoxyCode}
{
    try{
        mmain(argc, argv);
    }
    catch(Exceptions::All e)
    {
        cerr << "Fatal error: " << e.what << endl;
    }
}
\end{DoxyCode}
