\hypertarget{group__gStormImages}{
\subsection{Storm imagery classes (basic image processing)}
\label{group__gStormImages}\index{Storm imagery classes (basic image processing)@{Storm imagery classes (basic image processing)}}
}
\subsubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
vector$<$ Image$<$ float $>$ $>$ \hyperlink{group__gStormImages_ga4509e1e3b18bde496a21bd5f7585fe6b}{load\_\-and\_\-preprocess\_\-images2} (const vector$<$ string $>$ \&names)
\item 
vector$<$ Image$<$ float $>$ $>$ \hyperlink{group__gStormImages_gac1d45d4c1c6cbc126ad5d73fb55a8fdf}{load\_\-and\_\-preprocess\_\-images} (const vector$<$ string $>$ \&names)
\item 
vector$<$ Image$<$ float $>$ $>$ \hyperlink{group__gStormImages_gaa2cd758c4ae34fc803f8bad9b80e5832}{load\_\-and\_\-normalize\_\-images} (const vector$<$ string $>$ \&files)
\end{DoxyCompactItemize}


\subsubsection{Function Documentation}
\hypertarget{group__gStormImages_ga4509e1e3b18bde496a21bd5f7585fe6b}{
\index{Storm imagery classes (basic image processing)@{Storm imagery classes (basic image processing)}!load\_\-and\_\-preprocess\_\-images2@{load\_\-and\_\-preprocess\_\-images2}}
\index{load\_\-and\_\-preprocess\_\-images2@{load\_\-and\_\-preprocess\_\-images2}!Storm imagery classes (basic image processing)@{Storm imagery classes (basic image processing)}}
\paragraph[{load\_\-and\_\-preprocess\_\-images2}]{\setlength{\rightskip}{0pt plus 5cm}vector$<$Image$<$float$>$ $>$ load\_\-and\_\-preprocess\_\-images2 (
\begin{DoxyParamCaption}
\item[{const vector$<$ string $>$ \&}]{names}
\end{DoxyParamCaption}
)}}
\label{group__gStormImages_ga4509e1e3b18bde496a21bd5f7585fe6b}


Load all images from disk and do the initial preprocessing. 


\begin{DoxyParams}{Parameters}
{\em names} & List of filenames to load. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
preprocessed images. 
\end{DoxyReturn}


Definition at line 42 of file storm\_\-imagery.cc.


