EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
EMAN::TomoWedgeFscCmp Class Reference

Both images should be FFTs. More...

#include <cmp.h>

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

Public Member Functions

virtual float cmp (EMData *image, EMData *with) const
 To compare 'image' with another image passed in through its parameters. More...
 
virtual string get_name () const
 Get the Cmp's name. More...
 
virtual string get_desc () const
 
TypeDict get_param_types () const
 Get Cmp parameter information in a dictionary. More...
 
- Public Member Functions inherited from EMAN::Cmp
virtual ~Cmp ()
 
virtual Dict get_params () const
 Get the Cmp parameters in a key/value dictionary. More...
 
virtual void set_params (const Dict &new_params)
 Set the Cmp parameters using a key/value dictionary. More...
 

Static Public Member Functions

static CmpNEW ()
 

Static Public Attributes

static const string NAME = "fsc.tomo.auto"
 

Additional Inherited Members

- Protected Member Functions inherited from EMAN::Cmp
void validate_input_args (const EMData *image, const EMData *with) const
 
- Protected Attributes inherited from EMAN::Cmp
Dict params
 

Detailed Description

Both images should be FFTs.

Computes a CCC excluding pixels with very small value (assumes they are missing wedge) Returns overlap amount as "fft_overlap" in "image"

Date
2010-10-18

Definition at line 393 of file cmp.h.

Member Function Documentation

◆ cmp()

float TomoWedgeFscCmp::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 748 of file cmp.cpp.

