EMAN::PhaseCmp Class Reference

Amplitude weighted mean phase difference (radians) with optional SNR weight. More...

#include <cmp.h>

Inheritance diagram for EMAN::PhaseCmp:

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

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 ()


Detailed Description

Amplitude weighted mean phase difference (radians) with optional SNR weight.

SNR should be an array as returned by ctfcurve() 'with' should be the less noisy image, since it's amplitudes will be used to weight the phase residual. 2D only.

Use Phase Residual as a measure of similarity Differential phase residual (DPR) is a measure of statistical dependency between two averages, computed over rings in Fourier space as a function of ring radius (= spatial frequency, or resolution)

Definition at line 409 of file cmp.h.


Member Function Documentation

float PhaseCmp::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 722 of file cmp.cpp.

References EMAN::Util::angle_sub_2pi(), EMAN::Ctf::CTFOS, EMAN::EMData::do_fft(), ENTERFUNC, EXITFUNC, EMAN::EMData::get_const_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Util::hypot_fast(), norm(), ny, EMAN::EMData::ri2ap(), EMAN::Util::round(), sqrt(), EMAN::Cmp::validate_input_args(), x, and y.

00723 {
00724         ENTERFUNC;
00725 
00726 #ifdef EMAN2_USING_CUDA
00727         if (image->gpu_operation_preferred()) {
00728 //              cout << "Cuda cmp" << endl;
00729                 EXITFUNC;
00730                 return cuda_cmp(image,with);
00731         }
00732 #endif
00733         validate_input_args(image, with);
00734 
00735         static float *dfsnr = 0;
00736         static int nsnr = 0;
00737 
00738 //      if (image->get_zsize() > 1) {
00739 //              throw ImageDimensionException("2D only");
00740 //      }
00741 
00742         //int nx = image->get_xsize();
00743         int ny = image->get_ysize();
00744         //int nz = image->get_zsize();
00745 
00746         int np = (int) ceil(Ctf::CTFOS * sqrt(2.0f) * ny / 2) + 2;
00747 
00748         if (nsnr != np) {
00749                 nsnr = np;
00750                 dfsnr = (float *) realloc(dfsnr, np * sizeof(float));
00751 
00752                 //float w = Util::square(nx / 8.0f); // <- Not used currently
00753 
00754                 for (int i = 0; i < np; i++) {
00755 //                      float x2 = Util::square(i / (float) Ctf::CTFOS);
00756 //                      dfsnr[i] = (1.0f - exp(-x2 / 4.0f)) * exp(-x2 / w);
00757                         float x2 = 10.0f*i/np;
00758                         dfsnr[i] = x2 * exp(-x2);
00759                 }
00760 
00761 //              Util::save_data(0, 1.0f / Ctf::CTFOS, dfsnr, np, "filt.txt");
00762         }
00763 
00764         EMData *image_fft = image->do_fft();
00765         image_fft->ri2ap();
00766         EMData *with_fft = with->do_fft();
00767         with_fft->ri2ap();
00768 
00769         const float *const image_fft_data = image_fft->get_const_data();
00770         const float *const with_fft_data = with_fft->get_const_data();
00771         double sum = 0;
00772         double norm = FLT_MIN;
00773         size_t i = 0;
00774 
00775         for (int z = 0; z < image_fft->get_zsize(); ++z){
00776                 for (int y = 0; y < image_fft->get_ysize(); ++y) {
00777                         for (int x = 0; x < image_fft->get_xsize(); x += 2) {
00778                                 int r;
00779 //                              if ( nz == 1 ) {
00780                                         if (y<ny/2) r = Util::round(Util::hypot_fast(x / 2, y) * Ctf::CTFOS);
00781                                         else r = Util::round(Util::hypot_fast(x / 2, y-ny) * Ctf::CTFOS);
00782 
00783                                 float a = dfsnr[r] * with_fft_data[i];
00784 //                              cout << a << " " << Util::angle_sub_2pi(image_fft_data[i + 1], with_fft_data[i + 1]) << " " <<image_fft_data[i + 1] << " " << with_fft_data[i + 1] << endl;
00785                                 sum += Util::angle_sub_2pi(image_fft_data[i + 1], with_fft_data[i + 1]) * a;
00786                                 norm += a;
00787                                 i += 2;
00788                         }
00789                 }
00790         }
00791         EXITFUNC;
00792 
00793         if( image_fft )
00794         {
00795                 delete image_fft;
00796                 image_fft = 0;
00797         }
00798         if( with_fft )
00799         {
00800                 delete with_fft;
00801                 with_fft = 0;
00802         }
00803 #if 0
00804         return (1.0f - sum / norm);
00805 #endif
00806         return (float)(sum / norm);
00807 }

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

00415                 {
00416                         return "phase";
00417                 }

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

Implements EMAN::Cmp.

Definition at line 419 of file cmp.h.

00420                 {
00421                         return "Mean phase difference";
00422                 }

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

Definition at line 424 of file cmp.h.

00425                 {
00426                         return new PhaseCmp();
00427                 }

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

00430                 {
00431                         TypeDict d;
00432                         return d;
00433                 }


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

Generated on Sat Nov 21 02:20:17 2009 for EMAN2 by  doxygen 1.5.6