\begin{DoxyCode}
{
    vector<Image<float> > ims;
    //Load images
    for(unsigned int i=0; i < names.size(); i++)
    {
        Image<float> im = img_load(names[i]);
        ims.push_back(im);

        if(ims.back().size() != ims[0].size())
        {
            cerr << "Error with image " << names[i] << ":  all images must be the
       same size!\n";
            exit(1);
        }
    }
    double mean, variance;
    tie(mean, variance) = mean_and_variance(ims);
    {
        for(unsigned int i=0; i < ims.size(); i++)
            transform(ims[i].begin(), ims[i].end(), ims[i].begin(), bind2nd(minus
      <double>(), mean));
        for(unsigned int i=0; i < ims.size(); i++)
            transform(ims[i].begin(), ims[i].end(), ims[i].begin(), bind1st(multi
      plies<double>(), 1/ sqrt(variance)));
    }
    
    tie(mean, variance) = mean_and_variance(ims);

    cerr << "Rescaled:\n";
    cerr << "mean = " << mean << endl;
    cerr << "std  = " << sqrt(variance) << endl;



    //Normalize...

    //Fit the background model
    ImageRef size = ims[0].size();
    Vector<10> p = Zeros;   
    p[6]=-3;
    p[9]=-4;

    Image<Vector<6> > monomials(size);
    Image<double> polynomial(size);
    for(int yy=0; yy < size.y; yy++)
        for(int xx=0; xx < size.x; xx++)
        {
            double x = xx *2./ size.x -1 ;
            double x2 = x*x;
            double y = yy *2./size.y - 1;
            double y2 = yy;
            monomials[yy][xx] = makeVector(1, x, y, x2, x*y, y2);
        }
                    

    for(int i=0;i < 100;i++)
    {
        for(int yy=0; yy < size.y; yy++)
            for(int xx=0; xx < size.x; xx++)
                polynomial[yy][xx] = monomials[yy][xx] *  p.slice<0,6>();

        WLS<10> wls;    
        for(unsigned int i=0; i < ims.size(); i++)
            for(int yy=0; yy < size.y; yy++)
                for(int xx=0; xx < size.x; xx++)
                {
                    double t = i *1. / ims.size();
                    double func = polynomial[yy][xx] * (exp(p[6]*t) + p[8]*exp(p[
      9]*t)) + p[7];

                    Vector<10> mJ;

                    mJ.slice<0,6>() = exp(p[6]*t)* monomials[yy][xx];
                    //mJ.slice<3,3>() = Zeros;
                    mJ[6] = polynomial[yy][xx] * exp(p[6]*t) * t;
                    //mJ[6] = func  * t;
                    mJ[7] = 1;

                    mJ[8] = polynomial[yy][xx] * exp(p[9]*t);
                    mJ[9] = polynomial[yy][xx] * exp(p[9]*t) * t * p[8];

                    double err = ims[i][yy][xx] - func;

                    double w;

                    
                    if(err > 0)
                        w = .01 / (abs(err) + .01);
                    else
                        w = 1;

                    wls.add_mJ(func - ims[i][yy][xx], -mJ, w);
                }
        
        wls.add_prior(10);
        wls.compute();

        p += wls.get_mu();

        cout << p << endl << endl;
    }
    
    for(unsigned int i=0; i < ims.size(); i++)
        for(int yy=0; yy < size.y; yy++)
            for(int xx=0; xx < size.x; xx++)
            {
                double x = xx *2./ size.x -1 ;
                double x2 = x*x;
                double y = yy *2./size.y - 1;
                double y2 = yy;
                double t = i *1. / ims.size();
                Vector<6> f = makeVector(1, x, y, x2, x*y, y2);
                
                double func = f * p.slice<0,6>() * (exp(p[6]*t) + p[8]*exp(p[9]*t
      )) + p[7];
                ims[i][yy][xx] -= func;
            }

    tie(mean, variance) = mean_and_variance(ims);

    //A sanity check.
    cerr << "The mean should be small compared to std:\n";
    cerr << "mean = " << mean << endl;
    cerr << "std  = " << sqrt(variance) << endl;

    //Scale by the variance.
    {
        for(unsigned int i=0; i < ims.size(); i++)
            transform(ims[i].begin(), ims[i].end(), ims[i].begin(), bind1st(multi
      plies<double>(), 1/ sqrt(variance)));
    }
    tie(mean, variance) = mean_and_variance(ims);

    cerr << "Rescaled:\n";
    cerr << "mean = " << mean << endl;
    cerr << "std  = " << sqrt(variance) << endl;

    return ims;
}
\end{DoxyCode}
\hypertarget{group__gStormImages_gac1d45d4c1c6cbc126ad5d73fb55a8fdf}{
\index{Storm imagery classes (basic image processing)@{Storm imagery classes (basic image processing)}!load\_\-and\_\-preprocess\_\-images@{load\_\-and\_\-preprocess\_\-images}}
\index{load\_\-and\_\-preprocess\_\-images@{load\_\-and\_\-preprocess\_\-images}!Storm imagery classes (basic image processing)@{Storm imagery classes (basic image processing)}}
\paragraph[{load\_\-and\_\-preprocess\_\-images}]{\setlength{\rightskip}{0pt plus 5cm}vector$<$Image$<$float$>$ $>$ load\_\-and\_\-preprocess\_\-images (
\begin{DoxyParamCaption}
\item[{const vector$<$ string $>$ \&}]{names}
\end{DoxyParamCaption}
)}}
\label{group__gStormImages_gac1d45d4c1c6cbc126ad5d73fb55a8fdf}


Load all images from disk and do the initial preprocessing. 

Currently this is a high pass filter to make the resultimg images zero mean.

The filter is controlled with the {\ttfamily preprocess.lpf} and {\ttfamily preprocess.skip} Gvars

See also load\_\-and\_\-preprocess\_\-image()


\begin{DoxyParams}{Parameters}
{\em names} & List of filenames to load. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
preprocessed images. 
\end{DoxyReturn}


Definition at line 191 of file storm\_\-imagery.cc.



Referenced by load\_\-and\_\-normalize\_\-images().


