To compare 'image' with another image passed in through its parameters.
An optional transformation may be used to transform the 2 images.
425 if (negative) negative=-1.0;
else negative=1.0;
426#ifdef EMAN2_USING_CUDA
427 if(image->is_complex() && with->is_complex()) {
429 if (image->getcudarwdata() && with->getcudarwdata()) {
432 bool has_mask =
false;
436 if(mask!=0) {has_mask=
true;}
438 if(has_mask && !mask->getcudarwdata()){
439 mask->copy_to_cuda();
440 maskdata = mask->getcudarwdata();
443 float result =
dot_cmp_cuda(image->getcudarwdata(), with->getcudarwdata(), maskdata, image->get_xsize(), image->get_ysize(), image->get_zsize());
451 const float *
const x_data = image->get_const_data();
452 const float *
const y_data = with->get_const_data();
456 if(image->is_complex() && with->is_complex()) {
458 int nx = with->get_xsize();
459 int ny = with->get_ysize();
460 int nz = with->get_zsize();
461 nx = (nx - 2 + with->is_fftodd());
462 int lsd2 = (nx + 2 - nx%2) ;
464 int ixb = 2*((nx+1)%2);
469 for (
int iz = 0; iz <= nz-1; ++iz) {
471 for (
int iy = 0; iy <= ny-1; ++iy) {
472 for (
int ix = 2; ix <= lsd2 - 1 - ixb; ++ix) {
473 size_t ii = ix + (iy + iz * ny)* lsd2;
474 part += x_data[ii] * double(y_data[ii]);
477 for (
int iy = 1; iy <= ny/2-1 + iyb; ++iy) {
478 size_t ii = (iy + iz * ny)* lsd2;
479 part += x_data[ii] * double(y_data[ii]);
480 part += x_data[ii+1] * double(y_data[ii+1]);
483 for (
int iy = 1; iy <= ny/2-1 + iyb; ++iy) {
484 size_t ii = lsd2 - 2 + (iy + iz * ny)* lsd2;
485 part += x_data[ii] * double(y_data[ii]);
486 part += x_data[ii+1] * double(y_data[ii+1]);
491 part += x_data[0] * double(y_data[0]);
493 size_t ii = (ny/2 + iz * ny)* lsd2;
494 part += x_data[ii] * double(y_data[ii]);
497 size_t ii = lsd2 - 2 + (0 + iz * ny)* lsd2;
498 part += x_data[ii] * double(y_data[ii]);
500 int ii = lsd2 - 2 +(ny/2 + iz * ny)* lsd2;
501 part += x_data[ii] * double(y_data[ii]);
509 int ny2 = ny/2;
int nz2 = nz/2;
510 for (
int iz = 0; iz <= nz-1; ++iz) {
511 if(iz>nz2) kz=iz-nz;
else kz=iz;
512 for (
int iy = 0; iy <= ny-1; ++iy) {
513 if(iy>ny2) ky=iy-ny;
else ky=iy;
514 for (
int ix = 0; ix <= lsd2-1; ++ix) {
516 if (ix <= 1 || (ix >= lsd2-2 && nx%2 == 0) ) p = 1;
517 size_t ii = ix + (iy + iz * ny)* (
size_t)lsd2;
518 result += p * x_data[ii] * double(y_data[ii]);
523 double square_sum1 = 0., square_sum2 = 0.;
525 int ny2 = ny/2;
int nz2 = nz/2;
526 for (
int iz = 0; iz <= nz-1; ++iz) {
527 if(iz>nz2) kz=iz-nz;
else kz=iz;
528 for (
int iy = 0; iy <= ny-1; ++iy) {
529 if(iy>ny2) ky=iy-ny;
else ky=iy;
530 for (
int ix = 0; ix <= lsd2-1; ++ix) {
532 if (ix <= 1 || (ix >= lsd2-2 && nx%2 == 0) ) p = 1;
533 size_t ii = ix + (iy + iz * ny)* (
size_t)lsd2;
534 square_sum1 += p * x_data[ii] * double(x_data[ii]);
535 square_sum2 += p * y_data[ii] * double(y_data[ii]);
539 result /=
sqrt(square_sum1*square_sum2);
540 }
else result /= ((float)nx*(
float)ny*(float)nz*(
float)nx*(float)ny*(
float)nz);
543 double square_sum1 = 0., square_sum2 = 0.;
544 for (
int iz = 0; iz <= nz-1; ++iz) {
545 for (
int iy = 0; iy <= ny-1; ++iy) {
546 for (
int ix = 2; ix <= lsd2 - 1 - ixb; ++ix) {
547 size_t ii = ix + (iy + iz * ny)* lsd2;
548 square_sum1 += x_data[ii] * double(x_data[ii]);
549 square_sum2 += y_data[ii] * double(y_data[ii]);
552 for (
int iy = 1; iy <= ny/2-1 + iyb; ++iy) {
553 size_t ii = (iy + iz * ny)* lsd2;
554 square_sum1 += x_data[ii] * double(x_data[ii]);
555 square_sum1 += x_data[ii+1] * double(x_data[ii+1]);
556 square_sum2 += y_data[ii] * double(y_data[ii]);
557 square_sum2 += y_data[ii+1] * double(y_data[ii+1]);
560 for (
int iy = 1; iy <= ny/2-1 + iyb; ++iy) {
561 size_t ii = lsd2 - 2 + (iy + iz * ny)* lsd2;
562 square_sum1 += x_data[ii] * double(x_data[ii]);
563 square_sum1 += x_data[ii+1] * double(x_data[ii+1]);
564 square_sum2 += y_data[ii] * double(y_data[ii]);
565 square_sum2 += y_data[ii+1] * double(y_data[ii+1]);
570 square_sum1 += x_data[0] * double(x_data[0]);
572 square_sum2 += y_data[0] * double(y_data[0]);
574 int ii = (ny/2 + iz * ny)* lsd2;
575 square_sum1 += x_data[ii] * double(x_data[ii]);
576 square_sum2 += y_data[ii] * double(y_data[ii]);
579 int ii = lsd2 - 2 + (0 + iz * ny)* lsd2;
580 square_sum1 += x_data[ii] * double(x_data[ii]);
581 square_sum2 += y_data[ii] * double(y_data[ii]);
583 int ii = lsd2 - 2 +(ny/2 + iz * ny)* lsd2;
584 square_sum1 += x_data[ii] * double(x_data[ii]);
585 square_sum2 += y_data[ii] * double(y_data[ii]);
589 result /=
sqrt(square_sum1*square_sum2);
590 }
else result /= ((float)nx*(
float)ny*(float)nz*(
float)nx*(float)ny*(
float)nz);
596 size_t totsize = (size_t)image->get_xsize() * image->get_ysize() * image->get_zsize();
598 double square_sum1 = 0., square_sum2 = 0.;
603 const float *
const dm = mask->get_const_data();
605 for (
size_t i = 0; i < totsize; i++) {
607 square_sum1 += x_data[i]*double(x_data[i]);
608 square_sum2 += y_data[i]*double(y_data[i]);
609 result += x_data[i]*double(y_data[i]);
613 for (
size_t i = 0; i < totsize; i++) {
615 result += x_data[i]*double(y_data[i]);
622 for (
size_t i=0; i<totsize; i++) result += x_data[i]*y_data[i];
625 square_sum1 = image->get_attr(
"square_sum");
626 square_sum2 = with->get_attr(
"square_sum");
629 if (normalize) result /= (
sqrt(square_sum1*square_sum2));
else result /= n;
634 return (
float) (negative*result);
void validate_input_args(const EMData *image, const EMData *with) const
type set_default(const string &key, type val)
Default setting behavior This can be achieved using a template - d.woolford Jan 2008 (before there wa...
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.
float dot_cmp_cuda(float *data1, float *data2, const float *dm, const int &nx, const int &ny, const int &nz)
EMData * sqrt() const
return square root of current image