#include <cmp.h>
Inheritance diagram for EMAN::FRCCmp:
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 () |
Static Public Attributes | |
static const string | NAME = "frc" |
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 552 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 1245 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::Util::goodf(), EMAN::EMData::has_attr(), InvalidCallException, EMAN::EMData::is_complex(), norm(), ny, EMAN::Cmp::params, EMAN::EMData::set_attr(), EMAN::Dict::set_default(), EMAN::EMData::update(), EMAN::Cmp::validate_input_args(), and weight.
01246 { 01247 ENTERFUNC; 01248 validate_input_args(image, with); 01249 01250 int snrweight = params.set_default("snrweight", 0); 01251 int ampweight = params.set_default("ampweight", 0); 01252 int sweight = params.set_default("sweight", 1); 01253 int nweight = params.set_default("nweight", 0); 01254 int zeromask = params.set_default("zeromask",0); 01255 float minres = params.set_default("minres",500.0f); 01256 float maxres = params.set_default("maxres",2.0f); 01257 01258 vector < float >fsc; 01259 bool use_cpu = true; 01260 01261 if (use_cpu) { 01262 if (zeromask) { 01263 image=image->copy(); 01264 with=with->copy(); 01265 01266 int sz=image->get_xsize()*image->get_ysize()*image->get_zsize(); 01267 float *d1=image->get_data(); 01268 float *d2=with->get_data(); 01269 01270 for (int i=0; i<sz; i++) { 01271 if (d1[i]==0.0 || d2[i]==0.0) { d1[i]=0.0; d2[i]=0.0; } 01272 } 01273 01274 image->update(); 01275 with->update(); 01276 image->do_fft_inplace(); 01277 with->do_fft_inplace(); 01278 image->set_attr("free_me",1); 01279 with->set_attr("free_me",1); 01280 } 01281 01282 01283 if (!image->is_complex()) { 01284 image=image->do_fft(); 01285 image->set_attr("free_me",1); 01286 } 01287 if (!with->is_complex()) { 01288 with=with->do_fft(); 01289 with->set_attr("free_me",1); 01290 } 01291 01292 fsc = image->calc_fourier_shell_correlation(with,1); 01293 } 01294 01295 int ny = image->get_ysize(); 01296 int ny2=ny/2+1; 01297 01298 // The fast hypot here was supposed to speed things up. Little effect 01299 // if (image->get_zsize()>1) fsc = image->calc_fourier_shell_correlation(with,1); 01300 // else { 01301 // double *sxy = (double *)malloc(ny2*sizeof(double)*4); 01302 // double *sxx = sxy+ny2; 01303 // double *syy = sxy+2*ny2; 01304 // double *norm= sxy+3*ny2; 01305 // 01306 // float *df1=image->get_data(); 01307 // float *df2=with->get_data(); 01308 // int nx2=image->get_xsize(); 01309 // 01310 // for (int y=-ny/2; y<ny/2; y++) { 01311 // for (int x=0; x<nx2/2; x++) { 01312 // if (x==0 && y<0) continue; // skip Friedel pair 01313 // short r=Util::hypot_fast_int(x,y); 01314 // if (r>ny2-1) continue; 01315 // int l=x*2+(y<0?ny+y:y)*nx2; 01316 // sxy[r]+=df1[l]*df2[l]+df1[l+1]*df2[l+1]; 01317 // sxx[r]+=df1[l]*df1[l]; 01318 // syy[r]+=df2[l]*df2[l]; 01319 // norm[r]+=1.0; 01320 // } 01321 // } 01322 // fsc.resize(ny2*3); 01323 // for (int r=0; r<ny2; r++) { 01324 // fsc[r]=r*0.5/ny2; 01325 // fsc[ny2+r]=sxy[r]/(sqrt(sxx[r])*sqrt(syy[r])); 01326 // fsc[ny2*2+r]=norm[r]; 01327 // } 01328 // free(sxy); 01329 // } 01330 01331 vector<float> snr; 01332 if (snrweight) { 01333 Ctf *ctf = NULL; 01334 if (!image->has_attr("ctf")) { 01335 if (!with->has_attr("ctf")) throw InvalidCallException("SNR weight with no CTF parameters"); 01336 ctf=with->get_attr("ctf"); 01337 } 01338 else ctf=image->get_attr("ctf"); 01339 01340 float ds=1.0f/(ctf->apix*ny); 01341 snr=ctf->compute_1d(ny,ds,Ctf::CTF_SNR); 01342 if(ctf) {delete ctf; ctf=0;} 01343 } 01344 01345 vector<float> amp; 01346 if (ampweight) amp=image->calc_radial_dist(ny/2,0,1,0); 01347 01348 // Min/max modifications to weighting 01349 float pmin,pmax; 01350 if (minres>0) pmin=((float)image->get_attr("apix_x")*image->get_ysize())/minres; //cutoff in pixels, assume square 01351 else pmin=0; 01352 if (maxres>0) pmax=((float)image->get_attr("apix_x")*image->get_ysize())/maxres; 01353 else pmax=0; 01354 01355 double sum=0.0, norm=0.0; 01356 01357 for (int i=0; i<ny/2; i++) { 01358 double weight=1.0; 01359 if (sweight) weight*=fsc[(ny2)*2+i]; 01360 if (ampweight) weight*=amp[i]; 01361 if (snrweight) weight*=snr[i]; 01362 // if (snrweight) { 01363 // if (snr[i]>0) weight*=sqrt(snr[i]); 01364 // else weight=0; 01365 // } 01366 //if(snr[i]<0) printf("snr[%d] = %1.5g\n",i,snr[i]); 01367 if (pmin>0) weight*=(tanh(5.0*(i-pmin)/pmin)+1.0)/2.0; 01368 if (pmax>0) weight*=(1.0-tanh(i-pmax))/2.0; 01369 01370 sum+=weight*fsc[ny2+i]; 01371 norm+=weight; 01372 // printf("%d\t%f\t%f\n",i,weight,fsc[ny/2+1+i]); 01373 } 01374 01375 // This performs a weighting that tries to normalize FRC by correcting from the number of particles represented by the average 01376 sum/=norm; 01377 if (nweight && with->get_attr_default("ptcl_repr",0) && sum>=0 && sum<1.0) { 01378 sum=sum/(1.0-sum); // convert to SNR 01379 sum/=(float)with->get_attr_default("ptcl_repr",0); // divide by ptcl represented 01380 sum=sum/(1.0+sum); // convert back to correlation 01381 } 01382 01383 if (image->has_attr("free_me")) delete image; 01384 if (with->has_attr("free_me")) delete with; 01385 01386 EXITFUNC; 01387 01388 if (!Util::goodf(&sum)) sum=-3.0e38; 01389 01390 //.Note the negative! This is because EMAN2 follows the convention that 01391 // smaller return values from comparitors indicate higher similarity - 01392 // this enables comparitors to be used in a generic fashion. 01393 return (float)-sum; 01394 }
string EMAN::FRCCmp::get_desc | ( | ) | const [inline, virtual] |
string EMAN::FRCCmp::get_name | ( | ) | const [inline, virtual] |
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 572 of file cmp.h.
References EMAN::EMObject::FLOAT, EMAN::EMObject::INT, and EMAN::TypeDict::put().
00573 { 00574 TypeDict d; 00575 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)"); 00576 d.put("ampweight", EMObject::INT, "If set, the amplitude of 'this' will be used to weight the result (default=0)"); 00577 d.put("sweight", EMObject::INT, "If set, weight the (1-D) average by the number of pixels in each ring (default=1)"); 00578 d.put("nweight", EMObject::INT, "Downweight similarity based on number of particles in reference (default=0)"); 00579 d.put("zeromask", EMObject::INT, "Treat regions in either image that are zero as a mask"); 00580 d.put("minres", EMObject::FLOAT, "Lowest resolution to use in comparison (soft cutoff). Requires accurate A/pix in image. <0 disables. Default=500"); 00581 d.put("maxres", EMObject::FLOAT, "Highest resolution to use in comparison (soft cutoff). Requires accurate A/pix in image. <0 disables. Default=10"); 00582 return d; 00583 }
static Cmp* EMAN::FRCCmp::NEW | ( | ) | [inline, static] |
const string FRCCmp::NAME = "frc" [static] |