EMAN::FRCCmp Class Reference

FRCCmp returns a quality factor based on FRC between images. More...

#include <cmp.h>

Inheritance diagram for EMAN::FRCCmp:

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

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 = "frc"

Detailed Description

FRCCmp returns a quality factor based on FRC between images.

Fourier ring correlation (FRC) is a measure of statistical dependency between two averages, computed by comparison of rings in Fourier space. 1 means prefect agreement. 0 means no correlation.

Definition at line 463 of file cmp.h.


Member Function Documentation

float FRCCmp::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:
image The first image to be compared.
with The second image to be comppared.
Returns:
The comparison result. Smaller better by default

Implements EMAN::Cmp.

Definition at line 1069 of file cmp.cpp.

References EMAN::Ctf::apix, EMAN::EMData::calc_fourier_shell_correlation(), EMAN::EMData::calc_radial_dist(), EMAN::Ctf::compute_1d(), EMAN::EMData::copy(), EMAN::Ctf::CTF_SNR, EMAN::EMData::do_fft(), EMAN::EMData::do_fft_inplace(), ENTERFUNC, EXITFUNC, EMAN::EMObject::f, EMAN::EMData::get_attr(), EMAN::EMData::get_attr_default(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::EMData::has_attr(), InvalidCallException, EMAN::EMData::is_complex(), norm(), EMAN::Cmp::params, EMAN::EMData::set_attr(), EMAN::Dict::set_default(), EMAN::EMData::update(), EMAN::Cmp::validate_input_args(), and weight.

01070 {
01071         ENTERFUNC;
01072         validate_input_args(image, with);
01073 
01074         int snrweight = params.set_default("snrweight", 0);
01075         int ampweight = params.set_default("ampweight", 0);
01076         int sweight = params.set_default("sweight", 1);
01077         int nweight = params.set_default("nweight", 0);
01078         int zeromask = params.set_default("zeromask",0);
01079         float minres = params.set_default("minres",500.0f);
01080         float maxres = params.set_default("maxres",10.0f);
01081 
01082         if (zeromask) {
01083                 image=image->copy();
01084                 with=with->copy();
01085                 
01086                 int sz=image->get_xsize()*image->get_ysize()*image->get_zsize();
01087                 float *d1=image->get_data();
01088                 float *d2=with->get_data();
01089                 
01090                 for (int i=0; i<sz; i++) {
01091                         if (d1[i]==0.0 || d2[i]==0.0) { d1[i]=0.0; d2[i]=0.0; }
01092                 }
01093                 
01094                 image->update();
01095                 with->update();
01096                 image->do_fft_inplace();
01097                 with->do_fft_inplace();
01098                 image->set_attr("free_me",1); 
01099                 with->set_attr("free_me",1); 
01100         }
01101 
01102 
01103         if (!image->is_complex()) {
01104                 image=image->do_fft(); 
01105                 image->set_attr("free_me",1); 
01106         }
01107         if (!with->is_complex()) { 
01108                 with=with->do_fft(); 
01109                 with->set_attr("free_me",1); 
01110         }
01111 
01112         static vector < float >default_snr;
01113 
01114 //      if (image->get_zsize() > 1) {
01115 //              throw ImageDimensionException("2D only");
01116 //      }
01117 
01118 //      int nx = image->get_xsize();
01119         int ny = image->get_ysize();
01120         int ny2=ny/2+1;
01121 
01122         vector < float >fsc;
01123 
01124                 
01125 
01126         fsc = image->calc_fourier_shell_correlation(with,1);
01127 
01128         // The fast hypot here was supposed to speed things up. Little effect
01129 //      if (image->get_zsize()>1) fsc = image->calc_fourier_shell_correlation(with,1);
01130 //      else {
01131 //              double *sxy = (double *)malloc(ny2*sizeof(double)*4);
01132 //              double *sxx = sxy+ny2;
01133 //              double *syy = sxy+2*ny2;
01134 //              double *norm= sxy+3*ny2;
01135 //
01136 //              float *df1=image->get_data();
01137 //              float *df2=with->get_data();
01138 //              int nx2=image->get_xsize();
01139 //
01140 //              for (int y=-ny/2; y<ny/2; y++) {
01141 //                      for (int x=0; x<nx2/2; x++) {
01142 //                              if (x==0 && y<0) continue;      // skip Friedel pair
01143 //                              short r=Util::hypot_fast_int(x,y);
01144 //                              if (r>ny2-1) continue;
01145 //                              int l=x*2+(y<0?ny+y:y)*nx2;
01146 //                              sxy[r]+=df1[l]*df2[l]+df1[l+1]*df2[l+1];
01147 //                              sxx[r]+=df1[l]*df1[l];
01148 //                              syy[r]+=df2[l]*df2[l];
01149 //                              norm[r]+=1.0;
01150 //                      }
01151 //              }
01152 //              fsc.resize(ny2*3);
01153 //              for (int r=0; r<ny2; r++) {
01154 //                      fsc[r]=r*0.5/ny2;
01155 //                      fsc[ny2+r]=sxy[r]/(sqrt(sxx[r])*sqrt(syy[r]));
01156 //                      fsc[ny2*2+r]=norm[r];
01157 //              }
01158 //              free(sxy);
01159 //      }
01160 
01161         vector<float> snr;
01162         if (snrweight) {
01163                 Ctf *ctf = NULL;
01164                 if (!image->has_attr("ctf")) {
01165                         if (!with->has_attr("ctf")) throw InvalidCallException("SNR weight with no CTF parameters");
01166                         ctf=with->get_attr("ctf");
01167                 }
01168                 else ctf=image->get_attr("ctf");
01169 
01170                 float ds=1.0f/(ctf->apix*ny);
01171                 snr=ctf->compute_1d(ny,ds,Ctf::CTF_SNR);
01172                 if(ctf) {delete ctf; ctf=0;}
01173         }
01174 
01175         vector<float> amp;
01176         if (ampweight) amp=image->calc_radial_dist(ny/2,0,1,0);
01177 
01178         // Min/max modifications to weighting
01179         float pmin,pmax;
01180         if (minres>0) pmin=((float)image->get_attr("apix_x")*image->get_ysize())/minres;                //cutoff in pixels, assume square
01181         else pmin=0;
01182         if (maxres>0) pmax=((float)image->get_attr("apix_x")*image->get_ysize())/maxres;
01183         else pmax=0;
01184 
01185         double sum=0.0, norm=0.0;
01186 
01187         for (int i=0; i<ny/2; i++) {
01188                 double weight=1.0;
01189                 if (sweight) weight*=fsc[(ny2)*2+i];
01190                 if (ampweight) weight*=amp[i];
01191                 if (snrweight) weight*=snr[i];
01192                 if (pmin>0) weight*=(tanh(5.0*(i-pmin)/pmin)+1.0)/2.0;
01193                 if (pmax>0) weight*=(1.0-tanh(i-pmax))/2.0;
01194                 
01195                 sum+=weight*fsc[ny2+i];
01196                 norm+=weight;
01197 //              printf("%d\t%f\t%f\n",i,weight,fsc[ny/2+1+i]);
01198         }
01199 
01200         // This performs a weighting that tries to normalize FRC by correcting from the number of particles represented by the average
01201         sum/=norm;
01202         if (nweight && with->get_attr_default("ptcl_repr",0) && sum>=0 && sum<1.0) {
01203                 sum=sum/(1.0-sum);                                                      // convert to SNR
01204                 sum/=(float)with->get_attr_default("ptcl_repr",0);      // divide by ptcl represented
01205                 sum=sum/(1.0+sum);                                                      // convert back to correlation
01206         }
01207 
01208         if (image->has_attr("free_me")) delete image;
01209         if (with->has_attr("free_me")) delete with;
01210 
01211         EXITFUNC;
01212 
01213 
01214         //.Note the negative! This is because EMAN2 follows the convention that
01215         // smaller return values from comparitors indicate higher similarity -
01216         // this enables comparitors to be used in a generic fashion.
01217         return (float)-sum;
01218 }

string EMAN::FRCCmp::get_desc (  )  const [inline, virtual]

Implements EMAN::Cmp.

Definition at line 473 of file cmp.h.

00474                 {
00475                         return "Computes the mean Fourier Ring Correlation between the image and reference (with optional weighting factors).";
00476                 }

string EMAN::FRCCmp::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 468 of file cmp.h.

References NAME.

00469                 {
00470                         return NAME;
00471                 }

TypeDict EMAN::FRCCmp::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 483 of file cmp.h.

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

00484                 {
00485                         TypeDict d;
00486                         d.put("snrweight", EMObject::INT, "If set, the SNR of 'this' will be used to weight the result. If 'this' lacks CTF info, it will check 'with'. (default=0)");
00487                         d.put("ampweight", EMObject::INT, "If set, the amplitude of 'this' will be used to weight the result (default=0)");
00488                         d.put("sweight", EMObject::INT, "If set, weight the (1-D) average by the number of pixels in each ring (default=1)");
00489                         d.put("nweight", EMObject::INT, "Downweight similarity based on number of particles in reference (default=0)");
00490                         d.put("zeromask", EMObject::INT, "Treat regions in either image that are zero as a mask");
00491                         d.put("minres", EMObject::FLOAT, "Lowest resolution to use in comparison (soft cutoff). Requires accurate A/pix in image. <0 disables. Default=500");
00492                         d.put("maxres", EMObject::FLOAT, "Highest resolution to use in comparison (soft cutoff). Requires accurate A/pix in image. <0 disables.  Default=10");
00493                         return d;
00494                 }

static Cmp* EMAN::FRCCmp::NEW (  )  [inline, static]

Definition at line 478 of file cmp.h.

00479                 {
00480                         return new FRCCmp();
00481                 }


Member Data Documentation

const string FRCCmp::NAME = "frc" [static]

Definition at line 496 of file cmp.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Mon Jul 19 12:42:28 2010 for EMAN2 by  doxygen 1.4.7