749{
750 ENTERFUNC;
751 EMData *imageo=image;
752 EMData *witho=with;
753 if (!image->is_complex()) image=image->do_fft();
754 if (!with ->is_complex()) with =with ->do_fft();
755 if (image->get_xsize()!=with->get_xsize() || image->get_ysize()!=with->get_ysize() || image->get_zsize()!=with->get_zsize()) throw InvalidCallException("Error: TomoWedgeFscCmp requires 2 images the same size");
756
757 int nx=image->get_xsize();
758 int ny=image->get_ysize();
759 int nz=image->get_zsize();
760
761 float sigmaimgval = params.set_default("sigmaimgval",0.5f);
762 float sigmawithval = params.set_default("sigmawithval",0.5f);
763
764 bool retcurve = params.set_default("retcurve",false);
765 // User can pass in a sigma vector if they like, otherwise we call it 1/10 of the standard deviation in each shell
766 // This has proven to be a good cutoff for identifying the missing wedge voxels, without throwing away too many
767 // voxels if the image is complete in Fourier space (no wedge)
768 vector<float> sigmaimg;
769 if (params.has_key("sigmaimg")) sigmaimg=params["sigmaimg"];
770 else {
771 sigmaimg=image->calc_radial_dist(nx/2,0,1,4);
772 for (int i=0; i<nx/2; i++) sigmaimg[i]*=sigmaimg[i]*sigmaimgval; // The value here is amplitude, we square to make comparison less expensive
773 }
774
775 vector<float> sigmawith;
776 if (params.has_key("sigmawith")) sigmawith = params["sigmawith"];
777 else {
778 sigmawith=with->calc_radial_dist(nx/2,0,1,4);
779 for (int i=0; i<nx/2; i++) sigmawith[i]*=sigmawith[i]*sigmawithval; // The value here is amplitude, we square to make comparison less expensive
780 }
781
782 float apix = params.set_default("apix",image->get_attr_default("apix_x", 1.0f));
783 //get min and max res
784 float minres = params.set_default("minres",0.0f);
785 float maxres = params.set_default("maxres", 0.0f);
786
787 int pmin = params.set_default("pmin",3);
788 int pmax = params.set_default("pmax", ny/2);
789
790 if (minres>0)
791 pmin=(int)floor((apix*ny)/minres); //cutoff in pixels, assume square
792 if (maxres>0)
793 pmax=(int)ceil((apix*ny)/maxres);
794
795 int negative = params.set_default("negative",1);
796
797 double sum=0;
798 double sumsq1=0;
799 double sumsq2=0;
800 double norm=0;
801 vector<float> curve(nx/2), sqcv1(nx/2), sqcv2(nx/2);
802 for (int z=0; z<nz; z++) {
803 int za=z<nz/2?z:nz-z;
804 if (za>pmax) continue;
805 for (int y=0; y<ny; y++) {
806 int ya=y<ny/2?y:ny-y;
807 if (ya>pmax) continue;
808 for (int x=0; x<nx; x+=2) {
809 float r2=Util::hypot3sq(x/2,ya,za); // origin at 0,0; periodic
810 int r=int(sqrtf(r2));
811// float rf=Util::hypot3(x/2,y<ny/2?y:ny-y,z<nz/2?z:nz-z); // origin at 0,0; periodic
812// int r=int(rf);
813 if (r<pmin || r>pmax) continue;
814
815 float v1r=image->get_value_at(x,y,z);
816 float v1i=image->get_value_at(x+1,y,z);
817 float v1=Util::square_sum(v1r,v1i);
818 if (v1<sigmaimg[r]) continue;
819
820 float v2r=with->get_value_at(x,y,z);
821 float v2i=with->get_value_at(x+1,y,z);
822 float v2=Util::square_sum(v2r,v2i);
823 if (v2<sigmawith[r]) continue;
824
825 sum+=(v1r*v2r+v1i*v2i)/r2; // The r downweighting of points allows us to integrate over the entire image rather than computing a FSC and integrating that
826 sumsq1+=v1/r2;
827// if (Util::is_nan(sumsq1)) { printf("TomoWedgeCccCmp: NaN encountered: %d %d %d %f %f %f\n",x,y,z,v1r,v1i,v1); }
828 sumsq2+=v2/r2;
829 norm+=1.0;
830 if (retcurve){
831 curve[r]+=v1r*v2r+v1i*v2i;
832 sqcv1[r]+=v1;
833 sqcv2[r]+=v2;
834 }
835 }
836 }
837 }
838 image->set_attr("fft_overlap",(float)(2.0*norm/(image->get_xsize()*image->get_ysize()*image->get_zsize())));
839// printf("%f\t%f\t%f\t%f\t%f\n",s1,s2,sumsq1,sumsq2,norm);
840 if (retcurve){
841 for(int i=0; i<nx/2; i++){
842 if (sqcv1[i]==0) sqcv1[i]=1;
843 if (sqcv2[i]==0) sqcv2[i]=1;
844 curve[i]=curve[i]/(sqrt(sqcv1[i])*sqrt(sqcv2[i]));
845 }
846 image->set_attr("fsc_curve", curve);
847 }
848
849 if (imageo!=image) delete image;
850 if (witho!=with) delete with;
851
852 if (negative) sum*=-1.0;
853 return float(sum/(sqrt(sumsq1)*sqrt(sumsq2)));
854}
Dict params
Definition: cmp.h:132
type set_default(const string &key, type val)
Default setting behavior This can be achieved using a template - d.woolford Jan 2008 (before there wa...
Definition: emobject.h:569
bool has_key(const string &key) const
Ask the Dictionary if it as a particular key.
Definition: emobject.h:511
EMData stores an image's data and defines core image processing routines.
Definition: emdata.h:82
vector< float > calc_radial_dist(int n, float x0, float dx, int inten)
calculates radial distribution.
Definition: emdata.cpp:2781
static int hypot3sq(int x, int y, int z)
Euclidean distance function squared in 3D: f(x,y,z) = (x*x + y*y + z*z);.
Definition: util.h:805
static float square_sum(float x, float y)
Calcuate (x*x + y*y).
Definition: util.h:764
EMData * sqrt() const
return square root of current image
bool is_complex() const
Is this a complex image?
#define InvalidCallException(desc)
Definition: exception.h:348
#define ENTERFUNC
Definition: log.h:48
#define y(i, j)
Definition: projector.cpp:1516
#define x(i)
Definition: projector.cpp:1517

References EMAN::EMData::calc_radial_dist(), ENTERFUNC, EMAN::Dict::has_key(), EMAN::Util::hypot3sq(), InvalidCallException, is_complex(), EMAN::Cmp::params, EMAN::Dict::set_default(), sqrt(), EMAN::Util::square_sum(), x, and y.

◆ get_desc()

virtual string EMAN::TomoWedgeFscCmp::get_desc ( ) const
inlinevirtual

Implements EMAN::Cmp.

Definition at line 403 of file cmp.h.

404 {
405 return "FSC of two FFTs with missing wedge taken into account via a dynamic threshold. Also stores overlap as 'fft_overlap' in \
406first input image on return. This comparator can take the missing wedge into account automatically without any precomputation of wedge \
407orientation. If sigmaimg and/or sigmawith are provided, they must contain floating point arrays with at least as many elements as the \
408Fourier radius in pixels, and these curves represent the thresholds for each image for including the values in the FSC, or considering them \
409to be missing values. If not provided, these values will be computed automatically. These options are primarily provided for speed.";
410 }

◆ get_name()

virtual string EMAN::TomoWedgeFscCmp::get_name ( ) const
inlinevirtual

Get the Cmp's name.

Each Cmp is identified by a unique name.

Returns
The Cmp's name.

Implements EMAN::Cmp.

Definition at line 398 of file cmp.h.

399 {
400 return NAME;
401 }
static const string NAME
Definition: cmp.h:434

References NAME.

◆ get_param_types()

TypeDict EMAN::TomoWedgeFscCmp::get_param_types ( ) const
inlinevirtual

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 417 of file cmp.h.

418 {
419 TypeDict d;
420// d.put("norm", EMObject::BOOL,"Whether the cross correlation image should be normalized (should be for normalized images). Default is true.");
421// d.put("ccf", EMObject::EMDATA,"The ccf image, can be provided if it already exists to avoid recalculating it");
422 d.put("sigmaimg", EMObject::FLOATARRAY, "Res dependent amplitude threshold. If provided this must contain a floating point array with as many elements as the Fourier radius of the image. ");
423 d.put("sigmawith", EMObject::FLOATARRAY, "Resolution dependent coefficient for thresholding values included in the dot product in the 'with' image. Default = 0.1 and is normally fine");
424 d.put("sigmaimgval", EMObject::FLOAT, "Sigma coefficient for thresholding values included in the dot product. default = 0.5");
425 d.put("sigmawithval", EMObject::FLOAT, "Sigma coefficient for thresholding values included in the dot product in the 'with' image. Default = 0.5");
426 d.put("minres", EMObject::FLOAT, "The minimum resolution to accept (1/A) Default is 3 pixels. overwrites pmin");
427 d.put("maxres", EMObject::FLOAT, "The maximum resolution to accept (1/A) Default is axial Nyquist. overwrites pmax");
428 d.put("pmin", EMObject::INT, "The minimum resolution in pixels.");
429 d.put("pmax", EMObject::INT, "The maximum resolution in pixels.");
430 d.put("retcurve", EMObject::BOOL, "Return fsc curve in image header");
431 return d;
432 }

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

◆ NEW()

static Cmp * EMAN::TomoWedgeFscCmp::NEW ( )
inlinestatic

Definition at line 412 of file cmp.h.

413 {
414 return new TomoWedgeFscCmp();
415 }

Member Data Documentation

◆ NAME

const string TomoWedgeFscCmp::NAME = "fsc.tomo.auto"
static

Definition at line 434 of file cmp.h.

Referenced by get_name().


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