43#include <gsl/gsl_sf_bessel.h>
44#include <gsl/gsl_errno.h>
53 #define M_PI 3.14159265358979323846f
56#define EMDATA_EMAN2_DEBUG 0
58#ifdef EMAN2_USING_CUDA
68int EMData::totalalloc=0;
71#ifdef EMAN2_USING_CUDA
72 cudarwdata(0), cudarodata(0), num_bytes(0), nextlistitem(0), prevlistitem(0), roneedsupdate(0), cudadirtybit(0),
77 attr_dict(),
rdata(0), supp(0), flags(0), changecount(0), nx(0), ny(0), nz(0), nxy(0), nxyz(0), xoff(0), yoff(0),
78 zoff(0), all_translation(), path(
""), pathnum(0), rot_fp(0)
102#ifdef EMAN2_USING_CUDA
103 cudarwdata(0), cudarodata(0), num_bytes(0), nextlistitem(0), prevlistitem(0), roneedsupdate(0), cudadirtybit(0),
108 attr_dict(),
rdata(0), supp(0), flags(0), changecount(0), nx(0), ny(0), nz(0), nxy(0), nxyz(0), xoff(0), yoff(0), zoff(0),
109 all_translation(), path(filename), pathnum(image_index), rot_fp(0)
135#ifdef EMAN2_USING_CUDA
136 cudarwdata(0), cudarodata(0), num_bytes(0), nextlistitem(0), prevlistitem(0), roneedsupdate(0), cudadirtybit(0),
141 attr_dict(that.attr_dict),
rdata(0), supp(0), flags(that.flags), changecount(that.changecount), nx(that.nx), ny(that.ny), nz(that.nz),
142 nxy(that.nx*that.ny), nxyz((size_t)that.nx*that.ny*that.nz), xoff(that.xoff), yoff(that.yoff), zoff(that.zoff),all_translation(that.all_translation), path(that.path),
143 pathnum(that.pathnum), rot_fp(0)
147 float* data = that.
rdata;
148 size_t num_bytes = (size_t)
nx*
ny*
nz*
sizeof(
float);
149 if (data && num_bytes != 0)
154#ifdef EMAN2_USING_CUDA
155 if (EMData::usecuda == 1 && num_bytes != 0 && that.cudarwdata != 0) {
158 cudaError_t error = cudaMemcpy(cudarwdata,that.cudarwdata,num_bytes,cudaMemcpyDeviceToDevice);
159 if ( error != cudaSuccess )
throw UnexpectedBehaviorException(
"cudaMemcpy failed in EMData copy construction with error: " +
string(cudaGetErrorString(error)));
182 float* data = that.
rdata;
183 size_t num_bytes = that.
nx*that.
ny*that.
nz*
sizeof(float);
184 if (data && num_bytes != 0)
203#ifdef EMAN2_USING_CUDA
204 if (EMData::usecuda == 1 && num_bytes != 0 && that.cudarwdata != 0) {
205 if(cudarwdata){rw_free();}
207 cudaError_t error = cudaMemcpy(cudarwdata,that.cudarwdata,num_bytes,cudaMemcpyDeviceToDevice);
208 if ( error != cudaSuccess )
throw UnexpectedBehaviorException(
"cudaMemcpy failed in EMData copy construction with error: " +
string(cudaGetErrorString(error)));
222#ifdef EMAN2_USING_CUDA
223 cudarwdata(0), cudarodata(0), num_bytes(0), nextlistitem(0), prevlistitem(0), roneedsupdate(0), cudadirtybit(0),
228 attr_dict(),
rdata(0), supp(0), flags(0), changecount(0), nx(0), ny(0), nz(0), nxy(0), nxyz(0), xoff(0), yoff(0), zoff(0),
229 all_translation(), path(
""), pathnum(0), rot_fp(0)
245 int new_nx =
nx + 2 -
nx%2;
250 if(
ny==1 &&
nz ==1) {
277#ifdef EMAN2_USING_CUDA
278 cudarwdata(0), cudarodata(0), num_bytes(0), nextlistitem(0), prevlistitem(0), roneedsupdate(0), cudadirtybit(0),
283 attr_dict(attr_dict),
rdata(data), supp(0), flags(0), changecount(0), nx(
x), ny(
y), nz(z), nxy(
x*
y), nxyz((size_t)
x*
y*z), xoff(0),
284 yoff(0), zoff(0), all_translation(), path(
""), pathnum(0), rot_fp(0)
301#ifdef EMAN2_USING_CUDA
303EMData::EMData(
float* data,
float* cudadata,
const int x,
const int y,
const int z,
const Dict& attr_dict) :
304 cudarwdata(cudadata), cudarodata(0), num_bytes(
x*
y*z*sizeof(float)), nextlistitem(0), prevlistitem(0), roneedsupdate(0), cudadirtybit(1),
308 attr_dict(attr_dict),
rdata(data), supp(0), flags(0), changecount(0), nx(
x), ny(
y), nz(z), nxy(
x*
y), nxyz((size_t)
x*
y*z), xoff(0),
309 yoff(0), zoff(0), all_translation(), path(
""), pathnum(0), rot_fp(0)
335 if (fftcache!=0) {
delete fftcache; fftcache=0;}
339#ifdef EMAN2_USING_CUDA
340 if(cudarwdata){rw_free();}
341 if(cudarodata){ro_free();}
357 int prev_nx =
nx, prev_ny =
ny, prev_nz =
nz;
358 size_t prev_size = (size_t)
nx*
ny*
nz;
361 int new_nz = ( area.
size[2]==0 ? 1 : (int)area.
size[2]);
362 int new_ny = ( area.
size[1]==0 ? 1 : (int)area.
size[1]);
363 int new_nx = (int)area.
size[0];
365 if ( new_nz < 0 || new_ny < 0 || new_nx < 0 )
368 throw ImageDimensionException(
"New image dimensions are negative - this is not supported in the clip_inplace operation");
371 size_t new_size = (size_t)new_nz*new_ny*new_nx;
374 int x0 = (int) area.
origin[0];
375 int y0 = (
int) area.
origin[1];
376 int z0 = (int) area.
origin[2];
383 if ( x0 > prev_nx || y0 > prev_ny || z0 > prev_nz || civ.x_iter == 0 || civ.y_iter == 0 || civ.z_iter == 0)
400 if ( new_size > prev_size )
404 size_t clipped_row_size = (civ.x_iter) *
sizeof(
float);
407 size_t new_sec_size = new_nx * new_ny;
408 size_t prev_sec_size = prev_nx * prev_ny;
412 size_t src_it_begin = civ.prv_z_bottom*prev_sec_size + civ.prv_y_front*prev_nx + civ.prv_x_left;
413 size_t dst_it_begin = civ.new_z_bottom*new_sec_size + civ.new_y_front*new_nx + civ.new_x_left;
418 for (
int i = 0; i < civ.z_iter; ++i) {
419 for (
int j = 0; j < civ.y_iter; ++j) {
423 size_t dst_inc = dst_it_begin + j*new_nx + i*new_sec_size;
424 size_t src_inc = src_it_begin + j*prev_nx + i*prev_sec_size;
425 float* local_dst =
rdata + dst_inc;
426 float* local_src =
rdata + src_inc;
428 if ( dst_inc >= src_inc )
438 Assert( dst_inc < new_size && src_inc < prev_size && dst_inc >= 0 && src_inc >= 0 );
441 memmove(local_dst, local_src, clipped_row_size);
447 size_t src_it_end = prev_size - civ.prv_z_top*prev_sec_size - civ.prv_y_back*prev_nx - prev_nx + civ.prv_x_left;
448 size_t dst_it_end = new_size - civ.new_z_top*new_sec_size - civ.new_y_back*new_nx - new_nx + civ.new_x_left;
453 for (
int i = 0; i < civ.z_iter; ++i) {
454 for (
int j = 0; j < civ.y_iter; ++j) {
457 size_t dst_inc = dst_it_end - j*new_nx - i*new_sec_size;
458 size_t src_inc = src_it_end - j*prev_nx - i*prev_sec_size;
459 float* local_dst =
rdata + dst_inc;
460 float* local_src =
rdata + src_inc;
462 if (dst_inc <= (src_inc + civ.x_iter ))
465 if ( dst_inc > src_inc )
477 memmove(local_dst, local_src, clipped_row_size);
483 Assert( dst_inc < new_size && src_inc < prev_size && dst_inc >= 0 && src_inc >= 0 );
492 if ( new_size < prev_size )
501 size_t inc = (-z0)*new_sec_size;
506 if ( civ.new_z_top > 0 )
508 float* begin_pointer =
rdata + (new_nz-civ.new_z_top)*new_sec_size;
510 float* end_pointer = begin_pointer+(civ.new_z_top)*new_sec_size;
511 std::fill(begin_pointer,end_pointer,fill_value);
515 for (
int i = civ.new_z_bottom; i < civ.new_z_bottom + civ.z_iter; ++i )
520 float* begin_pointer =
rdata + i*new_sec_size;
522 float* end_pointer = begin_pointer+(-y0)*new_nx;
523 std::fill(begin_pointer,end_pointer,fill_value);
527 if ( civ.new_y_back > 0 )
529 float* begin_pointer =
rdata + i*new_sec_size + (new_ny-civ.new_y_back)*new_nx;
531 float* end_pointer = begin_pointer+(civ.new_y_back)*new_nx;
532 std::fill(begin_pointer,end_pointer,fill_value);
536 for (
int j = civ.new_y_front; j <civ.new_y_front + civ.y_iter; ++j)
541 float* begin_pointer =
rdata + i*new_sec_size + j*new_nx;
543 float* end_pointer = begin_pointer+(-x0);
544 std::fill(begin_pointer,end_pointer,fill_value);
548 if ( civ.new_x_right > 0 )
550 float* begin_pointer =
rdata + i*new_sec_size + j*new_nx + (new_nx - civ.new_x_right);
552 float* end_pointer = begin_pointer+(civ.new_x_right);
553 std::fill(begin_pointer,end_pointer,fill_value);
582 yorigin + apix_y * area.
origin[1],
583 zorigin + apix_z * area.
origin[2]);
607 int zsize = (int)area.
size[2];
608 if (zsize == 0 &&
nz <= 1) {
611 int ysize = (
ny<=1 && (int)area.
size[1]==0 ? 1 : (
int)area.
size[1]);
613 if ( (
int)area.
size[0] < 0 || ysize < 0 || zsize < 0 )
616 throw ImageDimensionException(
"New image dimensions are negative - this is not supported in the the get_clip operation");
634 result->set_size((
int)area.
size[0], ysize, zsize);
635 if (fill != 0.0) { result->to_value(fill); };
638 int x0 = (int) area.
origin[0];
639 x0 = x0 < 0 ? 0 : x0;
641 int y0 = (
int) area.
origin[1];
642 y0 = y0 < 0 ? 0 : y0;
644 int z0 = (int) area.
origin[2];
645 z0 = z0 < 0 ? 0 : z0;
647 int x1 = (
int) (area.
origin[0] + area.
size[0]);
648 x1 = x1 >
nx ?
nx : x1;
650 int y1 = (int) (area.
origin[1] + area.
size[1]);
651 y1 = y1 >
ny ?
ny : y1;
653 int z1 = (int) (area.
origin[2] + area.
size[2]);
654 z1 = z1 >
nz ?
nz : z1;
667 result->set_attr(
"apix_x",apix_x);
668 result->set_attr(
"apix_y",apix_y);
669 result->set_attr(
"apix_z",apix_z);
680 yorigin + apix_y * area.
origin[1],
681 zorigin + apix_z * area.
origin[2]);
699 result->set_path(
path);
717 half->set_size(
nx,
ny,
nz / 2);
719 float *half_data = half->get_data();
724 origin_z += apix_z *
nz / 2;
737 result->set_size(size[0],size[1],size[2]);
740 for (
int y=-size[1]/2;
y<(size[1]+1)/2;
y++) {
741 for (
int x=-size[0]/2;
x<(size[0]+1)/2;
x++) {
745 if (xv[0]<0||xv[1]<0||xv[0]>
nx-2||xv[1]>
ny-2) v=0.;
747 result->set_value_at(
x+size[0]/2,
y+size[1]/2,v);
752 for (
int z=-size[2]/2; z<(size[2]+1)/2; z++) {
753 for (
int y=-size[1]/2;
y<(size[1]+1)/2;
y++) {
754 for (
int x=-size[0]/2;
x<(size[0]+1)/2;
x++) {
758 if (xv[0]<0||xv[1]<0||xv[2]<0||xv[0]>
nx-2||xv[1]>
ny-2||xv[2]>
nz-2) v=0.;
760 result->set_value_at(
x+size[0]/2,
y+size[1]/2,z+size[2]/2,v);
781 LOGERR(
"Need real-space data for window_center()");
783 "Complex input image; real-space expected.");
789 int corner = n/2 - l/2;
794 if ((n !=
ny) || (n !=
nz)) {
795 LOGERR(
"Need the real-space image to be cubic.");
797 "Need cubic real-space image.");
803 LOGERR(
"Need the real-space image to be square.");
805 "Need square real-space image.");
815 "window_center only supports 1-d, 2-d, and 3-d images");
845 const int SUPP_ROW_SIZE = 8;
846 const int SUPP_ROW_OFFSET = 4;
847 const int supp_size = SUPP_ROW_SIZE + SUPP_ROW_OFFSET;
851 int supp_xy = supp_size *
ny;
854 for (
int z = 0; z <
nz; z++) {
855 size_t cur_z1 = z *
nxy;
856 size_t cur_z2 = z * supp_xy;
858 for (
int y = 0;
y <
ny;
y++) {
859 size_t cur_y1 =
y *
nx;
860 size_t cur_y2 =
y * supp_size;
862 for (
int x = 0;
x < SUPP_ROW_SIZE;
x++) {
863 size_t k = (
x + SUPP_ROW_OFFSET) + cur_y2 + cur_z2;
864 supp[k] = data[
x + cur_y1 + cur_z1];
869 for (
int z = 1, zz =
nz - 1; z <
nz; z++, zz--) {
870 size_t cur_z1 = zz *
nxy;
871 size_t cur_z2 = z * supp_xy;
873 for (
int y = 1, yy =
ny - 1;
y <
ny;
y++, yy--) {
874 supp[
y * 12 + cur_z2] = data[4 + yy *
nx + cur_z1];
875 supp[1 +
y * 12 + cur_z2] = -data[5 + yy *
nx + cur_z1];
876 supp[2 +
y * 12 + cur_z2] = data[2 + yy *
nx + cur_z1];
877 supp[3 +
y * 12 + cur_z2] = -data[3 + yy *
nx + cur_z1];
910 if( ( (dx-dx_) == 0 ) && ( (dy-dy_) == 0 ) && ( (dz-dz_) == 0 )) {
925 if( translation[0] == 0 && translation[1] == 0 && translation[2] == 0) {
930 Dict params(
"trans",
static_cast< vector<int>
>(translation));
944 if( translation[0] == 0.0f && translation[1] == 0.0f && translation[2] == 0.0f ) {
961 Dict d(
"type",
"eman");
973 cout <<
"Deprecation warning in EMData::rotate. Please consider using EMData::transform() instead " << endl;
985 for (
int i=0; i<int(2*M_PI*r0+0.5); i++) {
986 float ang = (float)i/r;
987 Vec3f v =
Vec3f(r0*cos(ang), r0*sin(ang), 0.0f);
997 cout <<
"Deprecation warning in EMData::rotate_translate. Please consider using EMData::transform() instead " << endl;
1007 float dz,
float pdx,
float pdy,
float pdz)
1009 cout <<
"Deprecation warning in EMData::rotate_translate. Please consider using EMData::transform() instead " << endl;
1218 size_t row_size =
nx *
sizeof(float);
1222 for (
int y = 0;
y <
ny;
y++) {
1224 for (
int x = 0;
x <
nx;
x++) {
1225 tmp[
x] = data[y_nx + (
x + dx) %
nx];
1244 LOGERR(
"images not same size");
1249 LOGERR(
"1D/2D Images only");
1253 float *this_data = 0;
1257 float da_rad = da*(float)M_PI/180.0f;
1259 float *with_data = with->get_data();
1260 float mx0 = cos(da_rad);
1261 float mx1 = sin(da_rad);
1262 float y = -
ny / 2.0f;
1263 float my0 = mx0 * (-
nx / 2.0f - 1.0f) +
nx / 2.0f - dx;
1264 float my1 = -mx1 * (-
nx / 2.0f - 1.0f) +
ny / 2.0f - dy;
1267 for (
int j = 0; j <
ny; j++) {
1268 float x2 = my0 + mx1 *
y;
1269 float y2 = my1 + mx0 *
y;
1276 for (
int i = 0; i <
nx; i++) {
1300 if (ii >= 0 && ii <= nx - 2 && jj >= 0 && jj <=
ny - 2) {
1301 int k0 = ii + jj *
nx;
1303 int k2 = k0 +
nx + 1;
1308 int idx = i + j *
nx;
1309 if (mirror) idx =
nx-1-i+j*
nx;
1310 result += (this_data[k0] * tt * uu + this_data[k1] * t * uu +
1311 this_data[k2] * t * u + this_data[k3] * tt * u) * with_data[idx];
1334 int nx2 = with->get_xsize();
1335 int ny2 = with->get_ysize();
1336 float em = with->get_edge_mean();
1339 float *with_data = with->get_data();
1340 float *ret_data = ret->get_data();
1342 float sum2 = (
Util::square((
float)with->get_attr(
"sigma")) +
1345 for (
int j = ny2 / 2; j <
ny - ny2 / 2; j++) {
1346 for (
int i = nx2 / 2; i <
nx - nx2 / 2; i++) {
1352 for (
int jj = j - ny2 / 2; jj < j + ny2 / 2; jj++) {
1353 for (
int ii = i - nx2 / 2; ii < i + nx2 / 2; ii++) {
1354 int l = ii + jj *
nx;
1357 sum += data[l] * with_data[k];
1361 float tmp_f1 = (sum1 / 2.0f - sum) / (nx2 * ny2);
1362 float tmp_f2 =
Util::square((
float)with->get_attr(
"mean") -
1363 summ / (nx2 * ny2));
1364 ret_data[i + j *
nx] = sum2 + tmp_f1 - tmp_f2;
1369 for (
int j = ny2 / 2; j <
ny - ny2 / 2; j++) {
1370 for (
int i = nx2 / 2; i <
nx - nx2 / 2; i++) {
1375 for (
int ii = i - nx2 / 2; ii < i + nx2 / 2; ii++) {
1376 eml += data[ii + (j - ny2 / 2) *
nx] + data[ii + (j + ny2 / 2 - 1) *
nx];
1379 for (
int jj = j - ny2 / 2; jj < j + ny2 / 2; jj++) {
1380 eml += data[i - nx2 / 2 + jj *
nx] + data[i + nx2 / 2 - 1 + jj *
nx];
1383 eml /= (nx2 + ny2) * 2.0f;
1386 for (
int jj = j - ny2 / 2; jj < j + ny2 / 2; jj++) {
1387 for (
int ii = i - nx2 / 2; ii < i + nx2 / 2; ii++) {
1388 dot += (data[ii + jj *
nx] - eml) * (with_data[k] - em);
1397 ret_data[i + j *
nx] = 0;
1400 ret_data[i + j *
nx] =
dot / (nx2 * ny2 * dot2 * (float)with->get_attr(
"sigma"));
1426 result->set_size(
nx,
ny, 1);
1428 float *result_data = result->get_data();
1430 EMData *this_copy =
this;
1433 for (
int i = 0; i <
nx; i++) {
1437 float *copy_data = this_copy->get_data();
1439 for (
int y = 0;
y <
nx;
y++) {
1440 for (
int x = 0;
x <
nx;
x++) {
1442 result_data[i +
y *
nx] += copy_data[
x +
y *
nx];
1447 this_copy->update();
1472 if (
nz == 1 ) it_z = 0;
1473 if (
ny == 1 ) it_y = 0;
1474 if (
nx == 1 ) it_z = 0;
1476 if (
nz == 1 &&
ny == 1 )
1478 for (
int x = -it_x;
x <= it_x; ++
x )
1484 for (
int y = -it_y;
y <= it_y; ++
y)
1485 for (
int x = -it_x;
x <= it_x; ++
x )
1490 for(
int z = -it_z; z <= it_z; ++z )
1491 for (
int y = -it_y;
y <= it_y; ++
y)
1492 for (
int x = -it_x;
x < it_x; ++
x )
1504#ifdef EMAN2_USING_CUDA
1505 if(EMData::usecuda == 1 && cudarwdata) {
1508 bool delifft =
false;
1513 ifft = do_fft_cuda();
1521 EMData * conv = ifft->do_ift_cuda();
1522 if(delifft)
delete ifft;
1529 return convolution(
this,
this,fpflag, center);
1531 else if ( with ==
this ){
1533 return correlation(
this,
this, fpflag,center);
1537#ifdef EMAN2_USING_CUDA
1541 if(EMData::usecuda == 1 && cudarwdata && with->cudarwdata) {
1545 bool delafft =
false, delbfft =
false;
1550 afft = do_fft_cuda();
1557 if(!with->is_complex()){
1558 bfft = with->do_fft_cuda();
1567 if(delbfft)
delete bfft;
1569 EMData * corr = afft->do_ift_cuda();
1570 if(delafft)
delete afft;
1579 bool undoresize =
false;
1580 int wnx = with->get_xsize();
int wny = with->get_ysize();
int wnz = with->get_zsize();
1581 if (!(
is_complex()^with->is_complex()) && (wnx !=
nx || wny !=
ny || wnz !=
nz) ) {
1587 EMData* cor = correlation(
this, with, fpflag, center);
1591 Region r((
nx-wnx)/2, (
ny-wny)/2,(
nz-wnz)/2,wnx,wny,wnz);
1602 if ((withsq==0 && mask!=0)||(withsq!=0 && mask==0))
1603 throw NullPointerException(
"calc_ccf_masked error, both or neither of withsq and mask must be specified");
1607 withsq=with->process(
"math.squared");
1608 mask=this->
process(
"threshold.notzero");
1616 c2->process_inplace(
"math.reciprocal",
Dict(
"zero_to",0.0f));
1617 c2->process_inplace(
"math.sqrt");
1633 LOGERR(
"NULL 'with' image. ");
1638 LOGERR(
"images not same size: (%d,%d,%d) != (%d,%d,%d)",
1640 with->get_xsize(), with->get_ysize(), with->get_zsize());
1644 LOGERR(
"2D images only");
1672 int width = (
nx+2-(
nx%2));
1673 int wpad = ((width+3)/4)*4;
1687#ifdef EMAN2_USING_CUDA
1689 if (EMData::usecuda == 1 && cudarwdata && with->cudarwdata) {
1691 if(!f1.cudarwdata) f1.rw_alloc();
1692 if(!f2.cudarwdata) f2.rw_alloc();
1693 if(!rslt.cudarwdata) rslt.rw_alloc();
1714 float *d2 = with->get_data();
1715 float *f1d = f1.get_data();
1716 float *f2d = f2.get_data();
1717 for (
int j = 0; j < height; j++) {
1718 EMfft::real_to_complex_1d(d1 + j *
nx, f1d+j*wpad,
nx);
1719 EMfft::real_to_complex_1d(d2 + j *
nx, f2d+j*wpad,
nx);
1723 for (
int j = 0; j < height; j++) {
1724 float *f1a = f1d + j * wpad;
1725 float *f2a = f2d + j * wpad;
1727 for (
int i = 0; i < width / 2; i++) {
1728 float re1 = f1a[2*i];
1729 float re2 = f2a[2*i];
1730 float im1 = f1a[2*i+1];
1731 float im2 = f2a[2*i+1];
1733 f1d[j*wpad+i*2] = re1 * re2 + im1 * im2;
1734 f1d[j*wpad+i*2+1] = im1 * re2 - re1 * im2;
1738 for (
int j = 0; j < height; j++) {
1739 float *f1a = f1d + j * wpad;
1740 float *f2a = f2d + j * wpad;
1742 for (
int i = 0; i < width / 2; i++) {
1743 float re1 = f1a[2*i];
1744 float re2 = f2a[2*i];
1745 float im1 = f1a[2*i+1];
1746 float im2 = f2a[2*i+1];
1748 f1d[j*wpad+i*2] = re1 * re2 - im1 * im2;
1749 f1d[j*wpad+i*2+1] = im1 * re2 + re1 * im2;
1754 float* rd = rslt.get_data();
1755 for (
int j = y0; j < y1; j++) {
1756 EMfft::complex_to_real_1d(f1d+j*wpad, rd+j*
nx,
nx);
1762 for (
int y=0;
y<height;
y++) {
1764 for (
int x=0;
x<
nx;
x++) {
1783 float *c = cf->get_data();
1784 for (
int j = 0; j < height; j++) {
1785 for(
int i = 0; i <
nx; ++i) {
1809 static int updsize = 0;
1810 EMData* filt = &obj_filt;
1811 filt->set_complex(
true);
1818 if (filt->get_xsize() !=
nx+2-(
nx%2) || filt->get_ysize() !=
ny ||
1819 filt->get_zsize() !=
nz ) {
1823 printf(
"FAILSAFE!!!!\n");
1826 filt->process_inplace(
"filter.highpass.gauss",
Dict(
"cutoff_abs", 1.5f/
nx));
1830 filt->set_size(
nx+2-(
nx%2),
ny,
nz);
1833 filt->process_inplace(
"filter.highpass.gauss",
Dict(
"cutoff_abs", 1.5f/
nx));
1839 ccf->sub(ccf->get_edge_mean());
1841 delete ccf; ccf = 0;
1843 if (delfilt)
delete filt;
1877 ccf->sub(ccf->get_edge_mean());
1880 delete ccf; ccf = 0;
1914 EMData* filt = &obj_filt;
1915 filt->set_complex(
true);
1922 int cs = (((
nx * 7 / 4) & 0xfffff8) -
nx) / 2;
1925 int big_x =
nx+2*cs;
1926 int big_y =
ny+2*cs;
1933 if ( big_clip.get_xsize() != big_x || big_clip.get_ysize() != big_y || big_clip.get_zsize() != big_z ) {
1934 big_clip.set_size(big_x,big_y,big_z);
1943 big_clip.insert_clip(
this,
IntPoint(cs,cs,cs));
1945 big_clip.insert_clip(
this,
IntPoint(cs,cs,0));
1952 if (filt->get_xsize() != big_clip.get_xsize() +2-(big_clip.get_xsize()%2) || filt->get_ysize() != big_clip.get_ysize() ||
1953 filt->get_zsize() != big_clip.get_zsize()) {
1954 filt->set_size(big_clip.get_xsize() + 2-(big_clip.get_xsize()%2), big_clip.get_ysize(), big_clip.get_zsize());
1956 filt->process_inplace(
"filter.highpass.gauss",
Dict(
"cutoff_abs", 1.5f/
nx));
1957#ifdef EMAN2_USING_CUDA
1966#ifdef EMAN2_USING_CUDA
1976 mc->sub(mc->get_edge_mean());
1979 int sml_x =
nx * 3 / 2;
1980 int sml_y =
ny * 3 / 2;
1986 if ( sml_clip.get_xsize() != sml_x || sml_clip.get_ysize() != sml_y || sml_clip.get_zsize() != sml_z ) {
1987 sml_clip.set_size(sml_x,sml_y,sml_z); }
1991 sml_clip.insert_clip(mc,
IntPoint(-cs+
nx/4,-cs+
ny/4,0));
1999#ifdef EMAN2_USING_CUDA
2002 result = sml_clip.process(
"mask.sharp",
Dict(
"outer_radius", -1,
"value", 0));
2006 result = sml_clip.
unwrap();
2013 result =
new EMData(sml_clip);
2016#ifdef EMAN2_USING_CUDA
2040 if (un->get_ysize() <= 6) {
2051 else if (type==1 || type==2 ||type==5 || type==6) {
2052 int i,j,kx,ky,lx,ly;
2058 float *rmap=(
float *)malloc(rmax*rmax*
sizeof(
float));
2059 for (i=0; i<rmax; i++) {
2060 for (j=0; j<rmax; j++) {
2061 rmap[i+j*rmax]=hypot((
float)i,(
float)j);
2073 for (kx=-rmax+1; kx<rmax; kx++) {
2074 for (ky=-rmax+1; ky<rmax; ky++) {
2075 for (lx=-rmax+1; lx<rmax; lx++) {
2076 for (ly=-rmax+1; ly<rmax; ly++) {
2079 if (abs(ax)>=rmax || abs(ay)>=rmax)
continue;
2080 int r1=(int)floor(.5+rmap[abs(kx)+rmax*abs(ky)]);
2081 int r2=(int)floor(.5+rmap[abs(lx)+rmax*abs(ly)]);
2084 if (r1+r2>=rmax)
continue;
2086 std::complex<float> p=fft->get_complex_at(kx,ky)*fft->get_complex_at(lx,ly)*conj(fft->get_complex_at(ax,ay));
2087 fp->set_value_at(r1*2,r2,p.real()+fp->get_value_at(r1*2,r2));
2090 fp->set_value_at(r1*2+1,r2,fp->get_value_at(r1*2+1,r2)+1);
2097 if (type==5 || type==6) {
2098 for (i=0; i<rmax*2; i+=2) {
2099 for (j=0; j<rmax; j++) {
2100 float norm=fp->get_value_at(i+1,j);
2101 fp->set_value_at(i,rmax*2-j-1,cbrt(fp->get_value_at(i,j)/(norm==0?1.0:norm)));
2102 fp->set_value_at(i,j,cbrt(fp->get_value_at(i,j)/(norm==0?1.0:norm)));
2103 fp->set_value_at(i+1,j,0.0);
2108 for (i=0; i<rmax*2; i+=2) {
2109 for (j=0; j<rmax; j++) {
2110 float norm=fp->get_value_at(i+1,j);
2111 fp->set_value_at(i,rmax*2-j-1,fp->get_value_at(i,j)/(norm==0.0f?1.0f:norm));
2112 fp->set_value_at(i,j,fp->get_value_at(i,j)/(norm==0.0f?1.0f:norm));
2113 fp->set_value_at(i+1,j,0.0);
2119 if (type==2||type==6) {
2121 if (f2->get_value_at(0,0)<0) f2->mult(-1.0f);
2122 f2->process_inplace(
"xform.phaseorigin.tocorner");
2128 else if (type==3 || type==4) {
2129 int h,i,j,kx,ky,lx,ly;
2135 float *rmap=(
float *)malloc(rmax*rmax*
sizeof(
float));
2136 for (i=0; i<rmax; i++) {
2137 for (j=0; j<rmax; j++) {
2138 rmap[i+j*rmax]=hypot((
float)i,(
float)j);
2151 for (kx=-rmax+1; kx<rmax; kx++) {
2152 for (ky=-rmax+1; ky<rmax; ky++) {
2153 for (lx=-rmax+1; lx<rmax; lx++) {
2154 for (ly=-rmax+1; ly<rmax; ly++) {
2157 if (abs(ax)>=rmax || abs(ay)>=rmax)
continue;
2158 float rr1=rmap[abs(kx)+rmax*abs(ky)];
2159 float rr2=rmap[abs(lx)+rmax*abs(ly)];
2160 int r1=(int)floor(.5+rr1);
2161 int r2=(int)floor(.5+rr2);
2164 if (r1+r2>=rmax || rr1==0 ||rr2==0)
continue;
2166 std::complex<float> p=fft->get_complex_at(kx,ky)*fft->get_complex_at(lx,ly)*conj(fft->get_complex_at(ax,ay));
2167 int dot=(int)floor((kx*lx+ky*ly)/(rr1*rr2)*7.5);
2170 fp->set_value_at(r1*2,r2,
dot,p.real()+fp->get_value_at(r1*2,r2,
dot));
2173 fp->set_value_at(r1*2+1,r2,
dot,fp->get_value_at(r1*2+1,r2,
dot)+1);
2180 for (i=0; i<rmax*2; i+=2) {
2181 for (j=0; j<rmax; j++) {
2182 for (h=0; h<16; h++) {
2183 float norm=fp->get_value_at(i+1,j,h);
2186 fp->set_value_at(i,rmax*2-j-1,h,(fp->get_value_at(i,j,h)/(norm==0.0f?1.0f:norm)));
2187 fp->set_value_at(i,j,h,(fp->get_value_at(i,j,h)/(norm==0.0f?1.0f:norm)));
2190 fp->set_value_at(i+1,j,h,0.0);
2198 if (f2->get_value_at(0,0,0)<0) f2->mult(-1.0f);
2199 f2->process_inplace(
"xform.phaseorigin.tocorner");
2214 LOGERR(
"images not same size");
2218#ifdef EMAN2_USING_CUDA
2219 if(EMData::usecuda == 1 && cudarwdata && with->cudarwdata)
2222 EMData* this_fft = do_fft_cuda();
2225 if (with && with !=
this) {
2226 cf = with->do_fft_cuda();
2228 cf = this_fft->copy();
2233 LOGERR(
"improperly sized filter");
2237 mult_complex_efficient_cuda(this_fft->cudarwdata, filter->cudarwdata, this_fft->get_xsize(), this_fft->get_ysize(), this_fft->get_zsize(), 1);
2240 mcf_cuda(this_fft->cudarwdata, cf->cudarwdata, this_fft->get_xsize(), this_fft->get_ysize(), this_fft->get_zsize());
2242 EMData *f2 = cf->do_ift_cuda();
2245 f2->process_inplace(
"xform.phaseorigin.tocenter");
2260 f2->set_attr(
"label",
"MCF");
2261 f2->set_path(
"/tmp/eman.mcf");
2274 LOGERR(
"FFT returns NULL image");
2281 if (with && with !=
this) {
2282 cf = with->do_fft();
2284 LOGERR(
"FFT returns NULL image");
2290 cf = this_fft->copy();
2295 LOGERR(
"improperly sized filter");
2299 cf->mult_complex_efficient(*filter,
true);
2300 this_fft->mult(*filter,
true);
2307 float *rdata1 = this_fft->get_data();
2308 float *rdata2 = cf->get_data();
2309 size_t this_fft_size = (size_t)this_fft->get_xsize() * this_fft->get_ysize() * this_fft->get_zsize();
2312 for (
size_t i = 0; i < this_fft_size; i += 2) {
2313 rdata2[i] =
std::sqrt(rdata1[i] * rdata2[i] + rdata1[i + 1] * rdata2[i + 1]);
2321 for (
size_t i = 0; i < this_fft_size; i += 2) {
2322 rdata2[i] = (rdata1[i] * rdata2[i] + rdata1[i + 1] * rdata2[i + 1]);
2323 rdata2[i + 1] = (rdata1[i + 1] * rdata2[i] - rdata1[i] * rdata2[i + 1]);
2327 for (
size_t i = 0; i < this_fft_size; i += 2) {
2339 EMData *f2 = cf->do_ift();
2342 f2->process_inplace(
"xform.phaseorigin.tocenter");
2357 f2->set_attr(
"label",
"MCF");
2358 f2->set_path(
"/tmp/eman.mcf");
2365vector < float >
EMData::calc_hist(
int hist_size,
float histmin,
float histmax,
const float& brt,
const float& cont)
2371 size_t size = (size_t)
nx *
ny *
nz;
2372 if (histmin == histmax) {
2377 float w = (float)(n-1) / (histmax - histmin);
2380 vector <float> hist(hist_size, 0.0);
2382 if (cont != 1.0f || brt != 0) {
2383 for(
size_t i=0; i<size; i++) {
2384 float val = cont*(data[i]+brt);
2394 for(
size_t i=0; i<size; i++) {
2395 float val = data[i];
2483 float *yc =
new float[n];
2485 vector<float> vd(n);
2486 for (
int i = 0; i < n; i++) {
2496 for (
int y = 0;
y <
ny;
y++) {
2497 for (
int x = 0;
x <
nx;
x += 2, c += 2) {
2502 if (r >= rmin && r <= rmax) {
2505 if (
y !=
ny / 2 ||
x != 0) {
2506 a = (atan2((
float)y1, (
float)x1) - a0) / da;
2509 int i = (int)(floor(a));
2514 h = (float)hypot(data[c], data[c + 1]);
2518 vd[0] += h * (1.0f - a);
2519 yc[0] += (1.0f - a);
2521 else if (i == n - 1) {
2525 else if (i > 0 && i < (n - 1)) {
2526 vd[i] += h * (1.0f - a);
2527 yc[i] += (1.0f - a);
2537 float half_nx = (
nx - 1) / 2.0f;
2538 float half_ny = (
ny - 1) / 2.0f;
2540 for (
int y = 0;
y <
ny;
y++) {
2541 for (
int x = 0;
x <
nx;
x++, c++) {
2542 float y1 =
y - half_ny;
2543 float x1 =
x - half_nx;
2544 float r = (float)hypot(x1, y1);
2546 if (r >= rmin && r <= rmax) {
2548 if (x1 != 0 || y1 != 0) {
2556 int i = (int)(floor(a));
2560 vd[0] += data[c] * (1.0f - a);
2561 yc[0] += (1.0f - a);
2563 else if (i == n - 1) {
2564 vd[n - 1] += data[c] * a;
2567 else if (i > 0 && i < (n - 1)) {
2568 vd[i] += data[c] * (1.0f - a);
2569 yc[i] += (1.0f - a);
2570 vd[i + 1] += data[c] * a;
2579 for (
int i = 0; i < n; i++) {
2580 if (vd[i]<0||yc[i]<0) printf(
"%d vd %f yc %f\n",i,vd[i],yc[i]);
2622 if (r2 <= r1 || r2 > rr) {
2626 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");
2628#ifdef EMAN2_USING_CUDA
2629 if (EMData::usecuda == 1 && isrodataongpu()){
2633 bindcudaarrayA(
true);
2634 emdata_unwrap(result->cudarwdata, r1, r2, xs, p, dx, dy, weight_radial,
nx,
ny);
2642 ret->set_size(xs, r2 - r1, 1);
2644 float *dd = ret->get_data();
2645 float pfac = (float)p/(
float)xs;
2648 for (
int x = 0;
x < xs;
x++) {
2649 float ang =
x * M_PI * pfac;
2650 float si = sin(ang);
2651 float co = cos(ang);
2653 for (
int y = 0;
y < r2 - r1;
y++) {
2654 float ypr1 = (float)
y + r1;
2655 float xx = ypr1 * co + nxon2 + dx;
2656 float yy = ypr1 * si + nyon2 + dy;
2659 float t = xx - (int)xx;
2660 float u = yy - (int)yy;
2662 int k = (int) xx + ((
int) yy) *
nx;
2664 if (weight_radial) val *= ypr1;
2665 dd[
x +
y * xs] = val;
2683 int n = (int)(array.size());
2685 if (n*step>2.0) printf(
"Warning, apply_radial_func takes x0 and step with respect to Nyquist (0.5)\n");
2695 for (
int j = 0; j <
ny; j++) {
2696 for (
int i = 0; i <
nx; i += 2, k += 2) {
2698 if (j<
ny/2) r = (float)hypot(i/(
float)(
nx*2), j/(
float)
ny);
2699 else r = (float)hypot(i/(
float)(
nx*2), (
ny-j)/(float)
ny);
2700 r = (r - x0) / step;
2707 l = (int) floor(r + 1);
2718 f = (array[l] * (1.0f - r) + array[l + 1] * r);
2730 else if (ndims == 3) {
2732 for (
int m = 0; m <
nz; m++) {
2734 if (m<
nz/2) mnz=m*m/(float)(
nz*
nz);
2735 else { mnz=(
nz-m)/(
float)
nz; mnz*=mnz; }
2737 for (
int j = 0; j <
ny; j++) {
2739 if (j<
ny/2) jny= j*j/(float)(
ny*
ny);
2740 else { jny=(
ny-j)/(
float)
ny; jny*=jny; }
2742 for (
int i = 0; i <
nx; i += 2, k += 2) {
2744 r = (r - x0) / step;
2751 l = (int) floor(r + 1);
2761 f = (array[l] * (1.0f - r) + array[l + 1] * r);
2785 vector<double>ret(n);
2786 vector<double>norm(n);
2787 vector<double>count(n);
2801 for (i=0; i<n; i++) ret[i]=norm[i]=count[i]=0.0;
2804 for (i=0; i<n; i++) ret[i]=1.0e27;
2807 for (i=0; i<n; i++) ret[i]=-1.0e27;
2815 for (
y=i=0;
y<
ny;
y++) {
2816 for (
x=0;
x<
nx;
x+=step,i+=step) {
2820 if (
x==0 &&
y>
ny/2)
continue;
2824 if (f<0 || f>=n)
continue;
2827 if (isri) v=(float)(hypot(data[i],data[i+1]));
2831 if (isinten) v=data[i];
2832 else if (isri) v=data[i]*data[i]+data[i+1]*data[i+1];
2833 else v=data[i]*data[i];
2836 if (isri) v=(float)(hypot(data[i],data[i+1]));
2838 if (v<ret[f]) ret[f]=v;
2841 if (isri) v=(float)(hypot(data[i],data[i+1]));
2843 if (v>ret[f]) ret[f]=v;
2846 if (isinten) v=data[i];
2847 else if (isri) v=data[i]*data[i]+data[i+1]*data[i+1];
2848 else v=data[i]*data[i];
2860 if (f<0 || f>=n)
continue;
2870 if (data[i]<ret[f]) ret[f]=data[i];
2873 if (data[i]>ret[f]) ret[f]=data[i];
2877 norm[f]+=data[i]*data[i];
2883 if (inten<2||inten==5) {
2899 for (z=i=0; z<
nz; ++z) {
2900 for (
y=0;
y<
ny; ++
y) {
2901 for (
x=0;
x<
nx;
x+=step,i+=step) {
2905 if (
x==0 && z>
nz/2)
continue;
2906 if (
x==0 && z==
nz/2 &&
y>
ny/2)
continue;
2910 if (f<0 || f>=n)
continue;
2913 if (isri) v=(float)(hypot(data[i],data[i+1]));
2917 if (isinten) v=data[i];
2918 else if (isri) v=data[i]*data[i]+data[i+1]*data[i+1];
2919 else v=data[i]*data[i];
2922 if (isri) v=(float)(hypot(data[i],data[i+1]));
2924 if (v<ret[f]) ret[f]=v;
2927 if (isri) v=(float)(hypot(data[i],data[i+1]));
2929 if (v>ret[f]) ret[f]=v;
2932 if (isinten) v=data[i];
2933 else if (isri) v=data[i]*data[i]+data[i+1]*data[i+1];
2934 else v=data[i]*data[i];
2947 if (f<0 || f>=n)
continue;
2957 if (data[i]<ret[f]) ret[f]=data[i];
2960 if (data[i]>ret[f]) ret[f]=data[i];
2964 norm[f]+=data[i]*data[i];
2970 if (inten<2||inten==5) {
2988 if (inten<2||inten==5) {
2989 for (i=0; i<n; i++) ret[i]/=(norm[i]==0?1.0f:norm[i]);
2991 else if (inten==4) {
2992 for (i=0; i<n; i++) {
2996 if (norm[i]<=ret[i]) ret[i]=0.0;
3003 return vector<float>(ret.begin(),ret.end());
3011 LOGERR(
"2D images only.");
3019 vector<double>ret(n*nwedge);
3020 vector<double>norm(n*nwedge);
3025 float astep=(float)(M_PI*2.0/nwedge);
3028 for (i=0; i<n*nwedge; i++) ret[i]=norm[i]=0.0;
3031 for (
y=i=0;
y<
ny;
y++) {
3032 for (
x=0;
x<
nx;
x+=step,i+=step) {
3036 r=(float)(hypot(
x/2.0,
y<
ny/2?
y:
ny-
y));
3037 a=atan2(
float(
y<
ny/2?
y:
y-
ny),
x/2.0f);
3039 if (isri) v=(float)(hypot(data[i],data[i+1]));
3042 if (isinten) v=data[i];
3043 else if (isri) v=data[i]*data[i]+data[i+1]*data[i+1];
3044 else v=data[i]*data[i];
3046 bin=n*int(floor((a+M_PI/2.0f+offset)/astep));
3049 r=(float)(hypot(
x-
nx/2,
y-
ny/2));
3050 a=atan2(
float(
y-
ny/2),
float(
x-
nx/2));
3051 if (inten) v=data[i]*data[i];
3053 bin=n*int(floor((a+M_PI+offset)/astep));
3055 if (bin>=nwedge*n) bin-=nwedge*n;
3056 if (bin<0) bin+=nwedge*n;
3062 ret[f+bin]+=v*(1.0f-r);
3063 norm[f+bin]+=(1.0f-r);
3072 for (i=0; i<n*nwedge; i++) ret[i]/=norm[i]?norm[i]:1.0f;
3075 return vector<float>(ret.begin(),ret.end());
3083 int nxhalf = nxreal/2;
3084 for (
int iz = 0; iz <
nz; iz++)
3085 for (
int iy = 0; iy <
ny; iy++)
3086 for (
int ix = 0; ix <= nxhalf; ix++)
3100 if (
rdata==0)
return;
3103 float max = -FLT_MAX;
3107 double square_sum = 0;
3116 size_t size = (size_t)
nx*
ny*
nz;
3118 for (
size_t i = 0; i < size; i += step) {
3123 square_sum += v * (double)(v);
3124 if (v != 0) n_nonzero++;
3127 size_t n = size / step;
3128 double mean = sum / n;
3129 double var = (square_sum - sum*sum / n) / (n-1);
3130 double sigma = var >= 0.0 ?
std::sqrt(var) : 0.0;
3132 double varn = (square_sum - sum*sum / n_nonzero) / (n_nonzero-1);
3133 double sigma_nonzero = varn >= 0.0 ?
std::sqrt(varn) : 0.0;
3134 double mean_nonzero = sum / n_nonzero;
3140 attr_dict[
"square_sum"] = (float)(square_sum);
3141 attr_dict[
"mean_nonzero"] = (float)(mean_nonzero);
3142 attr_dict[
"sigma_nonzero"] = (float)(sigma_nonzero);
3146 flags &= ~EMDATA_NEEDUPD;
3171 if (that.get_xsize() !=
nx || that.get_ysize() !=
ny || that.get_zsize() !=
nz )
return false;
3173 const float* d1 = that.get_const_data();
3176 for(
size_t i =0; i <
get_size(); ++i,++d1,++d2) {
3177 if ((*d1) != (*d2))
return false;
3294void EMData::calc_rcf(
EMData * with, vector < float >&sum_array)
3298 int array_size = sum_array.size();
3299 float da = 2 * M_PI / array_size;
3300 float *dat =
new float[array_size + 2];
3301 float *dat2 =
new float[array_size + 2];
3302 int nx2 =
nx * 9 / 20;
3305 if (fabs(translation[0]) < fabs(translation[1])) {
3306 lim = fabs(translation[1]);
3309 lim = fabs(translation[0]);
3312 nx2 -= (int)(floor(lim));
3314 for (
int i = 0; i < array_size; i++) {
3319 float with_sigma = with->get_attr_dict().get(
"sigma");
3321 vector<float> vdata, vdata2;
3322 for (
int i = 8; i < nx2; i += 6) {
3324 vdata2 = with->
calc_az_dist(array_size, 0, da, i, i + 6);
3325 Assert(vdata.size() <= array_size + 2);
3326 Assert(cdata2.size() <= array_size + 2);
3327 std::copy(vdata.begin(), vdata.end(), dat);
3328 std::copy(vdata2.begin(), vdata2.end(), dat2);
3330 EMfft::real_to_complex_1d(dat, dat, array_size);
3331 EMfft::real_to_complex_1d(dat2, dat2, array_size);
3333 for (
int j = 0; j < array_size + 2; j += 2) {
3334 float max = dat[j] * dat2[j] + dat[j + 1] * dat2[j + 1];
3335 float max2 = dat[j + 1] * dat2[j] - dat2[j + 1] * dat[j];
3340 EMfft::complex_to_real_1d(dat, dat, array_size);
3341 float norm = array_size * array_size * (4.0f * sigma) * (4.0f * with_sigma);
3343 for (
int j = 0; j < array_size; j++) {
3344 sum_array[j] += dat[j] * (float) i / norm;
3385 float *src = obj->get_data();
3386 size_t size = (size_t)
nx *
ny *
nz;
3387 for (
size_t j = 0; j < size; j += 2) {
3388 dest[j] = (float) hypot(src[j], dest[j]);
3406 if (second_img->get_xsize() !=
nx ||
ny != 1) {
3410 if (y_index > second_img->get_ysize() || y_index < 0) {
3416 float *d2 = second_img->get_data() + second_img->get_xsize() * y_index;
3418 for (
int i = 0; i <
nx; i++) {
3430 bool maskflag =
false;
3433 mask->process_inplace(
"testimage.circlesphere");
3439 int mnx = mask->get_xsize();
int mny = mask->get_ysize();
int mnz = mask->get_zsize();
3441 if ( mnx >
nx || mny >
ny || mnz >
nz)
3442 throw ImageDimensionException(
"Can not calculate variance map using an image that is larger than this image");
3445 for(
size_t i = 0; i < mask->get_size(); ++i){
3446 if (mask->get_value_at(i) != 0){
3450 float normfac = 1.0f/(float)P;
3454 int nxc =
nx+mnx;
int nyc =
ny+mny;
int nzc =
nz+mnz;
3457 if (
ny == 1) r =
Region((mnx-nxc)/2,nxc);
3458 else if (
nz == 1) r =
Region((mnx-nxc)/2, (mny-nyc)/2,nxc,nyc);
3459 else r =
Region((mnx-nxc)/2, (mny-nyc)/2,(mnz-nzc)/2,nxc,nyc,nzc);
3469 else if (
nz == 1) r2 =
Region((
nx-nxc)/2, (
ny-nyc)/2,nxc,nyc);
3470 else r2 =
Region((
nx-nxc)/2, (
ny-nyc)/2,(
nz-nzc)/2,nxc,nyc,nzc);
3473 EMData* tmp = squared->copy();
3476 squared->process_inplace(
"math.pow",pow);
3478 squared->mult(normfac);
3482 m->process_inplace(
"math.pow",pow);
3483 delete tmp; tmp = 0;
3486 s->process_inplace(
"math.sqrt");
3498 if (
ny == 1) r =
Region((nxc-mnx)/2,mnx);
3499 else if (
nz == 1) r =
Region((nxc-mnx)/2, (nyc-mny)/2,mnx,mny);
3500 else r =
Region((nxc-mnx)/2, (nyc-mny)/2,(nzc-mnz)/2,mnx,mny,mnz);
3507 s->process_inplace(
"xform.phaseorigin.tocenter");
3525 int mnx = with->get_xsize();
int mny = with->get_ysize();
int mnz = with->get_zsize();
3526 int nxc =
nx+mnx;
int nyc =
ny+mny;
int nzc =
nz+mnz;
3530 ones->process_inplace(
"testimage.circlesphere");
3533 EMData* with_resized = with->copy();
3534 with_resized->process_inplace(
"normalize");
3535 with_resized->mult(*ones);
3540 if (
ny == 1) r1 =
Region((mnx-nxc)/2,nxc);
3541 else if (
nz == 1) r1 =
Region((mnx-nxc)/2, (mny-nyc)/2,nxc,nyc);
3542 else r1 =
Region((mnx-nxc)/2, (mny-nyc)/2,(mnz-nzc)/2,nxc,nyc,nzc);
3547 else if (
nz == 1) r2 =
Region((
nx-nxc)/2, (
ny-nyc)/2,nxc,nyc);
3548 else r2 =
Region((
nx-nxc)/2, (
ny-nyc)/2,(
nz-nzc)/2,nxc,nyc,nzc);
3553 corr->process_inplace(
"xform.phaseorigin.tocenter");
3562 delete with_resized;
delete ones;
delete this_copy;
delete s;
3573 LOGERR(
"FFT returns NULL image");
3582 cf = with->do_fft();
3586 LOGERR(
"FFT returns NULL image");
3596 LOGERR(
"images not same size");
3600 float *rdata1 = f1->get_data();
3601 float *rdata2 = cf->get_data();
3602 size_t cf_size = (size_t)cf->get_xsize() * cf->get_ysize() * cf->get_zsize();
3606 for (
size_t i = 0; i < cf_size; i += 2) {
3607 re = rdata1[i] * rdata2[i] - rdata1[i + 1] * rdata2[i + 1];
3608 im = rdata1[i + 1] * rdata2[i] + rdata1[i] * rdata2[i + 1];
3613 EMData *f2 = cf->do_ift();
3633 int mode,
int steps,
bool horizontal)
3637 if (!image1 || !image2) {
3641 if (mode < 0 || mode > 2) {
3645 if (!image1->is_complex()) {
3646 image1 = image1->do_fft();
3648 if (!image2->is_complex()) {
3649 image2 = image2->do_fft();
3659 int image2_nx = image2->get_xsize();
3660 int image2_ny = image2->get_ysize();
3662 int rmax = image2_ny / 4 - 1;
3663 int array_size = steps * rmax * 2;
3664 float *im1 =
new float[array_size];
3665 float *im2 =
new float[array_size];
3666 for (
int i = 0; i < array_size; i++) {
3673 float *image1_data = image1->get_data();
3674 float *image2_data = image2->get_data();
3676 float da = M_PI / steps;
3677 float a = -M_PI / 2.0f + da / 2.0f;
3680 for (
int i = 0; i < steps * 2; i += 2, a += da) {
3686 for (
float r = 3.0f; r < rmax - 3.0f; j += 2, r += 1.0f) {
3687 float x = r * cos(a);
3688 float y = r * sin(a);
3693 LOGERR(
"CCL ERROR %d, %f !\n", i, -
x);
3696 int k = (int) (floor(
x) * 2 + floor(
y + image2_ny / 2) * image2_nx);
3698 float x2 =
x - floor(
x);
3699 float y2 =
y - floor(
y);
3703 image1_data[k + image2_nx],
3704 image1_data[k + 2 + image2_nx], x2, y2);
3708 image2_data[k + image2_nx],
3709 image2_data[k + 2 + image2_nx], x2, y2);
3715 image1_data[k + image2_nx],
3716 image1_data[k + 2 + image2_nx], x2, y2);
3720 image2_data[k + image2_nx],
3721 image2_data[k + 2 + image2_nx], x2, y2);
3732 for (
float r = 1; r < rmax; r += 1.0f) {
3735 im1[i3 + 1] /= sqrt_s1;
3737 im2[i3 + 1] /= sqrt_s2;
3745 for (
int m1 = 0; m1 < 2; m1++) {
3746 for (
int m2 = 0; m2 < 2; m2++) {
3748 if (m1 == 0 && m2 == 0) {
3749 for (
int i = 0; i < steps; i++) {
3750 int i2 = i * rmax * 2;
3751 for (
int j = 0; j < steps; j++) {
3752 int l = i + j * steps * 2;
3753 int j2 = j * rmax * 2;
3755 for (
int k = 0; k < jmax; k++) {
3756 data[l] += im1[i2 + k] * im2[j2 + k];
3762 int steps2 = steps * m2 + steps * steps * 2 * m1;
3764 for (
int i = 0; i < steps; i++) {
3765 int i2 = i * rmax * 2;
3766 for (
int j = 0; j < steps; j++) {
3767 int j2 = j * rmax * 2;
3768 int l = i + j * steps * 2 + steps2;
3771 for (
int k = 0; k < jmax; k += 2) {
3774 data[l] += im1[i2] * im2[j2];
3775 data[l] += -im1[i2 + 1] * im2[j2 + 1];
3785 for (
int m1 = 0; m1 < 2; m1++) {
3786 for (
int m2 = 0; m2 < 2; m2++) {
3787 int steps2 = steps * m2 + steps * steps * 2 * m1;
3793 for (
int i = 0; i < steps; i++) {
3794 int i2 = i * rmax * 2;
3796 for (
int j = 0; j < steps; j++) {
3797 int j2 = j * rmax * 2;
3799 int l = i + j * steps * 2 + steps2;
3803 for (
int k = 0; k < jmax; k += 2) {
3807 float a1 = (float) hypot(im1[i2], im1[i2 + 1]);
3808 float p1 = atan2(im1[i2 + 1], im1[i2]);
3809 float p2 = atan2(im2[j2 + 1], im2[j2]);
3815 data[l] /= (float)(a * M_PI / 180.0f);
3823 for (
int m1 = 0; m1 < 2; m1++) {
3824 for (
int m2 = 0; m2 < 2; m2++) {
3825 int steps2 = steps * m2 + steps * steps * 2 * m1;
3827 for (
int i = 0; i < steps; i++) {
3828 int i2 = i * rmax * 2;
3830 for (
int j = 0; j < steps; j++) {
3831 int j2 = j * rmax * 2;
3832 int l = i + j * steps * 2 + steps2;
3835 for (
int k = 0; k < jmax; k += 2) {
3838 data[l] += (float) (hypot(im1[i2], im1[i2 + 1]) * hypot(im2[j2], im2[j2 + 1]));
3851 float *tmp_array =
new float[
ny];
3852 for (
int i = 1; i <
nx; i++) {
3853 for (
int j = 0; j <
ny; j++) {
3856 for (
int j = 0; j <
ny; j++) {
3899 int steps,
bool horiz)
3903 if (!image1 || !image2) {
3911 int steps2 = steps * 2;
3912 int image_ny = image1->get_ysize();
3913 EMData *image1_copy = image1->copy();
3914 EMData *image2_copy = image2->copy();
3916 float *im1 =
new float[steps2 * image_ny];
3917 float *im2 =
new float[steps2 * image_ny];
3920 float *ims[] = { im1, im2 };
3922 for (
int m = 0; m < 2; m++) {
3924 float a = M_PI / steps2;
3926 for (
int i = 0; i < steps2; i++) {
3928 float *data =
images[i]->get_data();
3930 for (
int j = 0; j < image_ny; j++) {
3932 for (
int k = 0; k < image_ny; k++) {
3933 sum += data[j * image_ny + k];
3935 im[i * image_ny + j] = sum;
3940 for (
int j = 0; j < image_ny; j++) {
3941 int l = i * image_ny + j;
3943 sum2 += im[l] * im[l];
3946 float mean = sum1 / image_ny;
3947 float sigma =
std::sqrt(sum2 / image_ny - sum1 * sum1);
3949 for (
int j = 0; j < image_ny; j++) {
3950 int l = i * image_ny + j;
3951 im[l] = (im[l] - mean) / sigma;
3963 for (
int i = 0; i < steps2; i++) {
3964 for (
int j = 0, l = i; j < steps2; j++, l++) {
3970 for (
int k = 0; k < image_ny; k++) {
3971 sum += im1[i * image_ny + k] * im2[l * image_ny + k];
3973 data1[i + j * steps2] = sum;
3978 for (
int i = 0; i < steps2; i++) {
3979 for (
int j = 0; j < steps2; j++) {
3981 for (
int k = 0; k < image_ny; k++) {
3982 sum += im1[i * image_ny + k] * im2[j * image_ny + k];
3984 data1[i + j * steps2] = sum;
4031 float *sdata = map->get_data();
4034 int map_nx = map->get_xsize();
4035 int map_ny = map->get_ysize();
4036 int map_nz = map->get_zsize();
4037 int map_nxy = map_nx * map_ny;
4040 if (
ny % 2 == 1 ) ymax += 1;
4042 if (
nx % 2 == 1 ) xmax += 1;
4043 for (
int y = -
ny/2;
y < ymax;
y++) {
4044 for (
int x = -
nx/2;
x < xmax;
x++) {
4057 float xx = soln[0]+map_nx/2;
4058 float yy = soln[1]+map_ny/2;
4059 float zz = soln[2]+map_nz/2;
4063 float t = xx - floor(xx);
4064 float u = yy - floor(yy);
4065 float v = zz - floor(zz);
4067 if (xx < 0 || yy < 0 || zz < 0 ) {
4072 if ( xx > map_nx - 1 || yy > map_ny - 1 || zz > map_nz - 1) {
4079 if (xx < (map_nx - 1) && yy < (map_ny - 1) && zz < (map_nz - 1)) {
4081 sdata[k + 1], sdata[k + map_nx],sdata[k + map_nx + 1],
4082 sdata[k + map_nxy], sdata[k + map_nxy + 1], sdata[k + map_nx + map_nxy],
4083 sdata[k + map_nx + map_nxy + 1],t, u, v);
4085 else if ( xx == (map_nx - 1) && yy == (map_ny - 1) && zz == (map_nz - 1) ) {
4086 ddata[l] += sdata[k];
4088 else if ( xx == (map_nx - 1) && yy == (map_ny - 1) ) {
4091 else if ( xx == (map_nx - 1) && zz == (map_nz - 1) ) {
4094 else if ( yy == (map_ny - 1) && zz == (map_nz - 1) ) {
4097 else if ( xx == (map_nx - 1) ) {
4100 else if ( yy == (map_ny - 1) ) {
4103 else if ( zz == (map_nz - 1) ) {
4120 if ( xx > map_nx - 1 || yy > map_ny - 1 || zz > map_nz - 1) {
4125 ddata[l] = sdata[k];
4139 int rmax = (int)(rmax_f+0.5f);
4142 float maxmap=0.0f, minmap=0.0f;
4143 float temp=0.0f, diff_den=0.0f, norm=0.0f;
4144 float cut_off_va =0.0f;
4149 for (i=0;i<nvox;i++){
4150 if(d[i]>maxmap) maxmap=d[i];
4151 if(d[i]<minmap) minmap=d[i];
4153 diff_den = maxmap-minmap;
4154 for(i=0;i<nvox;i++) {
4155 temp = (d[i]-minmap)/diff_den;
4156 if(cut_off_va != 0.0) {
4157 if(temp < cut_off_va)
4160 d[i] = temp-cut_off_va;
4165 for(i=0;i<nvox;i++) {
4169 for(i=0;i<nvox;i++) d[i] /= norm;
4172 xs = (int) floor(do360*M_PI*
get_ysize()/4);
4178 if (r2<r1) r2=(int)maxext;
4181 ret->set_size(xs,r2+1,1);
4185 for (
int i=0; i<xs; i++) {
4186 float si=sin(i*M_PI*2/xs);
4187 float co=cos(i*M_PI*2/xs);
4188 for (
int r=0; r<=maxext; r++) {
4196 int x1=(int)floor(
x);
4197 int y1=(int)floor(
y);
4203 float f22= d[(x1+1)+(y1+1)*
get_xsize()];
4204 dd[i+r*xs] = (1-t)*(1-u)*f11+t*(1-u)*f21+t*u*f22+(1-t)*u*f12;
4216 imagepcsfft->set_size((size+2), (
int)MAXR+1, 1);
4217 float *d=imagepcsfft->get_data();
4220 data_in->set_size(size,1,1);
4221 float *in=data_in->get_data();
4223 for(
int row=0; row<=(int)MAXR; ++row){
4224 if(row<=(
int)rmax) {
4225 for(
int i=0; i<size;++i) in[i] = pcs[i+row*size];
4226 data_in->set_complex(
false);
4227 data_in->do_fft_inplace();
4228 for(
int j=0;j<size+2;j++) d[j+row*(size+2)]=in[j];
4230 else for(
int j=0;j<size+2;j++) d[j+row*(size+2)]=0.0;
4232 imagepcsfft->update();
4254 float *ddata = map->get_data();
4257 int map_nx = map->get_xsize();
4258 int map_ny = map->get_ysize();
4259 int map_nz = map->get_zsize();
4260 int map_nxy = map_nx * map_ny;
4261 float map_nz_round_limit = (float) map_nz-0.5f;
4262 float map_ny_round_limit = (float) map_ny-0.5f;
4263 float map_nx_round_limit = (float) map_nx-0.5f;
4269 if (
ny % 2 == 1 ) ymax += 1;
4271 if (
nx % 2 == 1 ) xmax += 1;
4272 for (
int y = -
ny/2;
y < ymax;
y++) {
4273 for (
int x = -
nx/2;
x < xmax;
x++) {
4284 float xx = soln[0]+map_nx/2;
4285 float yy = soln[1]+map_ny/2;
4286 float zz = soln[2]+map_nz/2;
4289 if (xx < -0.5 || yy < -0.5 || zz < -0.5 || xx >= map_nx_round_limit || yy >= map_ny_round_limit || zz >= map_nz_round_limit)
continue;
4293 ddata[k] = sdata[l];
4307 int box_nx = box->get_xsize();
4308 int box_ny = box->get_ysize();
4309 int box_nxy = box_nx*box_ny;
4310 float* bdata = box->get_data();
4319 float xb = cs_matrix[0]*
x +
y*cs_matrix[4] + z*cs_matrix[8] + cs_matrix[3];
4320 float yb = cs_matrix[1]*
x +
y*cs_matrix[5] + z*cs_matrix[9] + cs_matrix[7];
4321 float zb = cs_matrix[2]*
x +
y*cs_matrix[6] + z*cs_matrix[10] + cs_matrix[11];
4330 if ( xb >
nx - 1 || yb >
ny - 1 || zb >
nz - 1) {
4334 if (xb < 0 || yb < 0 || zb < 0){
4339 if (xb < (
nx - 1) && yb < (
ny - 1) && zb < (
nz - 1)) {
4340 bdata[l] =
Util::trilinear_interpolate(ddata[k], ddata[k + 1], ddata[k +
nx],ddata[k +
nx + 1], ddata[k +
nxy], ddata[k +
nxy + 1], ddata[k +
nx +
nxy], ddata[k +
nx +
nxy + 1],t, u, v);
4351 string image_endian =
"ImageEndian";
4352 string host_endian =
"HostEndian";
4372 test->set_size(
nx,
ny,
nz);
4374 float ratio = tan((90.0f-wedgeangle)*M_PI/180.0f);
4376 int offset_i = 2*int(start*
nz/2);
4377 int offset_f = int(stop*
nz/2);
4381 double square_sum = 0.0;
4382 for (
int j = 0; j < offset_f; j++){
4383 for (
int k = offset_i; k < offset_f; k++) {
4384 for (
int i = 0; i <
nx; i+=2) {
4385 if (i <
int(k*ratio)) {
4386 test->set_value_at(i, j, k, 1.0);
4389 square_sum += v * (double)(v);
4396 float mean = sum / step;
4397 double var = (square_sum - sum*mean) / (step-1);
4398 float sigma = var >= 0.0 ? (float)
std::sqrt(var) : 0.0;
4400 cout <<
"Mean sqr wedge amp " << mean <<
" Sigma Squ wedge Amp " << sigma << endl;
4402 set_attr(
"spt_wedge_sigma", sigma);
static bool is_host_big_endian()
Dict is a dictionary to store <string, EMObject> pair.
bool has_key(const string &key) const
Ask the Dictionary if it as a particular key.
EMData stores an image's data and defines core image processing routines.
EMData * get_top_half() const
Get the top half of this 3D image.
void scale(float scale_factor)
scale the image by a factor.
void translate(float dx, float dy, float dz)
Translate this image.
EMData * calc_fast_sigma_image(EMData *mask)
Calculates the local standard deviation (sigma) image using the given mask image.
EMData * compute_missingwedge(float wedgeangle, float start=0.05, float stop=0.5)
Find the mean and variance of voxels in the missing wedge.
EMData * rot_fp
This is a cached rotational footprint, can save much time.
void cconj()
Replace the image its complex conjugate.
void rotate(const Transform &t)
Rotate this image.
EMData * calc_flcf(EMData *with)
Calculates the cross correlation with local normalization between 2 images.
void save_byteorder_to_dict(ImageIO *imageio)
float max_3D_pixel_error(const Transform &t1, const Transform &t2, float r)
EMData()
For all image I/O.
void uncut_slice(EMData *const map, const Transform &tr) const
Opposite of the cut_slice().
EMData * window_center(int l)
Window the center of an image.
float * supp
supplementary data array
EMData * make_rotational_footprint_cmc(bool unwrap=true)
EMData * calc_mutual_correlation(EMData *with, bool tocorner=false, EMData *filter=0)
Calculates mutual correlation function (MCF) between 2 images.
void zero_corner_circulant(const int radius=0)
Zero the pixels in the bottom left corner of the image If radius is greater than 1,...
double dot_rotate_translate(EMData *with, float dx, float dy, float da, const bool mirror=false)
dot product of 2 images.
EMData * little_big_dot(EMData *little_img, bool do_sigma=false)
This does a normalized dot product of a little image with a big image using real-space methods.
float * rdata
image real data
EMData * calc_ccf_masked(EMData *with, EMData *withsq=0, EMData *mask=0)
Calculate cross correlation between this and with where this is assumed to have had a mask applied to...
Dict attr_dict
to store all image header info
void rotate_x(int dx)
This performs a translation of each line along x with wraparound.
EMData * get_clip(const Region &area, const float fill=0) const
Get an inclusive clip.
EMData * make_rotational_footprint_e1(bool unwrap=true)
int flags
CTF data All CTF data become attribute ctf(vector<float>) in attr_dict –Grant Tang.
void apply_radial_func(float x0, float dx, vector< float >array, bool interp=true)
multiplies by a radial function in fourier space.
vector< float > calc_radial_dist(int n, float x0, float dx, int inten)
calculates radial distribution.
vector< float > calc_hist(int hist_size=128, float hist_min=0, float hist_max=0, const float &brt=0.0f, const float &cont=1.0f)
Calculates the histogram of 'this' image.
void transform(const Transform &t)
Rotate then translate the image.
void cut_slice(const EMData *const map, const Transform &tr, bool interpolate=true)
cut a 2D slice out of a real 3D map.
void add_incoherent(EMData *obj)
Adds 'obj' to 'this' incoherently.
EMData * get_rotated_clip(const Transform &xform, const IntSize &size, float scale=1.0)
This will extract an arbitrarily oriented and sized region from the image.
EMData * do_radon()
Radon Transform: an algorithm that transforms an original image into a series of equiangular projecti...
EMData * make_footprint(int type=0)
Makes a 'footprint' for the current image.
EMData * oneDfftPolar(int size, float rmax, float MAXR)
Vec3f all_translation
translation from the original location
void set_xyz_origin(float origin_x, float origin_y, float origin_z)
Set the x,y,z origin of the image.
EMData * convolute(EMData *with)
Convolutes 2 data sets.
vector< float > calc_az_dist(int n, float a0, float da, float rmin, float rmax)
Caculates the azimuthal distributions.
float * setup4slice(bool redo=true)
Set up for fftslice operations.
EMData * unwrap_largerR(int r1, int r2, int xs, float rmax_f)
EMData * extract_box(const Transform &cs, const Region &r)
Extract a box from EMData in an abritrary orrientation.
void rotate_translate(const Transform &t)
Apply a transformation to the image.
void clip_inplace(const Region &area, const float &fill_value=0)
Clip the image inplace - clipping region must be smaller than the current region internally memory is...
float calc_dist(EMData *second_img, int y_index=0) const
Calculates the distance between 2 vectors.
int xoff
array index offsets
static void em_memset(void *data, const int value, const size_t size)
static void em_memcpy(void *dst, const void *const src, const size_t size)
static bool is_same_size(const EMData *image1, const EMData *image2)
Check whether two EMData images are of the same size.
static void * em_calloc(const size_t nmemb, const size_t size)
static void em_free(void *data)
static void * em_malloc(const size_t size)
ImageIO classes are designed for reading/writing various electron micrography image formats,...
virtual bool is_image_big_endian()=0
Is this image in big endian or not.
IntPoint defines an integer-coordinate point in a 1D/2D/3D space.
IntSize is used to describe a 1D, 2D or 3D rectangular size in integers.
Region defines a 2D or 3D rectangular region specified by its origin coordinates and all edges' sizes...
float get_width() const
get the width
float y_origin() const
get the y element of the origin
float x_origin() const
get the x element of the origin
float get_depth() const
get the depth
float z_origin() const
get the z element of the origin
float get_height() const
get the height
static float linear_interpolate(float p1, float p2, float t)
Calculate linear interpolation.
static float angle_sub_2pi(float x, float y)
Calculate the difference of 2 angles and makes the equivalent result to be less than Pi.
static int square(int n)
Calculate a number's square.
static int fast_floor(float x)
A fast way to calculate a floor, which is largest integral value not greater than argument.
static float hypot3(int x, int y, int z)
Euclidean distance function in 3D: f(x,y,z) = sqrt(x*x + y*y + z*z);.
static int round(float x)
Get ceiling round of a float number x.
static int calc_best_fft_size(int low)
Search the best FFT size with good primes.
static float trilinear_interpolate(float p1, float p2, float p3, float p4, float p5, float p6, float p7, float p8, float t, float u, float v)
Calculate trilinear interpolation.
static int get_min(int f1, int f2)
Get the minimum of 2 numbers.
static float bilinear_interpolate(float p1, float p2, float p3, float p4, float t, float u)
Calculate bilinear interpolation.
static float square_sum(float x, float y)
Calcuate (x*x + y*y).
static float get_max(float f1, float f2)
Get the maximum of 2 numbers.
static float hypot_fast(int x, int y)
Euclidean distance in 2D for integers computed fast using a cached lookup table.
int cuda_dd_fft_real_to_complex_nd(float *real_data, float *complex_data, int nx, int ny, int nz, int batch)
int cuda_dd_fft_complex_to_real_nd(float *complex_data, float *real_data, int nx, int ny, int nz, int batch)
void calc_ccf_cuda(float *afft, const float *bfft, const int nx, const int ny, const int nz)
void mcf_cuda(const float *data1, float *data2, const int nx, const int ny, const int nz)
void emdata_unwrap(float *data, int r1, int r2, int xs, int num_pi, int dx, int dy, int weight_radial, int nx, int ny)
float * emdata_column_sum(const float *data, const int nx, const int ny)
void mult_complex_efficient_cuda(float *data, const float *src_data, const int nx, const int ny, const int nz, const int radius)
void calc_conv_cuda(float *afft, const float *bfft, const int nx, const int ny, const int nz)
#define Assert(s)
Define Assert() function that is effective only when -DDEBUG is used.
float sget_value_at_interp(float x, float y) const
Get pixel density value at interpolation of (x,y).
EMData * copy() const
This file is a part of "emdata.h", to use functions in this file, you should "#include "emdata....
void to_zero()
Set all the pixel value = 0.
std::complex< float > & cmplx(const int ix, const int iy, const int iz)
Return reference to complex elements.
void set_value_at(Vec3i loc, float val)
set_value_at with Vec3i
bool equal(const EMData &that) const
compare the equality of two EMData object based on their pixel values
float get_value_at_wrap(int x, int y, int z) const
Get the pixel density value at coordinates (x,y,z).
EMData * sqrt() const
return square root of current image
float get_value_at(int x, int y, int z) const
Get the pixel density value at coordinates (x,y,z).
void free_memory()
Free memory associated with this EMData Called in destructor and in assignment operator.
EMData * copy_head() const
Make an image with a copy of the current image's header.
bool operator==(const EMData &that) const
void read_image(const string &filename, int img_index=0, bool header_only=false, const Region *region=0, bool is_3d=false, EMUtil::ImageType imgtype=EMUtil::IMAGE_UNKNOWN)
read an image file and stores its information to this EMData object.
EMData * process(const string &processorname, const Dict ¶ms=Dict()) const
Apply a processor with its parameters on a copy of this image, return result as a a new image.
void process_inplace(const string &processorname, const Dict ¶ms=Dict())
This file is a part of "emdata.h", to use functions in this file, you should "#include "emdata....
#define InvalidParameterException(desc)
#define ImageFormatException(desc)
#define ImageDimensionException(desc)
#define OutofRangeException(low, high, input, objname)
#define UnexpectedBehaviorException(desc)
#define NullPointerException(desc)
EMData & operator=(const EMData &that)
EMData assignment operator Performs a deep copy.
EMData * calc_ccf(EMData *with=0, fp_flag fpflag=CIRCULANT, bool center=false)
Calculate Cross-Correlation Function (CCF).
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 * calc_ccfx(EMData *const with, int y0=0, int y1=-1, bool nosum=false, bool flip=false, bool usez=false)
Calculate Cross-Correlation Function (CCF) in the x-direction and adds them up, result in 1D.
EMData * make_rotational_footprint(bool unwrap=true)
Makes a 'rotational footprint', which is an 'unwound' autocorrelation function.
void common_lines(EMData *image1, EMData *image2, int mode=0, int steps=180, bool horizontal=false)
Finds common lines between 2 complex images.
void common_lines_real(EMData *image1, EMData *image2, int steps=180, bool horizontal=false)
Finds common lines between 2 real images.
EMData * operator+(const EMData &em, float n)
EMData * rdiv(const EMData &em, float n)
double dot(const Vector3 &w, const Vector3 &v)
EMData * rsub(const EMData &em, float n)
EMData * operator-(const EMData &em, float n)
EMData * operator/(const EMData &em, float n)
EMData * operator*(const EMData &em, float n)