#include <cmp.h>


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 Cmp * | NEW () |
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 446 of file cmp.h.
To compare 'image' with another image passed in through its parameters.
An optional transformation may be used to transform the 2 images.
| image | The first image to be compared. | |
| with | The second image to be comppared. |
Implements EMAN::Cmp.
Definition at line 919 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(), EMAN::Cmp::params, EMAN::EMData::set_attr(), EMAN::Dict::set_default(), EMAN::EMData::update(), EMAN::Cmp::validate_input_args(), and weight.
00920 { 00921 ENTERFUNC; 00922 validate_input_args(image, with); 00923 00924 int snrweight = params.set_default("snrweight", 0); 00925 int ampweight = params.set_default("ampweight", 0); 00926 int sweight = params.set_default("sweight", 1); 00927 int nweight = params.set_default("nweight", 0); 00928 int zeromask = params.set_default("zeromask",0); 00929 00930 if (zeromask) { 00931 image=image->copy(); 00932 with=with->copy(); 00933 00934 int sz=image->get_xsize()*image->get_ysize()*image->get_zsize(); 00935 float *d1=image->get_data(); 00936 float *d2=with->get_data(); 00937 00938 for (int i=0; i<sz; i++) { 00939 if (d1[i]==0.0 || d2[i]==0.0) { d1[i]=0.0; d2[i]=0.0; } 00940 } 00941 00942 image->update(); 00943 with->update(); 00944 image->do_fft_inplace(); 00945 with->do_fft_inplace(); 00946 image->set_attr("free_me",1); 00947 with->set_attr("free_me",1); 00948 } 00949 00950 00951 if (!image->is_complex()) { 00952 image=image->do_fft(); 00953 image->set_attr("free_me",1); 00954 } 00955 if (!with->is_complex()) { 00956 with=with->do_fft(); 00957 with->set_attr("free_me",1); 00958 } 00959 00960 static vector < float >default_snr; 00961 00962 // if (image->get_zsize() > 1) { 00963 // throw ImageDimensionException("2D only"); 00964 // } 00965 00966 // int nx = image->get_xsize(); 00967 int ny = image->get_ysize(); 00968 int ny2=ny/2+1; 00969 00970 vector < float >fsc; 00971 00972 00973 00974 fsc = image->calc_fourier_shell_correlation(with,1); 00975 00976 // The fast hypot here was supposed to speed things up. Little effect 00977 // if (image->get_zsize()>1) fsc = image->calc_fourier_shell_correlation(with,1); 00978 // else { 00979 // double *sxy = (double *)malloc(ny2*sizeof(double)*4); 00980 // double *sxx = sxy+ny2; 00981 // double *syy = sxy+2*ny2; 00982 // double *norm= sxy+3*ny2; 00983 // 00984 // float *df1=image->get_data(); 00985 // float *df2=with->get_data(); 00986 // int nx2=image->get_xsize(); 00987 // 00988 // for (int y=-ny/2; y<ny/2; y++) { 00989 // for (int x=0; x<nx2/2; x++) { 00990 // if (x==0 && y<0) continue; // skip Friedel pair 00991 // short r=Util::hypot_fast_int(x,y); 00992 // if (r>ny2-1) continue; 00993 // int l=x*2+(y<0?ny+y:y)*nx2; 00994 // sxy[r]+=df1[l]*df2[l]+df1[l+1]*df2[l+1]; 00995 // sxx[r]+=df1[l]*df1[l]; 00996 // syy[r]+=df2[l]*df2[l]; 00997 // norm[r]+=1.0; 00998 // } 00999 // } 01000 // fsc.resize(ny2*3); 01001 // for (int r=0; r<ny2; r++) { 01002 // fsc[r]=r*0.5/ny2; 01003 // fsc[ny2+r]=sxy[r]/(sqrt(sxx[r])*sqrt(syy[r])); 01004 // fsc[ny2*2+r]=norm[r]; 01005 // } 01006 // free(sxy); 01007 // } 01008 01009 vector<float> snr; 01010 if (snrweight) { 01011 Ctf *ctf = NULL; 01012 if (!image->has_attr("ctf")) { 01013 if (!with->has_attr("ctf")) throw InvalidCallException("SNR weight with no CTF parameters"); 01014 ctf=with->get_attr("ctf"); 01015 } 01016 else ctf=image->get_attr("ctf"); 01017 01018 float ds=1.0f/(ctf->apix*ny); 01019 snr=ctf->compute_1d(ny,ds,Ctf::CTF_SNR); 01020 if(ctf) {delete ctf; ctf=0;} 01021 } 01022 01023 vector<float> amp; 01024 if (ampweight) amp=image->calc_radial_dist(ny/2,0,1,0); 01025 01026 double sum=0.0, norm=0.0; 01027 01028 for (int i=0; i<ny/2; i++) { 01029 double weight=1.0; 01030 if (sweight) weight*=fsc[(ny2)*2+i]; 01031 if (ampweight) weight*=amp[i]; 01032 if (snrweight) weight*=snr[i]; 01033 sum+=weight*fsc[ny2+i]; 01034 norm+=weight; 01035 // printf("%d\t%f\t%f\n",i,weight,fsc[ny/2+1+i]); 01036 } 01037 01038 // This performs a weighting that tries to normalize FRC by correcting from the number of particles represented by the average 01039 sum/=norm; 01040 if (nweight && with->get_attr_default("ptcl_repr",0) && sum>=0 && sum<1.0) { 01041 sum=sum/(1.0-sum); // convert to SNR 01042 sum/=(float)with->get_attr_default("ptcl_repr",0); // divide by ptcl represented 01043 sum=sum/(1.0+sum); // convert back to correlation 01044 } 01045 01046 if (image->has_attr("free_me")) delete image; 01047 if (with->has_attr("free_me")) delete with; 01048 01049 EXITFUNC; 01050 01051 01052 //.Note the negative! This is because EMAN2 follows the convention that 01053 // smaller return values from comparitors indicate higher similarity - 01054 // this enables comparitors to be used in a generic fashion. 01055 return (float)-sum; 01056 }
| string EMAN::FRCCmp::get_name | ( | ) | const [inline, virtual] |
| string EMAN::FRCCmp::get_desc | ( | ) | const [inline, virtual] |
| static Cmp* EMAN::FRCCmp::NEW | ( | ) | [inline, static] |
| 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.
Implements EMAN::Cmp.
Definition at line 466 of file cmp.h.
References EMAN::EMObject::INT, and EMAN::TypeDict::put().
00467 { 00468 TypeDict d; 00469 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)"); 00470 d.put("ampweight", EMObject::INT, "If set, the amplitude of 'this' will be used to weight the result (default=0)"); 00471 d.put("sweight", EMObject::INT, "If set, weight the (1-D) average by the number of pixels in each ring (default=1)"); 00472 d.put("nweight", EMObject::INT, "Downweight similarity based on number of particles in reference (default=0)"); 00473 d.put("zeromask", EMObject::INT, "Treat regions in either image that are zero as a mask"); 00474 return d; 00475 }
1.5.6