Classes | |
class | EMAN::TranslationalAligner |
Translational 2D Alignment using cross correlation. More... | |
class | EMAN::RotationalAligner |
rotational alignment using angular correlation More... | |
class | EMAN::RotateTranslateAligner |
rotational, translational alignment More... | |
class | EMAN::RotateFlipAligner |
rotational and flip alignment More... | |
class | EMAN::RotateTranslateFlipAligner |
rotational, translational and flip alignment More... | |
class | EMAN::Rotate180Processor |
Rotate by 180 using pixel swapping, works for 2D only. More... | |
class | EMAN::TransformProcessor |
Transform the image using a Transform object. More... | |
class | EMAN::IntTranslateProcessor |
Translate the image an integer amount Uses EMData::clip_inplace (inplace) and EMData::get_clip (out of place) to do the translation. More... | |
class | EMAN::BinarizeFourierProcessor |
A thresholding processor for Fourier images based on the amplitude component. More... | |
Functions | |
EMData * | EMAN::EMData::do_fft () const |
return the fast fourier transform (FFT) image of the current image. | |
EMData * | EMAN::EMData::do_ift () |
return the inverse fourier transform (IFT) image of the current image. | |
void | EMAN::EMData::ri2ap () |
convert the complex image from real/imaginary to amplitude/phase | |
void | EMAN::EMData::ap2ri () |
convert the complex image from amplitude/phase to real/imaginary | |
void | EMAN::EMData::ri2inten () |
convert the complex image from real/imaginary to Intensity/0. | |
void | EMAN::EMData::insert_clip (const EMData *const block, const IntPoint &origin) |
Insert a clip into this image. | |
EMAN::EMData::EMData (const EMData &that) | |
Construct from an EMData (copy constructor). | |
EMData & | EMAN::EMData::operator= (const EMData &that) |
EMData assignment operator Performs a deep copy. | |
EMData * | EMAN::EMData::get_clip (const Region &area, const float fill=0) const |
Get an inclusive clip. | |
EMData * | EMAN::EMData::calc_ccf (EMData *with, fp_flag fpflag=CIRCULANT, bool center=false) |
Calculate Cross-Correlation Function (CCF). | |
EMData * | EMAN::EMData::calc_ccfx (EMData *const with, int y0=0, int y1=-1, bool nosum=false) |
Calculate Cross-Correlation Function (CCF) in the x-direction and adds them up, result in 1D. | |
EMData * | EMAN::EMData::make_rotational_footprint (bool unwrap=true) |
Makes a 'rotational footprint', which is an 'unwound' autocorrelation function. | |
EMData * | EMAN::EMData::unwrap (int r1=-1, int r2=-1, int xs=-1, int dx=0, int dy=0, bool do360=false, bool weight_radial=true) const |
Maps to polar coordinates from Cartesian coordinates. | |
EMData * | do_fft () const |
return the fast fourier transform (FFT) image of the current image. | |
EMData * | do_ift () |
return the inverse fourier transform (IFT) image of the current image. | |
void | ri2ap () |
convert the complex image from real/imaginary to amplitude/phase | |
void | ap2ri () |
convert the complex image from amplitude/phase to real/imaginary | |
void | ri2inten () |
convert the complex image from real/imaginary to Intensity/0. | |
void | insert_clip (const EMData *const block, const IntPoint &origin) |
Insert a clip into this image. |
|
convert the complex image from amplitude/phase to real/imaginary
Referenced by EMAN::EMData::ap2ri(). |
|
|
Calculate Cross-Correlation Function (CCF). Calculate the correlation of two 1-, 2-, or 3-dimensional images. Note: this method internally just calls the correlation function from fundamentals.h.
Definition at line 1424 of file emdata.cpp. References EMAN::EMData::clip_inplace(), EMAN::convolution(), EMAN::correlation(), ENTERFUNC, EXITFUNC, EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::EMData::nx, EMAN::EMData::ny, and EMAN::EMData::nz. Referenced by EMAN::TranslationalAligner::align(), EMAN::EMData::calc_flcf(), EMAN::TomoDotCmp::cmp(), EMAN::EMData::make_rotational_footprint(), EMAN::RT3DSphereAligner::xform_align_nbest(), and EMAN::RT3DGridAligner::xform_align_nbest(). 01425 { 01426 ENTERFUNC; 01427 if( with == 0 ) { 01428 EXITFUNC; 01429 return convolution(this,this,fpflag, center); 01430 } 01431 else if ( with == this ){ // this if statement is not necessary, the correlation function tests to see if with == this 01432 EXITFUNC; 01433 return correlation(this, this, fpflag,center); 01434 } 01435 else { 01436 01437 #ifdef EMAN2_USING_CUDA 01438 if (gpu_operation_preferred()) { 01439 EXITFUNC; 01440 return calc_ccf_cuda(with,false,center); 01441 } 01442 #endif 01443 01444 // If the argument EMData pointer is not the same size we automatically resize it 01445 bool undoresize = false; 01446 int wnx = with->get_xsize(); int wny = with->get_ysize(); int wnz = with->get_zsize(); 01447 if ( wnx != nx || wny != ny || wnz != nz ) { 01448 Region r((wnx-nx)/2, (wny-ny)/2, (wnz-nz)/2,nx,ny,nz); 01449 with->clip_inplace(r); 01450 undoresize = true; 01451 } 01452 01453 EMData* cor = correlation(this, with, fpflag, center); 01454 01455 // If the argument EMData pointer was resized, it is returned to its original dimensions 01456 if ( undoresize ) { 01457 Region r((nx-wnx)/2, (ny-wny)/2,(nz-wnz)/2,wnx,wny,wnz); 01458 with->clip_inplace(r); 01459 } 01460 01461 EXITFUNC; 01462 return cor; 01463 } 01464 }
|
|
Calculate Cross-Correlation Function (CCF) in the x-direction and adds them up, result in 1D. WARNING: this routine will modify the 'this' and 'with' to contain 1D fft's without setting some flags. This is an optimization for rotational alignment.
Definition at line 1466 of file emdata.cpp. References EMAN::EMData::EMData(), ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), EMAN::EMData::get_ndim(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, ImageFormatException, EMAN::EMData::is_complex_x(), EMAN::EMUtil::is_same_size(), LOGERR, NullPointerException, EMAN::EMData::nx, EMAN::EMData::ny, EMAN::EMData::nz, EMAN::EMData::set_size(), EMAN::EMData::to_zero(), and EMAN::EMData::update(). Referenced by EMAN::RTFExhaustiveAligner::align(), EMAN::RotatePrecenterAligner::align(), EMAN::RotationalAligner::align_180_ambiguous(), and EMAN::EMData::make_footprint(). 01467 { 01468 ENTERFUNC; 01469 01470 #ifdef EMAN2_USING_CUDA 01471 if (gpu_operation_preferred() ) { 01472 EXITFUNC; 01473 return calc_ccfx_cuda(with,y0,y1,no_sum); 01474 } 01475 #endif 01476 01477 if (!with) { 01478 LOGERR("NULL 'with' image. "); 01479 throw NullPointerException("NULL input image"); 01480 } 01481 01482 if (!EMUtil::is_same_size(this, with)) { 01483 LOGERR("images not same size: (%d,%d,%d) != (%d,%d,%d)", 01484 nx, ny, nz, 01485 with->get_xsize(), with->get_ysize(), with->get_zsize()); 01486 throw ImageFormatException("images not same size"); 01487 } 01488 if (get_ndim() > 2) { 01489 LOGERR("2D images only"); 01490 throw ImageDimensionException("2D images only"); 01491 } 01492 01493 if (y1 <= y0) { 01494 y1 = ny; 01495 } 01496 01497 if (y0 >= y1) { 01498 y0 = 0; 01499 } 01500 01501 if (y0 < 0) { 01502 y0 = 0; 01503 } 01504 01505 if (y1 > ny) { 01506 y1 = ny; 01507 } 01508 if (is_complex_x() || with->is_complex_x() ) throw; // Woops don't support this anymore! 01509 01510 static int nx_fft = 0; 01511 static int ny_fft = 0; 01512 static EMData f1; 01513 static EMData f2; 01514 static EMData rslt; 01515 01516 int height = y1-y0; 01517 int width = (nx+2-(nx%2)); 01518 if (width != nx_fft || height != ny_fft ) { 01519 f1.set_size(width,height); 01520 f2.set_size(width,height); 01521 rslt.set_size(nx,height); 01522 nx_fft = width; 01523 ny_fft = height; 01524 } 01525 01526 float *d1 = get_data(); 01527 float *d2 = with->get_data(); 01528 float *f1d = f1.get_data(); 01529 float *f2d = f2.get_data(); 01530 for (int j = 0; j < height; j++) { 01531 EMfft::real_to_complex_1d(d1 + j * nx, f1d+j*width, nx); 01532 EMfft::real_to_complex_1d(d2 + j * nx, f2d+j*width, nx); 01533 } 01534 01535 for (int j = 0; j < height; j++) { 01536 float *f1a = f1d + j * width; 01537 float *f2a = f2d + j * width; 01538 01539 for (int i = 0; i < width / 2; i++) { 01540 float re1 = f1a[2*i]; 01541 float re2 = f2a[2*i]; 01542 float im1 = f1a[2*i+1]; 01543 float im2 = f2a[2*i+1]; 01544 01545 f1d[j*width+i*2] = re1 * re2 + im1 * im2; 01546 f1d[j*width+i*2+1] = im1 * re2 - re1 * im2; 01547 } 01548 } 01549 01550 float* rd = rslt.get_data(); 01551 for (int j = y0; j < y1; j++) { 01552 EMfft::complex_to_real_1d(f1d+j*width, rd+j*nx, nx); 01553 } 01554 01555 if (no_sum) { 01556 rslt.update(); // This is important in terms of the copy - the returned object won't have the correct flags unless we do this 01557 EXITFUNC; 01558 return new EMData(rslt); 01559 } else { 01560 EMData *cf = new EMData(nx,1,1); 01561 cf->to_zero(); 01562 float *c = cf->get_data(); 01563 for (int j = 0; j < height; j++) { 01564 for(int i = 0; i < nx; ++i) { 01565 c[i] += rd[i+j*nx]; 01566 } 01567 } 01568 cf->update(); 01569 EXITFUNC; 01570 return cf; 01571 } 01572 }
|
|
return the fast fourier transform (FFT) image of the current image. the current image is not changed. The result is in real/imaginary format.
|
|
|
return the inverse fourier transform (IFT) image of the current image. the current image may be changed if it is in amplitude/phase format as opposed to real/imaginary format - if this change is performed it is not undone.
|
|
return the inverse fourier transform (IFT) image of the current image. the current image may be changed if it is in amplitude/phase format as opposed to real/imaginary format - if this change is performed it is not undone.
Definition at line 240 of file emdata_transform.cpp. References EMAN::EMData::ap2ri(), EMAN::EMData::copy_head(), ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), EMAN::EMData::get_ndim(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageFormatException, EMAN::EMData::is_complex(), EMAN::EMData::is_fftodd(), EMAN::EMData::is_ri(), LOGERR, LOGWARN, EMAN::EMData::mult(), EMAN::EMData::nx, EMAN::EMData::ny, EMAN::EMData::nz, EMAN::EMData::rdata, EMAN::EMData::set_complex(), EMAN::EMData::set_complex_x(), EMAN::EMData::set_fftodd(), EMAN::EMData::set_fftpad(), EMAN::EMData::set_ri(), EMAN::EMData::set_size(), and EMAN::EMData::update(). Referenced by EMAN::EMData::calc_mutual_correlation(), EMAN::OptVarianceCmp::cmp(), EMAN::EMData::convolute(), EMAN::EMData::FH2Real(), EMAN::CtfAverager::finish(), EMAN::CtfCAutoAverager::finish(), EMAN::CtfCWautoAverager::finish(), main(), EMAN::EMData::make_footprint(), EMAN::PointArray::pdb2mrc_by_nfft(), EMAN::Wiener2DFourierProcessor::process(), EMAN::FileFourierProcessor::process_inplace(), EMAN::SNRProcessor::process_inplace(), EMAN::AmpweightFourierProcessor::process_inplace(), EMAN::FourierAnlProcessor::process_inplace(), EMAN::FourierProcessor::process_inplace(), EMAN::ImageProcessor::process_inplace(), and EMAN::GaussFFTProjector::project3d(). 00241 { 00242 ENTERFUNC; 00243 00244 #ifdef EMAN2_USING_CUDA 00245 if (gpu_operation_preferred()) { 00246 EXITFUNC; 00247 return do_ift_cuda(); 00248 } 00249 #endif 00250 00251 if (!is_complex()) { 00252 LOGERR("complex image expected. Input image is real image."); 00253 throw ImageFormatException("complex image expected. Input image is real image."); 00254 } 00255 00256 if (!is_ri()) { 00257 LOGWARN("run IFT on AP data, only RI should be used. Converting."); 00258 } 00259 00260 get_data(); // Required call if GPU caching is being used. Otherwise harmless 00261 EMData* dat = copy_head(); 00262 dat->set_size(nx, ny, nz); 00263 ap2ri(); 00264 00265 float *d = dat->get_data(); 00266 int ndim = get_ndim(); 00267 00268 /* Do inplace IFT on a image copy, because the complex to real transform of 00269 * nd will destroy its input array even for out-of-place transforms. 00270 */ 00271 memcpy((char *) d, (char *) rdata, nx * ny * nz * sizeof(float)); 00272 00273 int offset = is_fftodd() ? 1 : 2; 00274 //cout << "Sending offset " << offset << " " << nx-offset << endl; 00275 if (ndim == 1) { 00276 EMfft::complex_to_real_nd(d, d, nx - offset, ny, nz); 00277 } else { 00278 EMfft::complex_to_real_nd(d, d, nx - offset, ny, nz); 00279 00280 #ifndef CUDA_FFT 00281 size_t row_size = (nx - offset) * sizeof(float); 00282 for (int i = 1; i < ny * nz; i++) { 00283 memmove((char *) &d[i * (nx - offset)], (char *) &d[i * nx], row_size); 00284 } 00285 #endif 00286 } 00287 00288 dat->set_size(nx - offset, ny, nz); //remove the padding 00289 #if defined FFTW2 || defined FFTW3 || defined CUDA_FFT //native fft and ACML already done normalization 00290 // SCALE the inverse FFT 00291 float scale = 1.0f / ((nx - offset) * ny * nz); 00292 dat->mult(scale); 00293 #endif //FFTW2 || FFTW3 00294 dat->set_fftodd(false); 00295 dat->set_fftpad(false); 00296 dat->set_complex(false); 00297 if(dat->get_ysize()==1 && dat->get_zsize()==1) dat->set_complex_x(false); 00298 dat->set_ri(false); 00299 dat->update(); 00300 00301 00302 EXITFUNC; 00303 return dat; 00304 }
|
|
Construct from an EMData (copy constructor). Performs a deep copy
Definition at line 124 of file emdata.cpp. References data, EMAN::EMUtil::em_malloc(), EMAN::EMUtil::em_memcpy(), EMAN::EMData::EMData(), EMAN::EMData::EMDATA_GPU_RO_NEEDS_UPDATE, ENTERFUNC, EMAN::EMData::flags, EMAN::EMData::nx, EMAN::EMData::ny, EMAN::EMData::nz, EMAN::EMData::rdata, EMAN::EMData::rot_fp, EMAN::EMData::totalalloc, and UnexpectedBehaviorException. 00124 : 00125 #ifdef EMAN2_USING_CUDA 00126 cuda_cache_handle(-1), 00127 #endif //EMAN2_USING_CUDA 00128 attr_dict(that.attr_dict), rdata(0), supp(0), flags(that.flags), changecount(that.changecount), nx(that.nx), ny(that.ny), nz(that.nz), 00129 nxy(that.nx*that.ny), nxyz(that.nx*that.ny*that.nz), xoff(that.xoff), yoff(that.yoff), zoff(that.zoff),all_translation(that.all_translation), path(that.path), 00130 pathnum(that.pathnum), rot_fp(0) 00131 { 00132 ENTERFUNC; 00133 00134 float* data = that.rdata; 00135 size_t num_bytes = nx*ny*nz*sizeof(float); 00136 if (data && num_bytes != 0) 00137 { 00138 rdata = (float*)EMUtil::em_malloc(num_bytes); 00139 EMUtil::em_memcpy(rdata, data, num_bytes); 00140 } 00141 #ifdef EMAN2_USING_CUDA 00142 if (num_bytes != 0 && that.cuda_cache_handle != -1 && that.gpu_rw_is_current()) { 00143 float * cuda_data = that.get_cuda_data(); 00144 CudaDataLock lock2(&that); 00145 set_size_cuda(nx,ny,nz); 00146 float *cd = get_cuda_data(); 00147 CudaDataLock lock1(this); 00148 cudaError_t error = cudaMemcpy(cd,cuda_data,num_bytes,cudaMemcpyDeviceToDevice); 00149 if ( error != cudaSuccess ) throw UnexpectedBehaviorException("cudaMemcpy failed in EMData copy construction with error: " + string(cudaGetErrorString(error))); 00150 } 00151 // This is a bit of hack 00152 flags |= EMDATA_GPU_RO_NEEDS_UPDATE; 00153 #endif //EMAN2_USING_CUDA 00154 if (that.rot_fp != 0) rot_fp = new EMData(*(that.rot_fp)); 00155 00156 EMData::totalalloc++; 00157 00158 ENTERFUNC; 00159 }
|
|
Get an inclusive clip. Pads to fill if larger than this image.
Definition at line 544 of file emdata.cpp. References EMAN::EMData::attr_dict, EMAN::EMData::EMData(), ENTERFUNC, EXITFUNC, EMAN::Region::get_ndim(), EMAN::EMData::get_ndim(), EMAN::Dict::has_key(), ImageDimensionException, EMAN::EMData::insert_clip(), LOGERR, EMAN::EMData::nx, EMAN::EMData::ny, EMAN::EMData::nz, EMAN::Region::origin, EMAN::EMData::path, EMAN::EMData::pathnum, EMAN::EMData::set_path(), EMAN::EMData::set_pathnum(), EMAN::EMData::set_size(), EMAN::EMData::set_xyz_origin(), EMAN::Region::size, EMAN::EMData::to_value(), and EMAN::EMData::update(). Referenced by EMAN::EMData::calc_fast_sigma_image(), EMAN::EMData::make_footprint(), EMAN::ScaleTransformProcessor::process(), EMAN::IntTranslateProcessor::process(), EMAN::SNRProcessor::process_inplace(), EMAN::CutoffBlockProcessor::process_inplace(), and EMAN::EMData::window_center(). 00545 { 00546 ENTERFUNC; 00547 if (get_ndim() != area.get_ndim()) { 00548 LOGERR("cannot get %dD clip out of %dD image", area.get_ndim(),get_ndim()); 00549 return 0; 00550 } 00551 00552 EMData *result = new EMData(); 00553 00554 // Ensure that all of the metadata of this is stored in the new object 00555 // Originally added to ensure that euler angles were retained when preprocessing (zero padding) images 00556 // prior to insertion into the 3D for volume in the reconstruction phase (see reconstructor.cpp/h). 00557 result->attr_dict = this->attr_dict; 00558 int zsize = (int)area.size[2]; 00559 if (zsize == 0 && nz <= 1) { 00560 zsize = 1; 00561 } 00562 int ysize = (ny<=1 && (int)area.size[1]==0 ? 1 : (int)area.size[1]); 00563 00564 if ( (int)area.size[0] < 0 || ysize < 0 || zsize < 0 ) 00565 { 00566 // Negative image dimensions not supported - added retrospectively by d.woolford (who didn't write get_clip but wrote clip_inplace) 00567 throw ImageDimensionException("New image dimensions are negative - this is not supported in the the get_clip operation"); 00568 } 00569 00570 #ifdef EMAN2_USING_CUDA 00571 // Strategy is always to prefer using the GPU if possible 00572 bool use_gpu = false; 00573 if ( gpu_operation_preferred() ) { 00574 result->set_size_cuda((int)area.size[0], ysize, zsize); 00575 //CudaDataLock lock(this); // Just so we never have to recopy this data to and from the GPU 00576 result->get_cuda_data(); // Force the allocation - set_size_cuda is lazy 00577 // Setting the value is necessary seeing as cuda data is not automatically zeroed 00578 result->to_value(fill); // This will automatically use the GPU. 00579 use_gpu = true; 00580 } else { // cpu == True 00581 result->set_size((int)area.size[0], ysize, zsize); 00582 if (fill != 0.0) { result->to_value(fill); }; 00583 } 00584 #else 00585 result->set_size((int)area.size[0], ysize, zsize); 00586 if (fill != 0.0) { result->to_value(fill); }; 00587 #endif //EMAN2_USING_CUDA 00588 00589 int x0 = (int) area.origin[0]; 00590 x0 = x0 < 0 ? 0 : x0; 00591 00592 int y0 = (int) area.origin[1]; 00593 y0 = y0 < 0 ? 0 : y0; 00594 00595 int z0 = (int) area.origin[2]; 00596 z0 = z0 < 0 ? 0 : z0; 00597 00598 int x1 = (int) (area.origin[0] + area.size[0]); 00599 x1 = x1 > nx ? nx : x1; 00600 00601 int y1 = (int) (area.origin[1] + area.size[1]); 00602 y1 = y1 > ny ? ny : y1; 00603 00604 int z1 = (int) (area.origin[2] + area.size[2]); 00605 z1 = z1 > nz ? nz : z1; 00606 if (z1 <= 0) { 00607 z1 = 1; 00608 } 00609 00610 result->insert_clip(this,-((IntPoint)area.origin)); 00611 00612 if( attr_dict.has_key("apix_x") && attr_dict.has_key("apix_y") && 00613 attr_dict.has_key("apix_z") ) 00614 { 00615 if( attr_dict.has_key("origin_x") && attr_dict.has_key("origin_y") && 00616 attr_dict.has_key("origin_z") ) 00617 { 00618 float xorigin = attr_dict["origin_x"]; 00619 float yorigin = attr_dict["origin_y"]; 00620 float zorigin = attr_dict["origin_z"]; 00621 00622 float apix_x = attr_dict["apix_x"]; 00623 float apix_y = attr_dict["apix_y"]; 00624 float apix_z = attr_dict["apix_z"]; 00625 00626 result->set_xyz_origin(xorigin + apix_x * area.origin[0], 00627 yorigin + apix_y * area.origin[1], 00628 zorigin + apix_z * area.origin[2]); 00629 } 00630 } 00631 00632 #ifdef EMAN2_USING_CUDA 00633 if (use_gpu) result->gpu_update(); 00634 else result->update(); 00635 #else 00636 result->update(); 00637 #endif // EMAN2_USING_CUDA 00638 00639 00640 result->set_path(path); 00641 result->set_pathnum(pathnum); 00642 00643 EXITFUNC; 00644 return result; 00645 }
|
|
Insert a clip into this image. Very robust clip insertion code works in all way you might think possible
|
|
Insert a clip into this image. Very robust clip insertion code works in all way you might think possible
Definition at line 1702 of file emdata_transform.cpp. References EMAN::EMUtil::em_memcpy(), EXITFUNC, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::EMData::nx, EMAN::EMData::ny, EMAN::EMData::nz, EMAN::Region::origin, EMAN::Region::size, UnexpectedBehaviorException, and EMAN::EMData::update(). Referenced by EMAN::EMData::get_clip(), and EMAN::EMData::make_rotational_footprint_e1(). 01702 { 01703 int nx1 = block->get_xsize(); 01704 int ny1 = block->get_ysize(); 01705 int nz1 = block->get_zsize(); 01706 01707 Region area(origin[0], origin[1], origin[2],nx1, ny1, nz1); 01708 01709 int x0 = (int) area.origin[0]; 01710 x0 = x0 < 0 ? 0 : x0; 01711 01712 int y0 = (int) area.origin[1]; 01713 y0 = y0 < 0 ? 0 : y0; 01714 01715 int z0 = (int) area.origin[2]; 01716 z0 = z0 < 0 ? 0 : z0; 01717 01718 int x1 = (int) (area.origin[0] + area.size[0]); 01719 x1 = x1 > nx ? nx : x1; 01720 01721 int y1 = (int) (area.origin[1] + area.size[1]); 01722 y1 = y1 > ny ? ny : y1; 01723 01724 int z1 = (int) (area.origin[2] + area.size[2]); 01725 z1 = z1 > nz ? nz : z1; 01726 if (z1 <= 0) { 01727 z1 = 1; 01728 } 01729 01730 int xd0 = (int) (area.origin[0] < 0 ? -area.origin[0] : 0); 01731 int yd0 = (int) (area.origin[1] < 0 ? -area.origin[1] : 0); 01732 int zd0 = (int) (area.origin[2] < 0 ? -area.origin[2] : 0); 01733 01734 if (x1 < x0 || y1 < y0 || z1 < z0) return; // out of bounds, this is fine, nothing happens 01735 01736 size_t clipped_row_size = (x1-x0) * sizeof(float); 01737 int src_secsize = nx1 * ny1; 01738 int dst_secsize = nx * ny; 01739 01740 #ifdef EMAN2_USING_CUDA 01741 if (gpu_operation_preferred()) { 01742 // cudaMemcpy3DParms copyParams = {0}; 01743 // copyParams.srcPtr = make_cudaPitchedPtr((void*)get_cuda_data(), nx*sizeof(float), nx, ny); 01744 // cout << "Src pos is " << x0 << " " << y0 << " " << z0 << endl; 01745 // copyParams.srcPos = make_cudaPos(x0,y0,z0); 01746 // cout << "Extent is " << x1-x0 << " " << y1-y0 << " " << z1-z0 << endl; 01747 // cudaExtent extent = make_cudaExtent(x1-x0,y1-y0,z1-z0); 01748 // int rnx = result->get_xsize(); 01749 // int rny = result->get_ysize(); 01750 // copyParams.dstPtr = make_cudaPitchedPtr((void*)result->get_cuda_data(),rnx*sizeof(float),rnx,rny ); 01751 // cout << "Dest pos is " << xd0 << " " << yd0 << " " << zd0 << endl; 01752 // copyParams.dstPos = make_cudaPos(xd0,yd0,zd0); 01753 // copyParams.extent = extent; 01754 // copyParams.kind = cudaMemcpyDeviceToDevice; 01755 // cudaError_t error = cudaMemcpy3D(©Params); 01756 // if ( error != cudaSuccess) { 01757 // string e = cudaGetErrorString(error); 01758 // throw UnexpectedBehaviorException("CudaMemcpy3D failed with error: " + e); 01759 // } 01760 get_cuda_data(); 01761 CudaDataLock lock(this); 01762 block->get_cuda_data(); 01763 CudaDataLock lock2(block); 01764 for (int i = 0; i < (z1-z0); i++) { 01765 float* ldst = get_cuda_data() + (z0+i) * dst_secsize + y0 * nx + x0; 01766 float* lsrc = block->get_cuda_data() + (zd0+i) * src_secsize + yd0 * nx1 + xd0; 01767 01768 01769 // float* ldst = result->get_cuda_data() + (zd0+i) * dst_secsize + yd0 * (int)area.size[0] + xd0; 01770 // float* lsrc = get_cuda_data() + (z0+i) * src_secsize + y0 * nx + x0; 01771 cudaError_t error = cudaMemcpy2D( ldst, (nx)*sizeof(float), lsrc,nx1*sizeof(float), clipped_row_size, (y1-y0), cudaMemcpyDeviceToDevice ); 01772 if ( error != cudaSuccess) { 01773 string e = cudaGetErrorString(error); 01774 throw UnexpectedBehaviorException("cudaMemcpy2D failed in get_clip with error: " + e); 01775 } 01776 } 01777 gpu_update(); 01778 EXITFUNC; 01779 return; 01780 } 01781 #endif 01782 float *src = block->get_data() + zd0 * src_secsize + yd0 * nx1 + xd0; 01783 float *dst = get_data() + z0 * dst_secsize + y0 * nx + x0; 01784 01785 // float *src = get_data() + z0 * src_secsize + y0 * nx + x0; 01786 // float *dst = result->get_data(); 01787 // dst += zd0 * dst_secsize + yd0 * (int)area.size[0] + xd0; 01788 01789 int src_gap = src_secsize - (y1-y0) * nx1; 01790 int dst_gap = dst_secsize - (y1-y0) * nx; 01791 for (int i = z0; i < z1; i++) { 01792 for (int j = y0; j < y1; j++) { 01793 EMUtil::em_memcpy(dst, src, clipped_row_size); 01794 src += nx1; 01795 dst += nx; 01796 } 01797 src += src_gap; 01798 dst += dst_gap; 01799 } 01800 01801 update(); 01802 EXITFUNC; 01803 }
|
|
Makes a 'rotational footprint', which is an 'unwound' autocorrelation function. generally the image should be edge-normalized and masked before using this.
Definition at line 1626 of file emdata.cpp. References EMAN::EMData::calc_ccf(), EMAN::CIRCULANT, EMAN::EMData::EMData(), ENTERFUNC, EXITFUNC, EMAN::EMData::get_edge_mean(), EMAN::EMData::rot_fp, EMAN::EMData::sub(), EMAN::EMData::unwrap(), and EMAN::EMData::update_stat(). Referenced by EMAN::RotationalAligner::align_180_ambiguous(). 01626 { 01627 ENTERFUNC; 01628 update_stat(); 01629 // Note that rotational_footprint caching saves a large amount of time 01630 // but this is at the expense of memory. Note that a policy is hardcoded here, 01631 // that is that caching is only employed when premasked is false and unwrap 01632 // is true - this is probably going to be what is used in most scenarios 01633 // as advised by Steve Ludtke - In terms of performance this caching doubles the metric 01634 // generated by e2speedtest. 01635 if ( rot_fp != 0 && unwrap == true) { 01636 return new EMData(*rot_fp); 01637 } 01638 01639 EMData* ccf = this->calc_ccf(this,CIRCULANT,true); 01640 ccf->sub(ccf->get_edge_mean()); 01641 //ccf->process_inplace("xform.phaseorigin.tocenter"); ccf did the centering 01642 EMData *result = ccf->unwrap(); 01643 delete ccf; ccf = 0; 01644 01645 EXITFUNC; 01646 if ( unwrap == true) 01647 { // this if statement reflects a strict policy of caching in only one scenario see comments at beginning of function block 01648 01649 // Note that the if statement at the beginning of this function ensures that rot_fp is not zero, so there is no need 01650 // to throw any exception 01651 // if ( rot_fp != 0 ) throw UnexpectedBehaviorException("The rotational foot print is only expected to be cached if it is not NULL"); 01652 01653 // Here is where the caching occurs - the rot_fp takes ownsherhip of the pointer, and a deep copied EMData object is returned. 01654 // The deep copy invokes a cost in terms of CPU cycles and memory, but prevents the need for complicated memory management (reference counting) 01655 rot_fp = result; 01656 return new EMData(*rot_fp); 01657 } 01658 else return result; 01659 }
|
|
EMData assignment operator Performs a deep copy.
Definition at line 161 of file emdata.cpp. References EMAN::EMData::all_translation, EMAN::EMData::attr_dict, EMAN::EMData::changecount, data, EMAN::EMUtil::em_memcpy(), EMAN::EMData::EMData(), EMAN::EMData::EMDATA_GPU_RO_NEEDS_UPDATE, ENTERFUNC, EXITFUNC, EMAN::EMData::flags, EMAN::EMData::free_memory(), EMAN::EMData::nx, EMAN::EMData::ny, EMAN::EMData::nz, EMAN::EMData::path, EMAN::EMData::pathnum, EMAN::EMData::rdata, EMAN::EMData::rot_fp, EMAN::EMData::set_size(), UnexpectedBehaviorException, EMAN::EMData::xoff, EMAN::EMData::yoff, and EMAN::EMData::zoff. 00162 { 00163 ENTERFUNC; 00164 00165 if ( this != &that ) 00166 { 00167 free_memory(); // Free memory sets nx,ny and nz to 0 00168 00169 // Only copy the rdata if it exists, we could be in a scenario where only the header has been read 00170 float* data = that.rdata; 00171 size_t num_bytes = that.nx*that.ny*that.nz*sizeof(float); 00172 if (data && num_bytes != 0) 00173 { 00174 nx = 1; // This prevents a memset in set_size 00175 set_size(that.nx,that.ny,that.nz); 00176 EMUtil::em_memcpy(rdata, data, num_bytes); 00177 } 00178 00179 flags = that.flags; 00180 00181 all_translation = that.all_translation; 00182 00183 path = that.path; 00184 pathnum = that.pathnum; 00185 attr_dict = that.attr_dict; 00186 00187 xoff = that.xoff; 00188 yoff = that.yoff; 00189 zoff = that.zoff; 00190 00191 #ifdef EMAN2_USING_CUDA 00192 free_cuda_memory(); 00193 // There should also be the case where we deal with ro data... 00194 if (num_bytes != 0 && that.cuda_cache_handle != -1 && that.gpu_rw_is_current()) { 00195 float * cuda_data = that.get_cuda_data(); 00196 CudaDataLock lock1(&that); 00197 set_size_cuda(that.nx, that.ny, that.nz); 00198 float *cd = get_cuda_data(); 00199 CudaDataLock lock2(this); 00200 cudaError_t error = cudaMemcpy(cd,cuda_data,num_bytes,cudaMemcpyDeviceToDevice); 00201 if ( error != cudaSuccess ) throw UnexpectedBehaviorException("cudaMemcpy failed in operator= with error: " + string(cudaGetErrorString(error))); 00202 } 00203 // This is a bit of hack 00204 flags &= EMDATA_GPU_RO_NEEDS_UPDATE; 00205 #endif //EMAN2_USING_CUDA 00206 00207 changecount = that.changecount; 00208 00209 if (that.rot_fp != 0) rot_fp = new EMData(*(that.rot_fp)); 00210 else rot_fp = 0; 00211 } 00212 EXITFUNC; 00213 return *this; 00214 }
|
|
convert the complex image from real/imaginary to amplitude/phase
|
|
convert the complex image from real/imaginary to amplitude/phase
Definition at line 940 of file emdata_transform.cpp. References data, emdata_ri2ap(), ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), EMAN::EMData::is_complex(), EMAN::EMData::is_ri(), EMAN::EMData::nx, EMAN::EMData::ny, EMAN::EMData::nz, EMAN::EMData::set_ri(), and EMAN::EMData::update(). Referenced by EMAN::EMData::add_incoherent(), EMAN::OptVarianceCmp::cmp(), EMAN::EMData::get_fft_amplitude(), EMAN::EMData::get_fft_phase(), EMAN::TestImageFourierNoiseProfile::process_inplace(), EMAN::CTFSNRWeightProcessor::process_inplace(), EMAN::TestImageFourierNoiseGaussian::process_inplace(), EMAN::BinarizeFourierProcessor::process_inplace(), EMAN::RealToFFTProcessor::process_inplace(), EMAN::ComplexPixelProcessor::process_inplace(), EMAN::EMData::render_amp24(), and EMAN::EMData::render_ap24(). 00941 { 00942 ENTERFUNC; 00943 00944 if (!is_complex() || !is_ri()) { 00945 return; 00946 } 00947 #ifdef EMAN2_USING_CUDA 00948 if (gpu_operation_preferred()) { 00949 EMDataForCuda tmp = get_data_struct_for_cuda(); 00950 emdata_ri2ap(&tmp); 00951 set_ri(false); 00952 gpu_update(); 00953 EXITFUNC; 00954 return; 00955 } 00956 #endif 00957 00958 float * data = get_data(); 00959 00960 size_t size = nx * ny * nz; 00961 for (size_t i = 0; i < size; i += 2) { 00962 #ifdef _WIN32 00963 float f = (float)_hypot(data[i], data[i + 1]); 00964 #else 00965 float f = (float)hypot(data[i], data[i + 1]); 00966 #endif 00967 if (data[i] == 0 && data[i + 1] == 0) { 00968 data[i + 1] = 0; 00969 } 00970 else { 00971 data[i + 1] = atan2(data[i + 1], data[i]); 00972 } 00973 data[i] = f; 00974 } 00975 00976 set_ri(false); 00977 update(); 00978 EXITFUNC; 00979 }
|
|
convert the complex image from real/imaginary to Intensity/0. This conversion cannot be reversed, and the image remains marked as R/I |
|
convert the complex image from real/imaginary to Intensity/0. This conversion cannot be reversed, and the image remains marked as R/I Definition at line 909 of file emdata_transform.cpp. References EMAN::EMData::ap2ri(), data, emdata_ri2inten(), ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), EMAN::EMData::is_complex(), EMAN::EMData::is_ri(), EMAN::EMData::nx, EMAN::EMData::ny, EMAN::EMData::nz, EMAN::EMData::set_attr(), and EMAN::EMData::update(). Referenced by EMAN::CTFSNRWeightProcessor::process_inplace(). 00910 { 00911 ENTERFUNC; 00912 00913 if (!is_complex()) return; 00914 if (!is_ri()) ap2ri(); 00915 00916 #ifdef EMAN2_USING_CUDA 00917 if (gpu_operation_preferred()) { 00918 EMDataForCuda tmp = get_data_struct_for_cuda(); 00919 emdata_ri2inten(&tmp); 00920 set_attr("is_intensity", int(1)); 00921 gpu_update(); 00922 EXITFUNC; 00923 return; 00924 } 00925 #endif 00926 00927 float * data = get_data(); 00928 size_t size = nx * ny * nz; 00929 for (size_t i = 0; i < size; i += 2) { 00930 data[i]=data[i]*data[i]+data[i+1]*data[i+1]; 00931 data[i+1]=0; 00932 } 00933 00934 set_attr("is_intensity", int(1)); 00935 update(); 00936 EXITFUNC; 00937 }
|
|
Maps to polar coordinates from Cartesian coordinates. Optionaly radially weighted. When used with RFP, this provides 1 pixel accuracy at 75% radius. 2D only.
Definition at line 2284 of file emdata.cpp. References EMAN::Util::bilinear_interpolate(), EMAN::EMData::EMData(), emdata_unwrap(), ENTERFUNC, EXITFUNC, EMAN::Util::fast_floor(), EMAN::EMData::get_const_data(), EMAN::EMData::get_data(), EMAN::EMData::get_ndim(), ImageDimensionException, EMAN::EMData::nx, EMAN::EMData::ny, EMAN::EMData::set_size(), t, unbind_cuda_texture(), UnexpectedBehaviorException, EMAN::EMData::update(), x, and y. Referenced by EMAN::RTFExhaustiveAligner::align(), EMAN::RotatePrecenterAligner::align(), EMAN::EMData::make_rotational_footprint(), EMAN::EMData::make_rotational_footprint_cmc(), and EMAN::EMData::make_rotational_footprint_e1(). 02285 { 02286 ENTERFUNC; 02287 02288 if (get_ndim() != 2) { 02289 throw ImageDimensionException("2D image only"); 02290 } 02291 02292 int p = 1; 02293 if (do360) { 02294 p = 2; 02295 } 02296 02297 if (xs < 1) { 02298 xs = (int) Util::fast_floor(p * M_PI * ny / 4); 02299 xs -= xs % 8; 02300 if (xs<=8) xs=16; 02301 } 02302 02303 if (r1 < 0) { 02304 r1 = 4; 02305 } 02306 02307 #ifdef _WIN32 02308 int rr = ny / 2 - 2 - (int) Util::fast_floor(static_cast<float>(_hypot(dx, dy))); 02309 #else 02310 int rr = ny / 2 - 2 - (int) Util::fast_floor(static_cast<float>(hypot(dx, dy))); 02311 #endif //_WIN32 02312 rr-=rr%2; 02313 if (r2 <= r1 || r2 > rr) { 02314 r2 = rr; 02315 } 02316 02317 if ( (r2-r1) < 0 ) throw UnexpectedBehaviorException("The combination of function the arguments and the image dimensions causes unexpected behavior internally. Use a larger image, or a smaller value of r1, or a combination of both"); 02318 02319 #ifdef EMAN2_USING_CUDA 02320 if ( gpu_operation_preferred() ) { 02321 // cout << "Binding " << cuda_cache_handle << endl; 02322 bind_cuda_texture(); 02323 EMData* rslt = new EMData(); 02324 rslt->set_size_cuda(xs,r2-r1,1); 02325 EMDataForCuda r = rslt->get_data_struct_for_cuda(); 02326 // CudaDataLock lock1(rslt); 02327 /*EMDataForCuda* tmp = */emdata_unwrap(&r,r1,r2,xs,p,dx,dy,weight_radial,nx,ny); 02328 unbind_cuda_texture(); 02329 // EMData* e = new EMData(); 02330 // e->set_gpu_rw_data(tmp->data,tmp->nx,tmp->ny,tmp->nz); 02331 // free(tmp); 02332 return rslt; 02333 } 02334 #endif 02335 02336 EMData *ret = new EMData(); 02337 ret->set_size(xs, r2 - r1, 1); 02338 const float *const d = get_const_data(); 02339 float *dd = ret->get_data(); 02340 float pfac = (float)p/(float)xs; 02341 02342 int nxon2 = nx/2; 02343 int nyon2 = ny/2; 02344 for (int x = 0; x < xs; x++) { 02345 float ang = x * M_PI * pfac; 02346 float si = sin(ang); 02347 float co = cos(ang); 02348 02349 for (int y = 0; y < r2 - r1; y++) { 02350 float ypr1 = (float)y + r1; 02351 float xx = ypr1 * co + nxon2 + dx; 02352 float yy = ypr1 * si + nyon2 + dy; 02353 // float t = xx - Util::fast_floor(xx); 02354 // float u = yy - Util::fast_floor(yy); 02355 float t = xx - (int)xx; 02356 float u = yy - (int)yy; 02357 // int k = (int) Util::fast_floor(xx) + (int) (Util::fast_floor(yy)) * nx; 02358 int k = (int) xx + ((int) yy) * nx; 02359 float val = Util::bilinear_interpolate(d[k], d[k + 1], d[k + nx], d[k + nx+1], t,u); 02360 if (weight_radial) val *= ypr1; 02361 dd[x + y * xs] = val; 02362 } 02363 02364 } 02365 ret->update(); 02366 02367 EXITFUNC; 02368 return ret; 02369 }
|