EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes
EMAN::OptSubCmp Class Reference

Uses math.sub.optimal to remove the density of the reference from the image as much as possible. More...

#include <cmp.h>

Inheritance diagram for EMAN::OptSubCmp:
Inheritance graph
[legend]
Collaboration diagram for EMAN::OptSubCmp:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 OptSubCmp ()
float cmp (EMData *image, EMData *with) const
 To compare 'image' with another image passed in through its parameters.
string get_name () const
 Get the Cmp's name.
string get_desc () const
TypeDict get_param_types () const
 Get Cmp parameter information in a dictionary.

Static Public Member Functions

static CmpNEW ()

Static Public Attributes

static const string NAME = "optsub"

Detailed Description

Uses math.sub.optimal to remove the density of the reference from the image as much as possible.

What is left should be pure noise if there is a good match. If the match is not as good there should be additional residual power. This comparator returns the average residual power after subtraction weighted in various ways

Definition at line 439 of file cmp.h.


Constructor & Destructor Documentation

EMAN::OptSubCmp::OptSubCmp ( ) [inline]

Definition at line 442 of file cmp.h.

Referenced by NEW().

{}

Member Function Documentation

float OptSubCmp::cmp ( EMData image,
EMData with 
) const [virtual]

To compare 'image' with another image passed in through its parameters.

An optional transformation may be used to transform the 2 images.

Parameters:
imageThe first image to be compared.
withThe second image to be comppared.
Returns:
The comparison result. Smaller better by default

Implements EMAN::Cmp.

Definition at line 1404 of file cmp.cpp.

References ENTERFUNC, EMAN::EMData::get_attr(), EMAN::EMData::has_attr(), EMAN::EMData::mult(), EMAN::Cmp::params, EMAN::EMData::process(), EMAN::Dict::set_default(), and EMAN::Cmp::validate_input_args().

{
        ENTERFUNC;
        validate_input_args(image, with);

//      int snrweight = params.set_default("snrweight", 0);
//      int ampweight = params.set_default("ampweight", 0);
//      int sweight = params.set_default("sweight", 1);
//      int nweight = params.set_default("nweight", 0);
        int ctfweight = params.set_default("ctfweight",0);
        int zeromask = params.set_default("zeromask",0);
//      int swap = params.set_default("swap",0);
        float minres = params.set_default("minres",200.0f);
        float maxres = params.set_default("maxres",10.0f);
        EMData *mask = params.set_default("mask",(EMData *)NULL);
        
//      float ds=1.0f/((float)image->get_attr("apix_x")*(int)image->get_ysize());
        float apix=(float)image->get_attr("apix_x");

        // Sometimes we will get the "raw" image with CTF as image and sometimes as with, we always want to subtract the less noisy
        // reference, so if one has CTF parameters (even if ctfweight isn't used) we always pass it in as the primary
        EMData *diff;
        if (image->has_attr("ctf")) diff=image->process("math.sub.optimal",Dict("ref",with,"return_presigma",1,"low_cutoff_frequency",apix/minres ,"high_cutoff_frequency",apix/maxres,"ctfweight",ctfweight));
        else diff=with->process("math.sub.optimal",Dict("ref",image,"return_presigma",1,"low_cutoff_frequency",apix/minres ,"high_cutoff_frequency",apix/maxres,"ctfweight",ctfweight));

        if (mask!=NULL) diff->mult(*mask);
        if (zeromask) {
                EMData *tmp=with->process("threshold.notzero");
                diff->mult(*tmp);
                delete tmp;
        }
        
//      diff->process_inplace("filter.highpass.tophat",Dict("cutoff_freq",(float)1.0/minres));
//      diff->process_inplace("filter.lowpass.tophat",Dict("cutoff_freq",(float)1.0/maxres));
        
        float ret=(float)diff->get_attr("sigma")/(float)diff->get_attr("sigma_presub");
        delete diff;
        return ret;
        
        
//      EMData *diff=image->process("math.sub.optimal",Dict("ref",with,"return_fft",1));
//      
//      // Very expensive to use a mask, since it requires another ift/fft pair
//      if (mask!=NULL) {
//              EMData *tmp = diff->do_ift();
//              tmp->mult(*mask);
//              delete diff;
//              diff=tmp->do_fft();
//              delete tmp;
//      }
//      
//      // This gives us basically the 1-D power spectrum of what's left after subtraction (and masking)
//      vector<float> dist=diff->calc_radial_dist(diff->get_ysize()/2,0.0f,1.0f,1);
//      int s0=int(floor(1.0/(minres*ds)));
//      int s1=int(ceil(1.0/(maxres*ds)));
//      if (s0<2) s0=2;
//      
//      if (s1<=s0) throw InvalidCallException("OptSubCmp error. minres must be greater than maxres.");
// //   printf("%d %d\n",s0,s1);
//      
//      double sum=0.0f,sum2=0.0f;
//      for (int i=s0; i<s1; i++) sum+=dist[i]*i;
//      sum/=image->get_size()*s1;
//      
//      delete diff;
//      return sum;
}
string EMAN::OptSubCmp::get_desc ( ) const [inline, virtual]

Implements EMAN::Cmp.

Definition at line 451 of file cmp.h.

                {
                        return "Residual power left in the image after optimally subtracting the reference with math.sub.optimal. Smaller values indicate a closer match.";
                }
string EMAN::OptSubCmp::get_name ( ) const [inline, virtual]

Get the Cmp's name.

Each Cmp is identified by a unique name.

Returns:
The Cmp's name.

Implements EMAN::Cmp.

Definition at line 446 of file cmp.h.

References NAME.

                {
                        return NAME;
                }
TypeDict EMAN::OptSubCmp::get_param_types ( ) const [inline, virtual]

Get Cmp parameter information in a dictionary.

Each parameter has one record in the dictionary. Each record contains its name, data-type, and description.

Returns:
A dictionary containing the parameter info.

Implements EMAN::Cmp.

Definition at line 461 of file cmp.h.

References EMAN::EMObject::BOOL, EMAN::EMObject::EMDATA, EMAN::EMObject::FLOAT, and EMAN::TypeDict::put().

                {
                        TypeDict d;
                        d.put("minres", EMObject::FLOAT, "Lowest resolution to use in comparison (soft cutoff). Requires accurate A/pix in image. <0 disables. Default=200");
                        d.put("maxres", EMObject::FLOAT, "Highest resolution to use in comparison (soft cutoff). Requires accurate A/pix in image. <0 disables.  Default=10");
                        d.put("zeromask", EMObject::BOOL, "Treat zero regions in 'with' as a mask");
                        d.put("ctfweight", EMObject::BOOL, "Weight frequencies using CTF");
//                      d.put("swap", EMObject::BOOL, "Swaps the identity of this and with, since A->B comparisons are not equivalent to B->A");
                        d.put("mask", EMObject::EMDATA, "Real space mask. Only computes the residual power under the mask. Significant speed penalty if specified. Default=None.");
                        return d;
                }
static Cmp* EMAN::OptSubCmp::NEW ( ) [inline, static]

Definition at line 456 of file cmp.h.

References OptSubCmp().

                {
                        return new OptSubCmp();
                }

Member Data Documentation

const string OptSubCmp::NAME = "optsub" [static]

Definition at line 473 of file cmp.h.

Referenced by get_name().


The documentation for this class was generated from the following files: