EMAN2
emdata_metadata.cpp
Go to the documentation of this file.
1/*
2 * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu)
3 * Copyright (c) 2000-2006 Baylor College of Medicine
4 *
5 * This software is issued under a joint BSD/GNU license. You may use the
6 * source code in this file under either license. However, note that the
7 * complete EMAN2 and SPARX software packages have some GPL dependencies,
8 * so you are responsible for compliance with the licenses of these packages
9 * if you opt to use BSD licensing. The warranty disclaimer below holds
10 * in either instance.
11 *
12 * This complete copyright notice must be included in any revised version of the
13 * source code. Additional authorship citations may be added, but existing
14 * author citations must be preserved.
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 *
30 * */
31
32#include "emdata.h"
33#include "ctf.h"
34#include "portable_fileio.h"
35#include "io/imageio.h"
36
37#include <cstring>
38#include <sstream>
39using std::stringstream;
40
41#include <iomanip>
42using std::setprecision;
43using namespace EMAN;
44
45#ifdef EMAN2_USING_CUDA
46#include "cuda/cuda_processor.h"
47#endif
48// EMAN2_USING_CUDA
49
51{
53
54// int ndim = get_ndim();
55 if (!is_complex()) {
56 LOGERR("complex image expected. Input image is real image.");
57 throw ImageFormatException("complex image expected. Input image is a real image.");
58 }
59 if (nz>1) {
60 LOGERR("2D image expected. Input image is 3D");
61 throw ImageFormatException("2D odd square complex image"
62 " expected Input image is 3D.");
63 }
64
65 int nx2 = nx/2;
66
67 EMData *dat = copy_head();
68
69 dat->set_size(nx2, ny, nz);
70 dat->to_zero();
71
72 float temp=0;
73
74 for (int j = 0; j < ny; j++) {
75 for (int i = 0; i < nx2; i++) {
76 temp = (*this)(2*i,j)*(*this)(2*i,j);
77 temp += (*this)(2*i+1,j)*(*this)(2*i+1,j);
78 (*dat)(i,j) = std::sqrt(temp);
79 }
80 }
81
82 dat->update();
83 dat->set_complex(false);
84 dat->set_ri(false);
85
87 return dat;
88}
89
90
92{
94
95 if (!is_complex()) {
96 LOGERR("complex image expected. Input image is real image.");
97 throw ImageFormatException("complex image expected. Input image is a real image.");
98 }
99
100 ri2ap();
101
102 int nx2 = nx - 2;
103 EMData *dat = copy_head();
104 dat->set_size(nx2, ny, nz);
105 dat->to_zero();
106
107 float *d = dat->get_data();
108 float *data = get_data();
109 int ndim = get_ndim();
110
111 size_t idx1, idx2, idx3;
112 if (ndim == 3) {
113 for (int k = 1; k < nz; ++k) {
114 for (int j = 1; j < ny; ++j) {
115 for (int i = 0; i < nx2/2; ++i) {
116 idx1 = (size_t)k*nx2*ny+j*nx2+nx2/2+i;
117 idx2 = (size_t)k*nx*ny+j*nx+2*i;
118 idx3 = (size_t)(nz-k)*nx2*ny+(ny-j)*nx2+nx2/2-i;
119 d[idx1] = data[idx2];
120 d[idx3] = data[idx2];
121 }
122 }
123 }
124 }
125 else if (ndim == 2) {
126 for (int j = 1; j < ny; ++j) {
127 for (int i = 0; i < nx2/2; ++i) {
128 d[j*nx2+nx2/2+i] = data[j*nx+2*i];
129 d[(ny-j)*nx2+nx2/2-i] = data[j*nx+2*i];
130 }
131 }
132 }
133
134 dat->update();
135 dat->set_complex(false);
136 if(dat->get_ysize()==1 && dat->get_zsize()==1) {
137 dat->set_complex_x(false);
138 }
139 dat->set_ri(false);
140
141 EXITFUNC;
142 return dat;
143}
144
145
147{
148 ENTERFUNC;
149
150 if (!is_complex()) {
151 LOGERR("complex image expected. Input image is real image.");
152 throw ImageFormatException("complex image expected. Input image is a real image.");
153 }
154
155 ri2ap();
156
157 int nx2 = nx - 2;
158 EMData *dat = copy_head();
159 dat->set_size(nx2, ny, nz);
160 dat->to_zero();
161
162 float *d = dat->get_data();
163 float * data = get_data();
164
165 int ndim = get_ndim();
166 size_t idx1, idx2, idx3;
167 if (ndim == 3) {
168 for (int k = 1; k < nz; ++k) {
169 for (int j = 1; j < ny; ++j) {
170 for (int i = 0; i < nx2/2; ++i) {
171 idx1 = (size_t)k*nx2*ny+j*nx2+nx2/2+i;
172 idx2 = (size_t)k*nx*ny+j*nx+2*i+1;
173 idx3 = (size_t)(nz-k)*nx2*ny+(ny-j)*nx2+nx2/2-i;
174 d[idx1] = data[idx2];
175 d[idx3] = -data[idx2];
176 }
177 }
178 }
179 }
180 else if (ndim == 2) {
181 for (int j = 1; j < ny; ++j) {
182 for (int i = 0; i < nx2/2; ++i) {
183 d[j*nx2+nx2/2+i] = data[j*nx+2*i+1];
184 d[(ny-j)*nx2+nx2/2-i] = -data[j*nx+2*i+1];
185 }
186 }
187 }
188
189 dat->update();
190 dat->set_complex(false);
191 if(dat->get_ysize()==1 && dat->get_zsize()==1) {
192 dat->set_complex_x(false);
193 }
194 dat->set_ri(false);
195
196 EXITFUNC;
197 return dat;
198}
199
200#include <sys/stat.h>
201
202void EMData::write_data(string fsp,size_t loc,const Region* area,const int file_nx, const int file_ny, const int file_nz) {
203
204 if (area) {
205 struct stat fileinfo;
206 if ( stat(fsp.c_str(),&fileinfo) != 0 ) throw UnexpectedBehaviorException("To write an image using a region the file must already exist and be the correct dimensions");
207 }
208
209
210 FILE *f = 0;
211 f=fopen(fsp.c_str(), "rb+");
212 if (!f) f=fopen(fsp.c_str(), "wb");
213 if (!f) throw FileAccessException(fsp);
214 portable_fseek(f,loc,SEEK_SET);
215 if (!area) {
216 if (fwrite(get_data(),nx*ny,nz*4,f)!=(size_t)(nz*4)) throw FileAccessException(fsp);
217 } else {
218 int fnx = nx;
219 if (file_nx != 0) fnx = file_nx;
220 int fny = ny;
221 if (file_ny != 0) fny = file_ny;
222 int fnz = nz;
223 if (file_nz != 0) fnz = file_nz;
224
226 0, 4,fnx,fny,fnz,area);
227 }
228 fclose(f);
229// printf("WROTE %s %ld %ld\n",fsp.c_str(),loc,nx*ny*nz);
230}
231
232void EMData::read_data(string fsp,size_t loc,const Region* area, const int file_nx, const int file_ny, const int file_nz) {
233 FILE *f = 0;
234 f=fopen(fsp.c_str(), "rb");
235 if (!f) throw FileAccessException(fsp);
236 int fnx = nx;
237 if (file_nx != 0) fnx = file_nx;
238 int fny = ny;
239 if (file_ny != 0) fny = file_ny;
240 int fnz = nz;
241 if (file_nz != 0) fnz = file_nz;
242
243 portable_fseek(f,loc,SEEK_SET);
245 0, 4,fnx,fny,fnz,area);
246// portable_fseek(f,loc,SEEK_SET);
247// if (fread(get_data(),nx*ny,nz*4,f)!=(size_t)(nz*4)) throw FileAccessException(fsp);
248 fclose(f);
249}
250
252{
253 ENTERFUNC;
254
255 float center = get_attr("mean");
256 float sigma = get_attr("sigma");
257 float ds = sigma / 2;
258 size_t size = (size_t)nx * ny * nz;
259 float *d = get_data();
260 float sigma1 = sigma / 20;
261 float sigma2 = sigma / 1000;
262
263 while (ds > sigma1) {
264 double sum = 0;
265 int norm = 0;
266
267 for (size_t i = 0; i < size; ++i) {
268 if (fabs(d[i] - center) < ds) {
269 sum += d[i];
270 norm++;
271 }
272 }
273 if (!norm) {
274 break;
275 }
276 float mean = (float)(sum / norm);
277 if (fabs(mean - center) < sigma2) {
278 ds *= 0.5f;
279 }
280 center = mean;
281 }
282 EXITFUNC;
283
284 return center;
285}
286
287
289{
290 ENTERFUNC;
291
292 float *d = get_data();
293 float mean = get_attr("mean");
294 float sigma = get_attr("sigma");
295
296 double sum_up = 0;
297 double sum_down = 0;
298 int nup = 0;
299 int ndown = 0;
300
301 size_t size = (size_t)nx * ny * nz;
302
303 for (size_t i = 0; i < size; ++i) {
304 if (d[i] > mean) {
305 sum_up += Util::square(d[i] - mean);
306 nup++;
307 }
308 else {
309 sum_down += Util::square(mean - d[i]);
310 ndown++;
311 }
312 }
313
314 float sigup = std::sqrt((float)sum_up / nup);
315 float sigdown = std::sqrt((float)sum_down / ndown);
316 float sig_diff = fabs(sigup - sigdown) / sigma;
317
318
319 EXITFUNC;
320 return sig_diff;
321
322}
323
324
326{
327 ENTERFUNC;
328
329 int di = 1;
330 if (is_complex() && !is_ri()) {
331 di = 2;
332 }
333
334 float min = FLT_MAX;
335 int min_x = 0;
336 int min_y = 0;
337 int min_z = 0;
338 int nxy = nx * ny;
339 float * data = get_data();
340
341 for (int j = 0; j < nz; ++j) {
342 size_t cur_z = (size_t)j * nxy;
343
344 for (int k = 0; k < ny; ++k) {
345 size_t cur_y = k * nx + cur_z;
346
347 for (int l = 0; l < nx; l += di) {
348 float t = data[l + cur_y];
349 if (t < min) {
350 min_x = l;
351 min_y = k;
352 min_z = j;
353 min = t;
354 }
355 }
356 }
357 }
358
359 return IntPoint(min_x, min_y, min_z);
360}
361
362
364{
365 ENTERFUNC;
366
367 int di = 1;
368 if (is_complex() && !is_ri()) {
369 di = 2;
370 }
371
372 float max = -FLT_MAX;
373 int max_x = 0;
374 int max_y = 0;
375 int max_z = 0;
376 int nxy = nx * ny;
377 float * data = get_data();
378
379 for (int j = 0; j < nz; ++j) {
380 size_t cur_z = (size_t)j * nxy;
381
382 for (int k = 0; k < ny; ++k) {
383 size_t cur_y = k * nx + cur_z;
384
385 for (int l = 0; l < nx; l += di) {
386 float t = data[l + cur_y];
387 if (t > max) {
388 max_x = l;
389 max_y = k;
390 max_z = j;
391 max = t;
392 }
393 }
394 }
395 }
396
397 EXITFUNC;
398 return IntPoint(max_x, max_y, max_z);
399}
400
401
402IntPoint EMData::calc_max_location_wrap(const int maxdx, const int maxdy, const int maxdz, float *value)
403{
404 int maxshiftx = maxdx, maxshifty = maxdy, maxshiftz = maxdz;
405 if (maxdx == -1) maxshiftx = get_xsize()/4;
406 if (maxdy == -1) maxshifty = get_ysize()/4;
407 if (maxdz == -1) maxshiftz = get_zsize()/4;
408
409 float max_value = -FLT_MAX;
410
411 IntPoint peak(0,0,0);
412
413#ifdef EMAN2_USING_CUDA //CUDA
414 if(EMData::usecuda == 1 && cudarwdata){
415
416 CudaPeakInfo* soln = calc_max_location_wrap_cuda(cudarwdata, nx, ny, nz, maxdx, maxdy, maxdz);
417
418 peak[0] = soln->px;
419 peak[1] = soln->py;
420 peak[2] = soln->pz;
421 free(soln);
422
423// cout << "x " << peak[0] << " y " << peak[1] << " z " << peak[2] << endl;
424 return peak;
425 }
426#endif
427 for (int k = -maxshiftz; k <= maxshiftz; k++) {
428 for (int j = -maxshifty; j <= maxshifty; j++) {
429 for (int i = -maxshiftx; i <= maxshiftx; i++) {
430
431 float value = get_value_at_wrap(i,j,k);
432
433 if (value > max_value) {
434 max_value = value;
435 peak[0] = i;
436 peak[1] = j;
437 peak[2] = k;
438 }
439 }
440 }
441 }
442 if (value) *value=max_value;
443
444 return peak;
445}
446
447vector<float> EMData::calc_max_location_wrap_intp(const int maxdx, const int maxdy, const int maxdz)
448{
449 int maxshiftx = maxdx, maxshifty = maxdy, maxshiftz = maxdz;
450 if (maxdx == -1) maxshiftx = get_xsize()/4;
451 if (maxdy == -1) maxshifty = get_ysize()/4;
452 if (maxdz == -1) maxshiftz = get_zsize()/4;
453
454 float max_value = -FLT_MAX;
455 float is3d=(get_zsize()==1?0:1);
456 maxshiftz=maxshiftz*is3d;
457
458 IntPoint peak(0,0,0);
459
460// NOT yet working......
477 for (int k = -maxshiftz; k <= maxshiftz; k++) {
478 for (int j = -maxshifty; j <= maxshifty; j++) {
479 for (int i = -maxshiftx; i <= maxshiftx; i++) {
480
481 float value = get_value_at_wrap(i,j,k);
482
483 if (value > max_value) {
484 max_value = value;
485 peak[0] = i;
486 peak[1] = j;
487 peak[2] = k;
488 }
489 }
490 }
491 }
492
493// printf("%d,%d,%d\t%f\n",peak[0], peak[1], peak[2], max_value);
494 // compute the center of mass
495 float cmx = 0.0; float cmy = 0.0f; float cmz = 0.0f;
496 float sval = 0.0f;
497 for (float x = float(peak[0])-2.0f; x <= float(peak[0])+2.0f; x++) {
498 for (float y = float(peak[1])-2.0f; y <= float(peak[1])+2.0f; y++) {
499 for (float z = float(peak[2])-is3d*2.0f; z <= float(peak[2])+is3d*2.0f; z++) {
500 //Compute center of mass
501 float val = get_value_at_wrap(x,y,z);
502
503// printf("%.2f,%.2f, %.2f\t%.2f,%.2f,%.2f\n",x, y, val, cmx, cmy, sval);
504 if (val>0){
505 cmx += x*val;
506 cmy += y*val;
507 cmz += z*val;
508 sval += val;
509 }
510 }
511 }
512 }
513 cmx /= sval;
514 cmy /= sval;
515 cmz /= sval;
516
517 vector<float> mydata;
518 mydata.push_back(cmx);
519 mydata.push_back(cmy);
520 mydata.push_back(cmz);
521 mydata.push_back(max_value);
522
569 return mydata;
570}
571
573{
574 float *data = get_data();
575
576 //float sigma = get_attr("sigma");
577 //float mean = get_attr("mean");
578 float m = 0.0;
579
580 FloatPoint com(0,0,0);
581 for (int i = 0; i < nx; ++i) {
582 for (int j = 0; j < ny; ++j) {
583 int j2 = nx * j;
584 for (int k = 0; k < nz; ++k) {
585 size_t l = i + j2 + (size_t)k * nxy;
586 if (data[l] >= threshold) { // threshold out noise (and negative density)
587 com[0] += i * data[l];
588 com[1] += j * data[l];
589 com[2] += k * data[l];
590 m += data[l];
591 }
592 }
593 }
594 }
595
596 com[0] /= m;
597 com[1] /= m;
598 com[2] /= m;
599
600 return com;
601}
602
603
605{
606 IntPoint min_location = calc_min_location();
607 size_t i = min_location[0] + min_location[1] * nx + (size_t)min_location[2] * nx * ny;
608 return i;
609}
610
611
613{
614 IntPoint max_location = calc_max_location();
615 size_t i = max_location[0] + max_location[1] * nx + (size_t)max_location[2] * nx * ny;
616 return i;
617}
618
619
620vector<Pixel> EMData::calc_highest_locations(float threshold) const
621{
622 ENTERFUNC;
623
624 vector<Pixel> result;
625
626 int di = 1;
627 if (is_complex() && !is_ri()) {
628 di = 2;
629 }
630
631 int nxy = nx * ny;
632 float * data = get_data();
633
634 for (int j = 0; j < nz; ++j) {
635 size_t cur_z = (size_t)j * nxy;
636
637 for (int k = 0; k < ny; ++k) {
638 size_t cur_y = k * nx + cur_z;
639
640 for (int l = 0; l < nx; l += di) {
641 float v =data[l + cur_y];
642 if (v > threshold) {
643 result.push_back(Pixel(l, k, j, v));
644 }
645 }
646 }
647 }
648
649 std::sort(result.begin(), result.end());
650 std::reverse(result.begin(), result.end());
651
652 EXITFUNC;
653 return result;
654}
655
657{
658 ENTERFUNC;
659
660 vector<Pixel> result;
661
662 int di = 1;
663 if (is_complex() && !is_ri()) {
664 di = 2;
665 }
666
667 // initialize with n elements
668 float * data = get_data();
669 for ( int i=0; i<n; i++) result.push_back(Pixel(0,0,0,-data[0]));
670
671 int nxy = nx * ny;
672
673 for (int j = 0; j < nz; ++j) {
674 size_t cur_z = (size_t)j * nxy;
675
676 for (int k = 0; k < ny; ++k) {
677 size_t cur_y = k * nx + cur_z;
678
679 for (int l = 0; l < nx; l += di) {
680 float v =data[l + cur_y];
681 if (v<result[n-1].value) continue;
682 for (vector<Pixel>::iterator i=result.begin(); i<result.end(); i++) {
683 if (v>(*i).value) { result.insert(i,Pixel(l, k, j, v)); result.pop_back(); break; }
684 }
685 }
686 }
687 }
688
689 EXITFUNC;
690 return result;
691}
692
693vector<Pixel> EMData::find_pixels_with_value(float val)
694{
695 ENTERFUNC;
696
697 if ( is_complex() ) throw ImageFormatException("Error - find_pixels_with_value real only");
698
699 vector<Pixel> result;
700
701 for (int k = 0; k < nz; k++) {
702 for (int j = 0; j < ny; j++) {
703 for (int i = 0; i < nx; i++) {
704 if (get_value_at(i,j,k)==val) result.push_back(Pixel(i,j,k,val));
705 }
706 }
707 }
708
709 EXITFUNC;
710 return result;
711}
712
714{
715 ENTERFUNC;
716#ifdef EMAN2_USING_CUDA
717 if(EMData::usecuda == 1 && cudarwdata){
718
719 return get_edgemean_cuda(cudarwdata, nx, ny, nz);
720
721 }
722#endif
723 int di = 0;
724 double edge_sum = 0;
725 float edge_mean = 0;
726 size_t nxy = nx * ny;
727 float * data = get_data();
728 if (nz == 1) {
729 for (int i = 0, j = (ny - 1) * nx; i < nx; ++i, ++j) {
730 edge_sum += data[i] + data[j];
731 }
732 for (size_t i = 0, j = nx - 1; i < nxy; i += nx, j += nx) {
733 edge_sum += data[i] + data[j];
734 }
735 edge_mean = (float)edge_sum / (nx * 2 + ny * 2);
736 }
737 else {
738 if (nx == ny && nx == nz * 2 - 1) {
739 for (size_t j = (nxy * (nz - 1)); j < nxy * nz; ++j, ++di) {
740 edge_sum += data[j];
741 }
742 }
743 else {
744 for (size_t i = 0, j = (nxy * (nz - 1)); i < nxy; ++i, ++j, ++di) {
745 edge_sum += data[i] + data[j];
746 }
747 }
748
749 int nxy2 = nx * (ny - 1);
750 for (int k = 1; k < nz - 1; ++k) {
751 size_t k2 = k * nxy;
752 size_t k3 = k2 + nxy2;
753 for (int i = 0; i < nx; ++i, ++di) {
754 edge_sum += data[i + k2] + data[i + k3];
755 }
756 }
757 for (int k = 1; k < nz - 1; ++k) {
758 size_t k2 = k * nxy;
759 size_t k3 = nx - 1 + k2;
760 for (int i = 1; i < ny - 1; ++i, ++di) {
761 edge_sum += data[i * nx + k2] + data[i * nx + k3];
762 }
763 }
764
765 edge_mean = (float)edge_sum / (di * 2);
766 }
767 EXITFUNC;
768
769 return edge_mean;
770}
771
772
774{
775 ENTERFUNC;
776
777 static bool busy = false;
778 static EMData *mask = 0;
779
780 while (busy);
781 busy = true;
782
783 if (!mask || !EMUtil::is_same_size(this, mask)) {
784 if (!mask) {
785 mask = new EMData();
786 }
787 mask->set_size(nx, ny, nz);
788 mask->to_one();
789
790 float radius = (float)(ny / 2 - 2);
791 mask->process_inplace("mask.sharp", Dict("inner_radius", radius - 1,
792 "outer_radius", radius + 1));
793
794 }
795 double n = 0,s=0;
796 float *d = mask->get_data();
797 float * data = get_data();
798 size_t size = (size_t)nx*ny*nz;
799 for (size_t i = 0; i < size; ++i) {
800 if (d[i]) { n+=1.0; s+=data[i]; }
801 }
802
803
804 float result = (float)(s/n);
805 busy = false;
806
807 EXITFUNC;
808 return result;
809}
810
811
812void EMData::set_ctf(Ctf * new_ctf)
813{
814 ENTERFUNC;
815
816 vector<float> vctf = new_ctf->to_vector();
817 attr_dict["ctf"] = vctf;
818
819 EXITFUNC;
820}
821
823{
824 if(attr_dict.has_key("ctf")) {
825 EMAN1Ctf * ctf = new EMAN1Ctf();
826 ctf->from_vector(attr_dict["ctf"]);
827
828 return dynamic_cast<Ctf *>(ctf);
829 }
830 else {
831 return 0;
832 }
833}
834
835#include <iostream>
836using std::cout;
837using std::endl;
838
839void EMData::set_size(int x, int y, int z, bool noalloc)
840{
841 ENTERFUNC;
842
843 if (x <= 0) {
844 throw InvalidValueException(x, "x size <= 0");
845 }
846 else if (y <= 0) {
847 throw InvalidValueException(y, "y size <= 0");
848 }
849 else if (z <= 0) {
850 throw InvalidValueException(z, "z size <= 0");
851 }
852
853#ifdef MEMDEBUG2
854 printf("EMDATA sz %4d %p (%d,%d,%d)\n",EMData::totalalloc,this,x,y,z);
855#endif
856
857
858 int old_nx = nx;
859
860 size_t size = (size_t)x*y*z*sizeof(float);
861
862 if (noalloc) {
863 nx = x;
864 ny = y;
865 nz = z;
866 nxy = nx*ny;
867 nxyz = (size_t)nx*ny*nz;
868 return;
869 }
870
871 if (rdata != 0) {
872 rdata = (float*)EMUtil::em_realloc(rdata,size);
873 } else {
874 // Just pass on this for a while....see what happens
875 rdata = (float*)EMUtil::em_malloc(size);
876 }
877// rdata = static_cast < float *>(realloc(rdata, size));
878 if ( rdata == 0 )
879 {
880 stringstream ss;
881 string gigs;
882 ss << (float) size/1000000000.0;
883 ss >> gigs;
884 string message = "Cannot allocate " + gigs + " GB - not enough memory.";
885 throw BadAllocException(message);
886 }
887
888 nx = x;
889 ny = y;
890 nz = z;
891 nxy = nx*ny;
892 nxyz = (size_t)nx*ny*nz;
893
894// once the object is resized, the CUDA need to be updated
895#ifdef EMAN2_USING_CUDA
896 if(cudarwdata) {
897 //cout << "rw free on set size" << endl;
898 rw_free();
899 rw_alloc();
900 }
901 if(cudarodata) {
902 ro_free();
903 ro_alloc();
904 }
905#endif
906// EMAN2_USING_CUDA
907
908 if (old_nx == 0) {
909 EMUtil::em_memset(get_data(),0,size);
910 }
911
912 if (supp) {
914 supp = 0;
915 }
916
917 update();
918 EXITFUNC;
919}
920
921#ifdef EMAN2_USING_CUDA
922
923void EMData::set_size_cuda(int x, int y, int z)
924{
925 ENTERFUNC;
926
927 if (x <= 0) {
928 throw InvalidValueException(x, "x size <= 0");
929 }
930 else if (y <= 0) {
931 throw InvalidValueException(y, "y size <= 0");
932 }
933 else if (z <= 0) {
934 throw InvalidValueException(z, "z size <= 0");
935 }
936
937 nx = x;
938 ny = y;
939 nz = z;
940
941 nxy = nx*ny;
942 nxyz = (size_t)nx*ny*nz;
943
944// gpu_update();
945
946 EXITFUNC;
947}
948
949#endif
950// EMAN2_USING_CUDA
951
953{
954 const int ndims = 2;
955 if (get_ndim() != ndims) {
956 throw ImageDimensionException("2D only");
957 }
958 boost::array<std::size_t,ndims> dims = {{(size_t)nx, (size_t)ny}};
959 MArray2D marray(get_data(), dims, boost::fortran_storage_order());
960 return marray;
961}
962
963
965{
966 const int ndims = 3;
967 boost::array<std::size_t,ndims> dims = {{(size_t)nx, (size_t)ny, (size_t)nz}};
968 MArray3D marray(get_data(), dims, boost::fortran_storage_order());
969 return marray;
970}
971
972
974{
975 const int ndims = 2;
976 if (get_ndim() != ndims) {
977 throw ImageDimensionException("2D only");
978 }
979 boost::array<std::size_t,ndims> dims = {{(size_t)nx/2, (size_t)ny}};
980 std::complex<float>* cdata = reinterpret_cast<std::complex<float>*>(get_data());
981 MCArray2D marray(cdata, dims, boost::fortran_storage_order());
982 return marray;
983}
984
985
987{
988 const int ndims = 3;
989 boost::array<std::size_t,ndims> dims = {{(size_t)nx/2, (size_t)ny, (size_t)nz}};
990 std::complex<float>* cdata = reinterpret_cast<std::complex<float>*>(get_data());
991 MCArray3D marray(cdata, dims, boost::fortran_storage_order());
992 return marray;
993}
994
995
996int greaterthan( const void* p1, const void* p2 )
997{
998 float* v1 = (float*) p1;
999 float* v2 = (float*) p2;
1000
1001 if ( *v1 < *v2 ) return 0;
1002 else return 1;
1003}
1004
1005
1006EMObject EMData::get_attr(const string & key) const
1007{
1008 ENTERFUNC;
1009
1010 if ((flags & EMDATA_NEEDUPD) && (key != "is_fftpad") && (key != "xform.align2d")){update_stat();} //this gives a spped up of 7.3% according to e2speedtest
1011
1012 size_t size = (size_t)nx * ny * nz;
1013 if (key == "kurtosis") {
1014 float mean = attr_dict["mean"];
1015 float sigma = attr_dict["sigma"];
1016
1017 float *data = get_data();
1018 double kurtosis_sum = 0;
1019
1020 for (size_t k = 0; k < size; ++k) {
1021 float t = (data[k] - mean) / sigma;
1022 float tt = t * t;
1023 kurtosis_sum += tt * tt;
1024 }
1025
1026 float kurtosis = (float)(kurtosis_sum / size - 3.0);
1027 return kurtosis;
1028 }
1029 else if (key == "skewness") {
1030 float mean = attr_dict["mean"];
1031 float sigma = attr_dict["sigma"];
1032
1033 float *data = get_data();
1034 double skewness_sum = 0;
1035 for (size_t k = 0; k < size; ++k) {
1036 float t = (data[k] - mean) / sigma;
1037 skewness_sum += t * t * t;
1038 }
1039 float skewness = (float)(skewness_sum / size);
1040 return skewness;
1041 }
1042 else if (key == "moment_inertia") {
1043 double moment=0;
1044 if (ny==1 && nz==1) throw ImageFormatException("Error - cannot calculate moment of inertia of 1-D image");
1045 if (nz==1) {
1046 for (int y=0; y<ny; y++) {
1047 for (int x=0; x<nx; x++) {
1048 double v=get_value_at(x,y);
1049 if (v<=0) continue;
1050 moment+=v*(double)Util::hypot2sq(x-nx/2,y-ny/2);
1051 }
1052 }
1053 }
1054 else {
1055 for (int z=0; z<nz; z++) {
1056 for (int y=0; y<ny; y++) {
1057 for (int x=0; x<nx; x++) {
1058 double v=get_value_at(x,y,z);
1059 if (v<=0) continue;
1060 moment+=v*(double)Util::hypot3sq(x-nx/2,y-ny/2,z-nz/2);
1061 }
1062 }
1063 }
1064 }
1065 return (float)moment;
1066 }
1067 else if (key == "radius_gyration") {
1068 double moment=0;
1069 double mass=0;
1070 if (ny==1 && nz==1) throw ImageFormatException("Error - cannot calculate moment of inertia of 1-D image");
1071 if (nz==1) {
1072 for (int y=0; y<ny; y++) {
1073 for (int x=0; x<nx; x++) {
1074 double v=get_value_at(x,y);
1075 if (v<=0) continue;
1076 mass+=v;
1077 moment+=v*(double)Util::hypot2sq(x-nx/2,y-ny/2);
1078 }
1079 }
1080 }
1081 else {
1082 for (int z=0; z<nz; z++) {
1083 for (int y=0; y<ny; y++) {
1084 for (int x=0; x<nx; x++) {
1085 double v=get_value_at(x,y,z);
1086 if (v<=0) continue;
1087 mass+=v;
1088 moment+=v*(double)Util::hypot3sq(x-nx/2,y-ny/2,z-nz/2);
1089 }
1090 }
1091 }
1092 }
1093 return (float)(std::sqrt(moment/mass));
1094 }
1095 else if (key == "median")
1096 {
1097 if ( is_complex() ) throw ImageFormatException("Error - can not calculate the median of a complex image");
1098 size_t n = size;
1099 float* tmp = new float[n];
1100 float* d = get_data();
1101 if (tmp == 0 ) throw BadAllocException("Error - could not create deep copy of image data");
1102// for(size_t i=0; i < n; ++i) tmp[i] = d[i]; // should just be a memcpy
1103 std::copy(d, d+n, tmp);
1104 qsort(tmp, n, sizeof(float), &greaterthan);
1105 float median;
1106 if (n%2==1) median = tmp[n/2];
1107 else median = (tmp[n/2-1]+tmp[n/2])/2.0f;
1108 delete [] tmp;
1109 return median;
1110 }
1111 else if (key == "nonzero_median")
1112 {
1113 if ( is_complex() ) throw ImageFormatException("Error - can not calculate the median of a complex image");
1114 vector<float> tmp;
1115 size_t n = size;
1116 float* d = get_data();
1117 for( size_t i = 0; i < n; ++i ) {
1118 if ( d[i] != 0 ) tmp.push_back(d[i]);
1119 }
1120 sort(tmp.begin(), tmp.end());
1121 unsigned int vsize = tmp.size();
1122 float median;
1123 if (vsize%2==1) median = tmp[vsize/2];
1124 else median = (tmp[vsize/2-1]+tmp[vsize/2])/2.0f;
1125 return median;
1126 }
1127 else if (key == "changecount") return EMObject(changecount);
1128 else if (key == "nx") {
1129 return nx;
1130 }
1131 else if (key == "ny") {
1132 return ny;
1133 }
1134 else if (key == "nz") {
1135 return nz;
1136 }
1137
1138 if(attr_dict.has_key(key)) {
1139 return attr_dict[key];
1140 }
1141 else {
1142 throw NotExistingObjectException(key, "The requested key does not exist");
1143 }
1144
1145 EXITFUNC;
1146}
1147
1148EMObject EMData::get_attr_default(const string & key, const EMObject & em_obj) const
1149{
1150 ENTERFUNC;
1151
1152 if(attr_dict.has_key(key)) {
1153 return get_attr(key);
1154 }
1155 else {
1156 return em_obj;
1157 }
1158
1159 EXITFUNC;
1160}
1161
1163{
1164 if(rdata) {
1165 update_stat();
1166 }
1167
1168 Dict tmp=Dict(attr_dict);
1169 tmp["nx"]=nx;
1170 tmp["ny"]=ny;
1171 tmp["nz"]=nz;
1172 tmp["changecount"]=changecount;
1173
1174 return tmp;
1175}
1176
1177void EMData::set_attr_dict(const Dict & new_dict)
1178{
1179 /*set nx, ny nz may resize the image*/
1180 // This wasn't supposed to 'clip' the image, but just redefine the size --steve
1181 if( new_dict.has_key("nx") || new_dict.has_key("ny") || new_dict.has_key("nz") ) {
1182 LOGWARN("Warning: Ignored setting dimension size by modifying attribute!!!");
1183 const_cast<Dict&>(new_dict).erase("nx");
1184 const_cast<Dict&>(new_dict).erase("ny");
1185 const_cast<Dict&>(new_dict).erase("nz");
1186 }
1187
1188 vector<string> new_keys = new_dict.keys();
1189 vector<string>::const_iterator it;
1190 for(it = new_keys.begin(); it!=new_keys.end(); ++it) {
1191 this->set_attr(*it, new_dict[*it]);
1192 }
1193}
1194
1195void EMData::set_attr_dict_explicit(const Dict & new_dict)
1196{
1197 attr_dict = new_dict;
1198}
1199
1200void EMData::del_attr(const string & attr_name)
1201{
1202 attr_dict.erase(attr_name);
1203}
1204
1205void EMData::del_attr_dict(const vector<string> & del_keys)
1206{
1207 vector<string>::const_iterator it;
1208 for(it=del_keys.begin(); it!=del_keys.end(); ++it) {
1209 this->del_attr(*it);
1210 }
1211}
1212
1213void EMData::set_attr(const string & key, EMObject val)
1214{
1215 /* Ignore dimension attribute. */
1216 if(key == "nx" || key == "ny" || key == "nz")
1217 {
1218 printf("Ignore setting dimension attribute %s. Use set_size if you need resize this EMData object.", key.c_str());
1219 return;
1220 }
1221
1222 if(rdata) { //skip following for header only image
1223 /* Ignore 'read only' attribute. */
1224 if(key == "sigma" ||
1225 key == "sigma_nonzero" ||
1226 key == "square_sum" ||
1227 key == "maximum" ||
1228 key == "minimum" ||
1229 key == "mean" ||
1230 key == "mean_nonzero" )
1231 {
1232 LOGWARN("Ignore setting read only attribute %s", key.c_str());
1233 return;
1234 }
1235 }
1236
1237 attr_dict[key] = val;
1238}
1239
1240void EMData::set_attr_python(const string & key, EMObject val)
1241{
1242 /* Ignore dimension attribute. */
1243 if(key == "nx" || key == "ny" || key == "nz")
1244 {
1245 printf("Ignore setting dimension attribute %s. Use set_size if you need resize this EMData object.", key.c_str());
1246 return;
1247 }
1248
1249 /* Ignore 'read only' attribute. */
1250 if(key == "sigma" ||
1251 key == "sigma_nonzero" ||
1252 key == "square_sum" ||
1253 key == "maximum" ||
1254 key == "minimum" ||
1255 key == "mean" ||
1256 key == "mean_nonzero" )
1257 {
1258 LOGWARN("Ignore setting read only attribute %s", key.c_str());
1259 return;
1260 }
1261
1262 EMObject::ObjectType argtype = val.get_type();
1263 if (argtype == EMObject::EMDATA) {
1264 EMData* e = (EMData*) val;
1265 e = e->copy();
1266 EMObject v(e);
1267 attr_dict[key] = v;
1268 }
1269 else if (argtype == EMObject::TRANSFORM) {
1270 Transform* t = new Transform(*((Transform*) val));
1271 EMObject v(t);
1272 attr_dict[key] = v;
1273 delete t; t=0;
1274 } else {
1275 attr_dict[key] = val;
1276 }
1277
1278}
1279
1280void EMData::scale_pixel(float scale) const
1281{
1282 attr_dict["apix_x"] = ((float) attr_dict["apix_x"]) * scale;
1283 attr_dict["apix_y"] = ((float) attr_dict["apix_y"]) * scale;
1284 attr_dict["apix_z"] = ((float) attr_dict["apix_z"]) * scale;
1285 if (attr_dict.has_key("ctf")) {
1286 Ctf *ctf=(Ctf *)attr_dict["ctf"];
1287 ctf->apix*=scale;
1288 attr_dict["ctf"]=ctf;
1289 if(ctf) {delete ctf; ctf=0;}
1290 }
1291}
1292
1293//vector<float> EMData::get_data_pickle() const
1295{
1296// vector<float> vf;
1297// vf.resize(nx*ny*nz);
1298// std::copy(rdata, rdata+nx*ny*nz, vf.begin());
1299
1300 EMBytes vf;
1301 vf.assign((const char *)get_data(),nx*ny*nz*sizeof(float));
1302
1303 return vf;
1304}
1305
1306//void EMData::set_data_pickle(const vector<float>& vf)
1307void EMData::set_data_pickle(std::string vf)
1308{
1309// if (rdata) printf("rdata exists\n");
1310// rdata = (float *)malloc(nx*ny*nz*sizeof(float));
1311// std::copy(vf.begin(), vf.end(), rdata);
1312 EMUtil::em_memcpy(get_data(),vf.data(),(size_t)nx*ny*nz*sizeof(float));
1313
1314}
1315
1317{
1318 return 0;
1319}
1320
1322{
1323 this->supp = 0;
1324}
1325
1327{
1328
1329 if (thres < 0 || thres > 1){
1330 LOGERR("threshold bust be between 0 and 1.");
1331 throw InvalidValueException(thres, "thres: 0 <= thres <= 1");
1332 }
1333
1334 EMData * amps = get_fft_amplitude();
1335 vector<float> ampvector = amps->get_data_as_vector();
1336 // yes I realize this may be slow if the map is big, but then again this function is only suited for tomo alignments, which if you have a big map will be VERY slow anyways!
1337 sort (ampvector.begin(), ampvector.end());
1338 int thresidx = int(thres * ampvector.size());
1339 float thresamp = ampvector[thresidx];
1340
1341 return thresamp;
1342}
1343
1344vector<Vec3i > find_region(EMData* image,const vector<Vec3i >& coords, const float value, vector<Vec3i >& region)
1345{
1346 static vector<Vec3i> two_six_connected;
1347 if (two_six_connected.size() == 0) {
1348 for(int i = -1; i <= 1; ++i) {
1349 for(int j = -1; j <= 1; ++j) {
1350 for(int k = -1; k <= 1; ++k) {
1351 if ( j != 0 || i != 0 || k != 0) {
1352 two_six_connected.push_back(Vec3i(i,j,k));
1353 }
1354 }
1355 }
1356 }
1357 }
1358
1359 vector<Vec3i> ret;
1360 for(vector<Vec3i>::const_iterator it = two_six_connected.begin(); it != two_six_connected.end(); ++it ) {
1361 for(vector<Vec3i>::const_iterator it2 = coords.begin(); it2 != coords.end(); ++it2 ) {
1362 if (image->get_value_at((*it2)[0],(*it2)[1],(*it2)[2]) != value) throw;
1363 Vec3i c = (*it)+(*it2);
1364
1365 if ( c[0] < 0 || c[0] >= image->get_xsize()) continue;
1366 if ( c[1] < 0 || c[1] >= image->get_ysize()) continue;
1367 if ( c[2] < 0 || c[2] >= image->get_zsize()) continue;
1368
1369 if( image->get_value_at(c[0],c[1],c[2]) == value ) {
1370 if (find(ret.begin(),ret.end(),c) == ret.end()) {
1371 if (find(region.begin(),region.end(),c) == region.end()) {
1372 region.push_back(c);
1373 ret.push_back(c);
1374 }
1375 }
1376 }
1377 }
1378 }
1379 return ret;
1380}
1381
1382vector<Vec3i> EMData::mask_contig_region(const float& value, const Vec3i& seed) {
1383 Vec3i coord(seed[0],seed[1],seed[2]);
1384 vector<Vec3i> region;
1385 region.push_back(coord);
1386 vector<Vec3i> find_region_input = region;
1387 while (true) {
1388 vector<Vec3i> v = find_region(this,find_region_input, value, region);
1389 if (v.size() == 0 ) break;
1390 else find_region_input = v;
1391 }
1392 return region;
1393}
Ctf is the base class for all CTF model.
Definition: ctf.h:60
virtual vector< float > to_vector() const =0
float apix
Definition: ctf.h:88
Dict is a dictionary to store <string, EMObject> pair.
Definition: emobject.h:385
void erase(const string &key)
Remove a particular key.
Definition: emobject.h:552
bool has_key(const string &key) const
Ask the Dictionary if it as a particular key.
Definition: emobject.h:511
vector< string > keys() const
Get a vector containing all of the (string) keys in this dictionary.
Definition: emobject.h:475
EMAN1Ctf is the CTF model used in EMAN1.
Definition: ctf.h:120
void from_vector(const vector< float > &vctf)
Definition: ctf.cpp:112
EMData stores an image's data and defines core image processing routines.
Definition: emdata.h:82
void scale(float scale_factor)
scale the image by a factor.
Definition: emdata.cpp:886
void update_stat() const
Definition: emdata.cpp:3091
EMData()
For all image I/O.
Definition: emdata.cpp:70
static int totalalloc
Definition: emdata.h:803
float * supp
supplementary data array
Definition: emdata.h:837
@ EMDATA_NEEDUPD
Definition: emdata.h:816
int changecount
Definition: emdata.h:846
float * rdata
image real data
Definition: emdata.h:835
Dict attr_dict
to store all image header info
Definition: emdata.h:833
int nx
image size
Definition: emdata.h:848
int flags
CTF data All CTF data become attribute ctf(vector<float>) in attr_dict –Grant Tang.
Definition: emdata.h:844
size_t nxyz
Definition: emdata.h:849
EMObject is a wrapper class for types including int, float, double, etc as defined in ObjectType.
Definition: emobject.h:123
ObjectType get_type() const
Get the ObjectType This is an enumerated type first declared in the class EMObjectTypes.
Definition: emobject.h:224
static void process_region_io(void *cdata, FILE *file, int rw_mode, int image_index, size_t mode_size, int nx, int ny, int nz=1, const Region *area=0, bool need_flip=false, ImageType imgtype=IMAGE_UNKNOWN, int pre_row=0, int post_row=0)
Process image region IO.
Definition: emutil.cpp:931
static void em_memset(void *data, const int value, const size_t size)
Definition: emutil.h:377
static void em_memcpy(void *dst, const void *const src, const size_t size)
Definition: emutil.h:384
static bool is_same_size(const EMData *image1, const EMData *image2)
Check whether two EMData images are of the same size.
Definition: emutil.cpp:1224
static void em_free(void *data)
Definition: emutil.h:380
static void * em_realloc(void *data, const size_t new_size)
Definition: emutil.h:374
static void * em_malloc(const size_t size)
Definition: emutil.h:366
FloatPoint defines a float-coordinate point in a 1D/2D/3D space.
Definition: geometry.h:278
IntPoint defines an integer-coordinate point in a 1D/2D/3D space.
Definition: geometry.h:192
Pixel describes a 3D pixel's coordinates and its intensity value.
Definition: geometry.h:452
Region defines a 2D or 3D rectangular region specified by its origin coordinates and all edges' sizes...
Definition: geometry.h:497
A Transform object is a somewhat specialized object designed specifically for EMAN2/Sparx storage of ...
Definition: transform.h:75
static int hypot3sq(int x, int y, int z)
Euclidean distance function squared in 3D: f(x,y,z) = (x*x + y*y + z*z);.
Definition: util.h:805
static int square(int n)
Calculate a number's square.
Definition: util.h:736
static int hypot2sq(int x, int y)
Euclidean distance function squared in 2D: f(x,y) = (x*x + y*y);.
Definition: util.h:784
CudaPeakInfo * calc_max_location_wrap_cuda(const float *in, const int nx, const int ny, const int nz, const int maxdx, const int maxdy, const int maxdz)
float get_edgemean_cuda(const float *data, const int nx, const int ny, const int nz)
EMData * copy() const
This file is a part of "emdata.h", to use functions in this file, you should "#include "emdata....
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).
Definition: emdata_core.h:221
EMData * copy_head() const
Make an image with a copy of the current image's header.
vector< Vec3i > find_region(EMData *image, const vector< Vec3i > &coords, const float value, vector< Vec3i > &region)
int greaterthan(const void *p1, const void *p2)
void read_data(string fsp, size_t loc, const Region *area=0, const int file_nx=0, const int file_ny=0, const int file_nz=0)
Read the image pixel data in native byte order from a disk file.
vector< Pixel > calc_n_highest_locations(int n)
Calculate and return a sorted list of N highest pixels in the map.
EMObject get_attr(const string &attr_name) const
The generic way to get any image header information given a header attribute name.
EMData * get_fft_amplitude()
This file is a part of "emdata.h", to use functions in this file, you should "#include "emdata....
float get_amplitude_thres(float thres)
return the FFT amplitude which is greater than thres %
vector< Vec3i > mask_contig_region(const float &val, const Vec3i &seed)
int get_ysize() const
Get the image y-dimensional size.
void del_attr_dict(const vector< string > &del_keys)
Delete the attributes from the dictionary.
vector< Pixel > find_pixels_with_value(float val)
Find pixels in the image with exactly the specified values.
vector< float > calc_max_location_wrap_intp(const int maxshiftx=-1, const int maxshifty=-1, const int maxshiftz=-1)
Calculates the wrapped coordinates of the maximum value, and uses quadration intp to subpixel prec Th...
void set_attr_dict_explicit(const Dict &new_dict)
Make the attributes of this EMData exactly equal to the argument dictionary Originally introduced bec...
void set_attr_python(const string &key, EMObject val)
Set a header attribute's value from Python.
void set_attr_dict(const Dict &new_dict)
Merge the new values with the existing dictionary.
void write_data(string fsp, size_t loc, const Region *const area=0, const int file_nx=0, const int file_ny=0, const int file_nz=0)
Dump the image pixel data in native byte order to a disk file.
MArray2D get_2dview() const
Get image raw pixel data in a 2D multi-array format.
size_t calc_max_index() const
Calculates the index of maximum-value pixel when assuming all pixels are in a 1D array.
bool is_ri() const
Is this image a real/imaginary format complex image?
Ctf * get_ctf() const
Get ctf parameter of this image.
bool is_complex() const
Is this a complex image?
IntPoint calc_max_location_wrap(const int maxshiftx=-1, const int maxshifty=-1, const int maxshiftz=-1, float *value=0)
Calculates the wrapped coordinates of the maximum value This function is useful in the context of Fou...
EMData * get_fft_amplitude2D()
return the amplitudes of the 2D FFT including the left half PRB
IntPoint calc_min_location() const
Calculates the coordinates of the minimum-value pixel.
void set_supp_pickle(int i)
void set_data_pickle(std::string vf)
EMBytes get_data_pickle() const
Dict get_attr_dict() const
Get the image attribute dictionary containing all the image attribute names and attribute values.
void scale_pixel(float scale_factor) const
Scale the angstrom per pixel of this image by a uniform amount Alters the EMData metadata I had to ma...
int get_zsize() const
Get the image z-dimensional size.
void del_attr(const string &attr_name)
Delete the attribute from dictionary.
int get_xsize() const
Get the image x-dimensional size.
MCArray3D get_3dcview() const
Get complex image raw pixel data in a 3D multi-array format.
EMData * get_fft_phase()
return the phases of the FFT including the left half
int get_ndim() const
Get image dimension.
size_t calc_min_index() const
Calculates the index of minimum-value pixel when assuming all pixels are in a 1D array.
void set_ctf(Ctf *ctf)
Set the CTF parameter of this image.
IntPoint calc_max_location() const
Calculates the coordinates of the maximum-value pixel.
void set_size(int nx, int ny=1, int nz=1, bool noalloc=false)
Resize this EMData's main board memory pointer.
float get_circle_mean()
Calculates the circular edge mean by applying a circular mask on 'this' image.
void update()
Mark EMData as changed, statistics, etc will be updated at need.
MCArray2D get_2dcview() const
Get complex image raw pixel data in a 2D multi-array format.
float calc_center_density()
Calculates the density value at the peak of the image histogram, sort of like the mode of the density...
MArray3D get_3dview() const
Get image raw pixel data in a 3D multi-array format.
EMObject get_attr_default(const string &attr_name, const EMObject &em_obj=EMObject()) const
The generic way to get any image header information given a header attribute name.
float * get_data() const
Get the image pixel density data in a 1D float array.
void set_attr(const string &key, EMObject val)
Set a header attribute's value.
vector< Pixel > calc_highest_locations(float threshold) const
Calculate and return a sorted list of pixels whose values are above a specified threshold.
float calc_sigma_diff()
Calculates sigma above and below the mean and returns the difference between them.
int get_supp_pickle() const
float get_edge_mean() const
Calculates the mean pixel values around the (1 pixel) edge of the image.
FloatPoint calc_center_of_mass(const float threshold=0)
Calculate the center of mass with a threshold (Default 0, so only positive values are considered)
void ri2ap()
convert the complex image from real/imaginary to amplitude/phase
#define InvalidValueException(val, desc)
Definition: exception.h:285
#define ImageFormatException(desc)
Definition: exception.h:147
#define NotExistingObjectException(objname, desc)
Definition: exception.h:130
#define BadAllocException(desc)
Definition: exception.h:387
#define ImageDimensionException(desc)
Definition: exception.h:166
#define UnexpectedBehaviorException(desc)
Definition: exception.h:400
#define FileAccessException(filename)
Definition: exception.h:187
#define LOGWARN
Definition: log.h:53
#define LOGERR
Definition: log.h:51
#define ENTERFUNC
Definition: log.h:48
#define EXITFUNC
Definition: log.h:49
E2Exception class.
Definition: aligner.h:40
boost::multi_array_ref< std::complex< float >, 3 > MCArray3D
Definition: emdata.h:71
boost::multi_array_ref< float, 3 > MArray3D
Definition: emdata.h:69
boost::multi_array_ref< float, 2 > MArray2D
Definition: emdata.h:68
Vec3< int > Vec3i
Definition: vec3.h:694
boost::multi_array_ref< std::complex< float >, 2 > MCArray2D
Definition: emdata.h:70
int portable_fseek(FILE *fp, off_t offset, int whence)
#define y(i, j)
Definition: projector.cpp:1516
#define x(i)
Definition: projector.cpp:1517