\begin{DoxyCode}
{
    vector<Image<float> > ims;

    //float wide = GV3::get<float>("preprocess.lpf", 0., -1);
    //bool p = GV3::get<bool>("preprocess.skip", 0, -1);
    
    for(unsigned int i=0; i < names.size(); i++)
    {
        Image<float> im = img_load(names[i]);
    
        ims.push_back(preprocess_image(im));
    
        if(ims.back().size() != ims[0].size())
        {
            cerr << "Error with image " << names[i] << ":  all images must be the
       same size!\n";
            exit(1);
        }
    }
    return ims;
}
\end{DoxyCode}
\hypertarget{group__gStormImages_gaa2cd758c4ae34fc803f8bad9b80e5832}{
\index{Storm imagery classes (basic image processing)@{Storm imagery classes (basic image processing)}!load\_\-and\_\-normalize\_\-images@{load\_\-and\_\-normalize\_\-images}}
\index{load\_\-and\_\-normalize\_\-images@{load\_\-and\_\-normalize\_\-images}!Storm imagery classes (basic image processing)@{Storm imagery classes (basic image processing)}}
\paragraph[{load\_\-and\_\-normalize\_\-images}]{\setlength{\rightskip}{0pt plus 5cm}vector$<$Image$<$float$>$ $>$ load\_\-and\_\-normalize\_\-images (
\begin{DoxyParamCaption}
\item[{const vector$<$ string $>$ \&}]{files}
\end{DoxyParamCaption}
)}}
\label{group__gStormImages_gaa2cd758c4ae34fc803f8bad9b80e5832}


Wrapper for \hyperlink{group__gStormImages_gac1d45d4c1c6cbc126ad5d73fb55a8fdf}{load\_\-and\_\-preprocess\_\-images()} to allow more flexible behaviour. 


\begin{DoxyParams}{Parameters}
{\em files} & List of filenames to load. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
preprocessed images. 
\end{DoxyReturn}


Definition at line 271 of file storm\_\-imagery.cc.



References auto\_\-fixed\_\-scaling(), and load\_\-and\_\-preprocess\_\-images().



Referenced by mmain().


\begin{DoxyCode}
{
    //Load the raw data, and then load the spot parameters.
    vector<Image<float> > ims = load_and_preprocess_images(files);
    double mean, variance;
    tie(mean, variance) = mean_and_variance(ims);

    if(GV3::get<bool>("preprocess.fixed_scaling", 0, FATAL_IF_NOT_DEFINED))
    {
        bool skip = GV3::get<bool>("preprocess.skip");
        if(!skip)
        {
            cerr << "WARNING WARNING WARNING WARNING!!!!!!!!!!!!!!!\n";
            cerr << "preprocessing and fixed scaling selected!!!\n";
            exit(1);
        }

        double sub, div;
        if(GV3::get<bool>("preprocess.fixed_scaling.auto", 0, FATAL_IF_NOT_DEFINE
      D))
        {
            double frac = GV3::get<double>("preprocess.fixed_scaling.auto.proport
      ion", 0, FATAL_IF_NOT_DEFINED);
            tie(sub, div) = auto_fixed_scaling(ims, frac);
        }
        else
        {
            sub = GV3::get<double>("preprocess.fixed_scaling.subtract", 0, FATAL_
      IF_NOT_DEFINED);
            div = GV3::get<double>("preprocess.fixed_scaling.divide", 0, FATAL_IF
      _NOT_DEFINED);
        }

        for(unsigned int i=0; i < ims.size(); i++)
            for(Image<float>::iterator j=ims[i].begin(); j != ims[i].end(); j++)
                *j = (*j - sub)/div;
    }
    else
    {
        //A sanity check.
        cerr << "The mean should be small compared to std:\n";
        cerr << "mean = " << mean << endl;
        cerr << "std  = " << sqrt(variance) << endl;

        //Scale by the variance.
        {
            for(unsigned int i=0; i < ims.size(); i++)
                transform(ims[i].begin(), ims[i].end(), ims[i].begin(), bind1st(m
      ultiplies<double>(), 1/ sqrt(variance)));
        }
    }

    tie(mean, variance) = mean_and_variance(ims);

    //A sanity check.
    cerr << "Rescaled:\n";
    cerr << "mean = " << mean << endl;
    cerr << "std  = " << sqrt(variance) << endl;

    return ims;
}
\end{DoxyCode}
