EMAN2
Functions
emdata_core.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

EMData * copy () const
 This file is a part of "emdata.h", to use functions in this file, you should "#include "emdata.h", NEVER directly include this file. More...
 
EMDatacopy_head () const
 Make an image with a copy of the current image's header. More...
 
void add (float f, int keepzero=0)
 add a number to each pixel value of the image. More...
 
void add (const EMData &image)
 add a same-size image to this image pixel by pixel. More...
 
void addsquare (const EMData &image)
 add the squared value of each pixel from a same-size image to this image. More...
 
void sub (float f)
 subtract a float number to each pixel value of the image. More...
 
void sub (const EMData &image)
 subtract a same-size image from this image pixel by pixel. More...
 
void subsquare (const EMData &image)
 subtract the squared value of each pixel from a same-size image to this image. More...
 
void mult (int n)
 multiply an integer number to each pixel value of the image. More...
 
void mult (float f)
 multiply a float number to each pixel value of the image. More...
 
void mult (const EMData &image, bool prevent_complex_multiplication=false)
 multiply each pixel of this image with each pixel of some other same-size image. More...
 
void mult_ri (const EMData &image)
 multiply each complex RI pixel of this image with each pixel of some other same-size image. More...
 
void mult_complex_efficient (const EMData &em, const int radius)
 
void div (float f)
 make each pixel value divided by a float number. More...
 
void div (const EMData &image)
 make each pixel value divided by pixel value of another same-size image. More...
 
void update_min (const EMData &image)
 Replaces the value of each pixel with the minimum of the current value and the value in the provided image. More...
 
void to_zero ()
 Set all the pixel value = 0. More...
 
void to_one ()
 set all the pixel values = 1. More...
 
void to_value (const float &value)
 set all the pixel values to a value. More...
 
float dot (EMData *with)
 Dot product 2 images. More...
 
EMDataget_row (int row_index) const
 Get one row of a 1D/2D image. More...
 
void set_row (const EMData *data, int row_index)
 Set one row of a 1D/2D image. More...
 
EMDataget_col (int col_index) const
 Get one column of a 2D images. More...
 
void set_col (const EMData *data, int col_index)
 Set one column of a 2D image. More...
 
float get_value_at (int x, int y, int z) const
 Get the pixel density value at coordinates (x,y,z). More...
 
float get_value_at_index (size_t i) const
 Get the pixel density value at index i. More...
 
float get_value_at (int x, int y) const
 Get the pixel density value at coordinates (x,y). More...
 
float get_value_at (size_t i) const
 Get the pixel density value given an index 'i' assuming the pixles are stored in a 1D array. More...
 
std::complex< float > get_complex_at (const int &x, const int &y) const
 Get complex<float> value at x,y. More...
 
std::complex< float > get_complex_at (const int &x, const int &y, const int &z) const
 Get complex<float> value at x,y,z. More...
 
size_t get_complex_index (const int &x, const int &y, const int &z) const
 Get complex<float> index for coords x,y,z. More...
 
size_t get_complex_index (int x, int y, int z, const int &subx0, const int &suby0, const int &subz0, const int &fullnx, const int &fullny, const int &fullnz) const
 
size_t get_complex_index_fast (const int &x, const int &y, const int &z) const
 
void set_complex_at_idx (const int &x, const int &y, const int &z, const std::complex< float > &val)
 Set complex<float> value at x,y,z without reinterpreting the coordinates. More...
 
void set_complex_at (const int &x, const int &y, const std::complex< float > &val)
 Set complex<float> value at x,y. More...
 
void set_complex_at (const int &x, const int &y, const int &z, const std::complex< float > &val)
 Set complex<float> value at x,y,z. More...
 
size_t add_complex_at (const int &x, const int &y, const int &z, const std::complex< float > &val)
 Add complex<float> value at x,y,z. More...
 
size_t add_complex_at_fast (const int &x, const int &y, const int &z, const std::complex< float > &val)
 
size_t add_complex_at (int x, int y, int z, const int &subx0, const int &suby0, const int &subz0, const int &fullnx, const int &fullny, const int &fullnz, const std::complex< float > &val)
 Add complex<float> value at x,y,z assuming that 'this' is a subvolume from a larger virtual volume. More...
 
float get_value_at_wrap (int x, int y, int z) const
 Get the pixel density value at coordinates (x,y,z). More...
 
float get_value_at_wrap (int x, int y) const
 Get the pixel density value at coordinates (x,y). More...
 
float get_value_at_wrap (int x) const
 Get the pixel density value at coordinates (x). More...
 
float sget_value_at (Vec3i v)
 Vec3i version of save routines below. More...
 
float sget_value_at (int x, int y, int z) const
 A safer, slower way to get the pixel density value at coordinates (x,y,z). More...
 
float sget_value_at (int x, int y) const
 A safer, slower way to get the pixel density value at coordinates (x,y). More...
 
float sget_value_at (size_t i) const
 A safer, slower way to get the pixel density value given an index 'i' assuming the pixles are stored in a 1D array. More...
 
std::complex< float > get_complex_at_interp (float x, float y) const
 Gets bilinear interpolated complex values. More...
 
std::complex< float > get_complex_at_ginterp (float x, float y) const
 Gets 2x2 Gaussian interpolated complex values note that with Gaussian interpolation, there is a discontinuity in the interpolated values as you shift from one set of 2x2 samples to the next. More...
 
std::complex< float > get_complex_at_3ginterp (float x, float y) const
 Gets 3x3 Gaussian interpolated complex values note that with Gaussian interpolation, there is a discontinuity in the interpolated values as you shift from one set of 3x3 samples to the next. More...
 
float sget_value_at_interp (float x, float y) const
 Get pixel density value at interpolation of (x,y). More...
 
float sget_value_at_interp (float x, float y, float z) const
 Get the pixel density value at interpolation of (x,y,z). More...
 
void set_value_at (Vec3i loc, float val)
 set_value_at with Vec3i More...
 
void set_value_at (int x, int y, int z, float v)
 Set the pixel density value at coordinates (x,y,z). More...
 
void mult_value_at_fast (int x, int y, int z, float v)
 Multiplies the pixel density value at coordinates (x,y,z). More...
 
void set_value_at_fast (int x, int y, int z, float v)
 Set the pixel density value at coordinates (x,y,z). More...
 
void set_value_at_index (size_t i, float v)
 Set the pixel density value at index. More...
 
void set_value_at (int x, int y, float v)
 Set the pixel density value at coordinates (x,y). More...
 
void set_value_at_fast (int x, int y, float v)
 Set the pixel density value at coordinates (x,y). More...
 
void set_value_at (int x, float v)
 Set the pixel density value at coordinate (x). More...
 
void set_value_at_fast (int x, float v)
 Set the pixel density value at coordinate (x). More...
 
void free_memory ()
 Free memory associated with this EMData Called in destructor and in assignment operator. More...
 
void free_rdata ()
 Free rdata memory associated with this EMData Called in CUDA. More...
 
EMData & operator+= (float n)
 
EMData & operator-= (float n)
 
EMData & operator*= (float n)
 
EMData & operator/= (float n)
 
EMData & operator+= (const EMData &em)
 
EMData & operator-= (const EMData &em)
 
EMData & operator*= (const EMData &em)
 
EMData & operator/= (const EMData &em)
 
bool operator== (const EMData &that) const
 
bool equal (const EMData &that) const
 compare the equality of two EMData object based on their pixel values More...
 
float & operator() (const int ix, const int iy, const int iz) const
 Overload operator() for array indexing. More...
 
float & operator() (const int ix, const int iy) const
 
float & operator() (const size_t ix) const
 
void set_array_offsets (const int xoff_=0, const int yoff_=0, const int zoff_=0)
 Set the array offsets. More...
 
void set_array_offsets (vector< int > offsets)
 
vector< int > get_array_offsets ()
 
std::complex< float > & cmplx (const int ix, const int iy, const int iz)
 Return reference to complex elements. More...
 
std::complex< float > & cmplx (const int ix, const int iy)
 
std::complex< float > & cmplx (const int ix)
 
EMDatapower (int n) const
 return a image to the power of n More...
 
EMDatasqrt () const
 return square root of current image More...
 
EMDatalog () const
 return natural logarithm image for a image More...
 
EMDatalog10 () const
 return base 10 logarithm image for a image More...
 
EMData * real () const
 return real part of a complex image as a real image format, if this image is a real image, return a copy of this image. More...
 
EMData * imag () const
 return imaginary part of a complex image as a real image format. More...
 
EMDataabsi () const
 For a real image, it returns a same size image with abs() of each pixel. More...
 
EMData * amplitude () const
 return amplitude part of a complex image as a real image format More...
 
EMDataphase () const
 return phase part of a complex image as a real image format More...
 
EMDatareal2complex (float img=0.0f) const
 create a complex image from a real image, this complex image is in real/imaginary format More...
 

Function Documentation

◆ absi()

EMData * EMData::absi ( ) const

For a real image, it returns a same size image with abs() of each pixel.

For a complex image, it returns a image in size (nx/2,ny,nz), the pixel value output[i]=sqrt(input[i]*input[i]+input[i+1]*input[i+1])

Exceptions
InvalidCallExceptionthis function call require a complex image in real/imaginary format.

Definition at line 1268 of file emdata_core.cpp.

1269{
1270 ENTERFUNC;
1271
1272 EMData * e = new EMData();
1273
1274 if( is_real() ) // a real image
1275 {
1276 e = this->copy();
1277 int nx = get_xsize();
1278 int ny = get_ysize();
1279 int nz = get_zsize();
1280 float *edata = e->get_data();
1281 float * data = get_data();
1282 size_t idx;
1283 for( int i=0; i<nx; ++i ) {
1284 for( int j=0; j<ny; ++j ) {
1285 for( int k=0; k<nz; ++k ) {
1286 idx = i+j*nx+k*nx*ny;
1287 edata[idx] = std::abs(data[idx]);
1288 }
1289 }
1290 }
1291 }
1292 else //for a complex image
1293 {
1294 if( !is_ri() )
1295 {
1296 throw InvalidCallException("This image is in amplitude/phase format, this function call require a complex image in real/imaginary format.");
1297 }
1298 int nx = get_xsize();
1299 int ny = get_ysize();
1300 int nz = get_zsize();
1301 e->set_size(nx/2, ny, nz);
1302 float * edata = e->get_data();
1303 float * data = get_data();
1304 size_t idx1, idx2;
1305 for( int i=0; i<nx; ++i )
1306 {
1307 for( int j=0; j<ny; ++j )
1308 {
1309 for( int k=0; k<nz; ++k )
1310 {
1311 if( i%2 == 0 )
1312 {
1313 idx1 = i/2+j*(nx/2)+k*(nx/2)*ny;
1314 idx2 = i+j*nx+k*nx*ny;
1315 //complex data in format [real, complex, real, complex...]
1316 edata[idx1] =
1317 std::sqrt(data[idx2]*data[idx2]+data[idx2+1]*data[idx2+1]);
1318 }
1319 }
1320 }
1321 }
1322 }
1323
1324 e->set_complex(false);
1325 if(e->get_ysize()==1 && e->get_zsize()==1) {
1326 e->set_complex_x(false);
1327 }
1328 e->update();
1329 return e;
1330
1331 EXITFUNC;
1332}
EMData stores an image's data and defines core image processing routines.
Definition: emdata.h:82
EMData * copy() const
This file is a part of "emdata.h", to use functions in this file, you should "#include "emdata....
EMData * sqrt() const
return square root of current image
bool is_real() const
Is this a real image?
int get_ysize() const
Get the image y-dimensional size.
bool is_ri() const
Is this image a real/imaginary format complex image?
int get_zsize() const
Get the image z-dimensional size.
int get_xsize() const
Get the image x-dimensional size.
float * get_data() const
Get the image pixel density data in a 1D float array.
#define InvalidCallException(desc)
Definition: exception.h:348
#define ENTERFUNC
Definition: log.h:48
#define EXITFUNC
Definition: log.h:49

References copy(), EMAN::EMData::EMData(), ENTERFUNC, EXITFUNC, get_data(), get_xsize(), get_ysize(), get_zsize(), InvalidCallException, is_real(), is_ri(), EMAN::EMData::nx, EMAN::EMData::ny, EMAN::EMData::nz, and sqrt().

◆ add() [1/2]

void add ( const EMData &  image)

add a same-size image to this image pixel by pixel.

Parameters
imageThe image added to 'this' image.
Exceptions
ImageFormatExceptionIf the 2 images are not same size.

◆ add() [2/2]

void add ( float  f,
int  keepzero = 0 
)

add a number to each pixel value of the image.

Image may be real or complex.

Parameters
fThe number added to 'this' image.
keepzeroIf set will not modify pixels that are exactly zero

◆ add_complex_at() [1/2]

size_t EMData::add_complex_at ( const int &  x,
const int &  y,
const int &  z,
const std::complex< float > &  val 
)

Add complex<float> value at x,y,z.

This assumes the image is a standard real/imaginary image with the complex origin in the first memory location. If you take the fft of a real nx x ny x nz image, a nx+2 x ny x nz image will be produced, and values using this function can go from -nx/2 to nx/2 and -ny/2 to ny/2. It will automatically deal with wraparound and complex conjugate issues for -x. It will return the index into the float array at which the complex began, or nx*ny*nz if out of range

Parameters
xx coordinate
yy coordinate
zz coordinate
valcomplex<float> value to set
Returns
The complex pixel at x,y

Definition at line 251 of file emdata_core.cpp.

251 {
252if (abs(x)>=nx/2 || abs(y)>ny/2 || abs(z)>nz/2) return nxyz;
253
254//if (x==0 && abs(y)==16 && abs(z)==1) printf("## %d %d %d\n",x,y,z);
255size_t idx;
256// for x=0, we need to insert the value in 2 places
257if (x==0) {
258 if (y==0 && z==0) {
259 rdata[0]+=(float)val.real();
260 rdata[1]=0;
261 return 0;
262 }
263 // complex conjugate in x=0 plane
264 size_t idx=(y<=0?-y:ny-y)*(size_t)nx+(z<=0?-z:nz-z)*(size_t)nxy;
265// if (idx==16*34+1*34*32) printf("a %d %d %d\t%1.5f+%1.5fi\t%1.5f+%1.5fi\n",x,y,z,val.real(),val.imag(),rdata[idx],rdata[idx+1]);
266 rdata[idx]+=(float)val.real();
267 rdata[idx+1]+=(float)-val.imag();
268}
269if (abs(x)==nx/2-1) {
270 if (y==0 && z==0) {
271 rdata[nx-2]+=(float)val.real();
272 rdata[nx-1]=0;
273 return nx-2;
274 }
275 // complex conjugate in x=0 plane
276 size_t idx=nx-2+(y<=0?-y:ny-y)*(size_t)nx+(z<=0?-z:nz-z)*(size_t)nxy;
277// if (idx==16*34+1*34*32) printf("b %d %d %d\t%1.5f+%1.5fi\t%1.5f+%1.5fi\n",x,y,z,val.real(),val.imag(),rdata[idx],rdata[idx+1]);
278 rdata[idx]+=(float)val.real();
279 rdata[idx+1]+=(float)-val.imag();
280}
281if (x<0) {
282 idx=-x*2+(y<=0?-y:ny-y)*(size_t)nx+(z<=0?-z:nz-z)*(size_t)nxy;
283// if (idx==16*34+1*34*32) printf("c %d %d %d\t%1.5f+%1.5fi\t%1.5f+%1.5fi\n",x,y,z,val.real(),val.imag(),rdata[idx],rdata[idx+1]);
284 rdata[idx]+=(float)val.real();
285 rdata[idx+1]+=-(float)val.imag();
286 return idx;
287}
288
289idx=x*2+(y<0?ny+y:y)*(size_t)nx+(z<0?nz+z:z)*(size_t)nxy;
290//if (idx==16*34+1*34*32) printf("d %d %d %d\t%1.5f+%1.5fi\t%1.5f+%1.5fi\n",x,y,z,val.real(),val.imag(),rdata[idx],rdata[idx+1]);
291rdata[idx]+=(float)val.real();
292rdata[idx+1]+=(float)val.imag();
293
294return idx;
295}
#define rdata(i)
Definition: analyzer.cpp:592
#define y(i, j)
Definition: projector.cpp:1516
#define x(i)
Definition: projector.cpp:1517

References EMAN::EMData::nx, EMAN::EMData::nxy, EMAN::EMData::nxyz, EMAN::EMData::ny, EMAN::EMData::nz, EMAN::EMData::rdata, x, and y.

◆ add_complex_at() [2/2]

size_t EMData::add_complex_at ( int  x,
int  y,
int  z,
const int &  subx0,
const int &  suby0,
const int &  subz0,
const int &  fullnx,
const int &  fullny,
const int &  fullnz,
const std::complex< float > &  val 
)

Add complex<float> value at x,y,z assuming that 'this' is a subvolume from a larger virtual volume.

Requires that parameters often stored in the header as: subvolume_x0,y0,z0 and subvolume_full_nx,ny,nz be passed in as parameters. Otherwise similar to add_complex_at. It will return the index into the subvolume float array at which the complex began, or nx*ny*nz if out of range

Parameters
xx coordinate
yy coordinate
zz coordinate
valcomplex<float> value to set
Returns
The complex pixel at x,y

Definition at line 297 of file emdata_core.cpp.

297 {
298if (abs(x)>=fullnx/2 || abs(y)>fullny/2 || abs(z)>fullnz/2) return nxyz;
299//if (x==0 && (y!=0 || z!=0)) add_complex_at(0,-y,-z,subx0,suby0,subz0,fullnx,fullny,fullnz,conj(val));
300// complex conjugate insertion. Removed due to ambiguity with returned index
301/*if (x==0&& (y!=0 || z!=0)) {
302 int yy=y<=0?-y:fullny-y;
303 int zz=z<=0?-z:fullnz-z;
304
305 if (yy<suby0||zz<subz0||yy>=suby0+ny||zz>=subz0+nz) return nx*ny*nz;
306
307 size_t idx=(yy-suby0)*nx+(zz-subz0)*nx*ny;
308 rdata[idx]+=(float)val.real();
309 rdata[idx+1]+=(float)-val.imag();
310}*/
311float cc=1.0;
312if (x<0) {
313 x*=-1;
314 y*=-1;
315 z*=-1;
316 cc=-1.0;
317}
318if (y<0) y=fullny+y;
319if (z<0) z=fullnz+z;
320
321if (x<subx0||y<suby0||z<subz0||x>=subx0+nx||y>=suby0+ny||z>=subz0+nz) return nxyz;
322
323size_t idx=(x-subx0)*2+(y-suby0)*(size_t)nx+(z-subz0)*(size_t)nx*ny;
324rdata[idx]+=(float)val.real();
325rdata[idx+1]+=cc*(float)val.imag();
326return idx;
327}

References EMAN::EMData::nx, EMAN::EMData::nxyz, EMAN::EMData::ny, EMAN::EMData::nz, EMAN::EMData::rdata, x, and y.

◆ add_complex_at_fast()

size_t add_complex_at_fast ( const int &  x,
const int &  y,
const int &  z,
const std::complex< float > &  val 
)
inline

Definition at line 368 of file emdata_core.h.

368 {
369//if (x>=nx/2 || y>ny/2 || z>nz/2 || x<=-nx/2 || y<-ny/2 || z<-nz/2) return nxyz;
370if (abs(x)>=nx/2 || abs(y)>ny/2 || abs(z)>nz/2) return nxyz;
371
372//if (x==0 && abs(y)==16 && abs(z)==1) printf("## %d %d %d\n",x,y,z);
373size_t idx;
374// for x=0, we need to insert the value in 2 places
375if (x==0) {
376 if (y==0 && z==0) {
377 rdata[0]+=(float)val.real();
378 rdata[1]=0;
379 return 0;
380 }
381 // complex conjugate in x=0 plane
382 size_t idx=(y<=0?-y:ny-y)*(size_t)nx+(z<=0?-z:nz-z)*(size_t)nxy;
383// if (idx==16*34+1*34*32) printf("a %d %d %d\t%1.5f+%1.5fi\t%1.5f+%1.5fi\n",x,y,z,val.real(),val.imag(),rdata[idx],rdata[idx+1]);
384 rdata[idx]+=(float)val.real();
385 rdata[idx+1]+=(float)-val.imag();
386}
387if (abs(x)==nx/2-1) {
388 if (y==0 && z==0) {
389 rdata[nx-2]+=(float)val.real();
390 rdata[nx-1]=0;
391 return nx-2;
392 }
393 // complex conjugate in x=0 plane
394 size_t idx=nx-2+(y<=0?-y:ny-y)*(size_t)nx+(z<=0?-z:nz-z)*(size_t)nxy;
395// if (idx==16*34+1*34*32) printf("b %d %d %d\t%1.5f+%1.5fi\t%1.5f+%1.5fi\n",x,y,z,val.real(),val.imag(),rdata[idx],rdata[idx+1]);
396 rdata[idx]+=(float)val.real();
397 rdata[idx+1]+=(float)-val.imag();
398}
399if (x<0) {
400 idx=-x*2+(y<=0?-y:ny-y)*(size_t)nx+(z<=0?-z:nz-z)*(size_t)nxy;
401// if (idx==16*34+1*34*32) printf("c %d %d %d\t%1.5f+%1.5fi\t%1.5f+%1.5fi\n",x,y,z,val.real(),val.imag(),rdata[idx],rdata[idx+1]);
402 rdata[idx]+=(float)val.real();
403 rdata[idx+1]+=-(float)val.imag();
404 return idx;
405}
406
407idx=x*2+(y<0?ny+y:y)*(size_t)nx+(z<0?nz+z:z)*(size_t)nxy;
408//if (idx==16*34+1*34*32) printf("d %d %d %d\t%1.5f+%1.5fi\t%1.5f+%1.5fi\n",x,y,z,val.real(),val.imag(),rdata[idx],rdata[idx+1]);
409rdata[idx]+=(float)val.real();
410rdata[idx+1]+=(float)val.imag();
411
412return idx;
413}

References rdata, x, and y.

◆ addsquare()

void addsquare ( const EMData &  image)

add the squared value of each pixel from a same-size image to this image.

Parameters
imageThe image whose square is added to 'this' image.
Exceptions
ImageFormatExceptionIf the 2 images are not same size.

◆ amplitude()

EMData * amplitude ( ) const

return amplitude part of a complex image as a real image format

Returns
EMData * a real image which is the amplitude part of this image
Exceptions
InvalidCallExceptionif this image is a real image or is in real/imaginary format

◆ cmplx() [1/3]

std::complex< float > & cmplx ( const int  ix)

Definition at line 803 of file emdata_core.h.

803 {
804 ptrdiff_t pos = 2*(ix-xoff);
805#ifdef BOUNDS_CHECKING
806 if (pos < 0 || pos >= (size_t)nx*ny*nz)
807 throw OutofRangeException(0, (size_t)nx*ny*nz-1, pos, "EMData");
808#endif // BOUNDS_CHECKING
809 float* begin = get_data() + pos;
810 return *(reinterpret_cast<std::complex<float>* >(begin));
811}
#define OutofRangeException(low, high, input, objname)
Definition: exception.h:334

References get_data(), and OutofRangeException.

◆ cmplx() [2/3]

std::complex< float > & cmplx ( const int  ix,
const int  iy 
)

Definition at line 792 of file emdata_core.h.

792 {
793 ptrdiff_t pos = 2*(ix-xoff)+(iy-yoff)*nx;
794#ifdef BOUNDS_CHECKING
795 if (pos < 0 || pos >= (size_t)nx*ny*nz)
796 throw OutofRangeException(0, (size_t)nx*ny*nz-1, pos, "EMData");
797#endif // BOUNDS_CHECKING
798 float* begin = get_data() + pos;
799 return *(reinterpret_cast<std::complex<float>* >(begin));
800}

References get_data(), and OutofRangeException.

◆ cmplx() [3/3]

std::complex< float > & cmplx ( const int  ix,
const int  iy,
const int  iz 
)

Return reference to complex elements.

Definition at line 781 of file emdata_core.h.

781 {
782 ptrdiff_t pos = 2*(ix-xoff)+((iy-yoff)+(iz-zoff)*ny)*(size_t)nx;
783#ifdef BOUNDS_CHECKING
784 if (pos < 0 || pos >= (size_t)nx*ny*nz)
785 throw OutofRangeException(0, (size_t)nx*ny*nz-1, pos, "EMData");
786#endif // BOUNDS_CHECKING
787 float* begin = get_data() + pos;
788 return *(reinterpret_cast<std::complex<float>* >(begin));
789}

References get_data(), and OutofRangeException.

Referenced by EMAN::EMData::cconj().

◆ copy()

EMData * copy ( ) const

◆ copy_head()

EMData * EMData::copy_head ( ) const

Make an image with a copy of the current image's header.

Returns
An image with a copy of the current image's header.

Definition at line 100 of file emdata_core.cpp.

101{
102 ENTERFUNC;
103 EMData *ret = new EMData();
104 ret->attr_dict = attr_dict;
105
106 ret->set_size(nx, ny, nz);
107 ret->flags = flags;
108
109 ret->all_translation = all_translation;
110
111 ret->path = path;
112 ret->pathnum = pathnum;
113
114// should these be here? d.woolford I did not comment them out, merely place them here (commented out) to draw attention
115// ret->xoff = xoff;
116// ret->yoff = yoff;
117// ret->zoff = zoff;
118// ret->changecount = changecount;
119
120 ret->update();
121
122 EXITFUNC;
123 return ret;
124}
int pathnum
Definition: emdata.h:858
Dict attr_dict
to store all image header info
Definition: emdata.h:833
string path
Definition: emdata.h:857
int flags
CTF data All CTF data become attribute ctf(vector<float>) in attr_dict –Grant Tang.
Definition: emdata.h:844
Vec3f all_translation
translation from the original location
Definition: emdata.h:854

References EMAN::EMData::all_translation, EMAN::EMData::attr_dict, EMAN::EMData::EMData(), ENTERFUNC, EXITFUNC, EMAN::EMData::flags, EMAN::EMData::nx, EMAN::EMData::ny, EMAN::EMData::nz, EMAN::EMData::path, and EMAN::EMData::pathnum.

Referenced by do_fft(), do_ift(), get_fft_amplitude(), get_fft_amplitude2D(), get_fft_phase(), and EMAN::EMData::little_big_dot().

◆ div() [1/2]

void div ( const EMData &  image)

make each pixel value divided by pixel value of another same-size image.

Parameters
imageThe image 'this' image divided by.
Exceptions
ImageFormatExceptionIf the 2 images are not same size.

◆ div() [2/2]

void EMData::div ( float  f)

make each pixel value divided by a float number.

Parameters
fThe float number 'this' image divided by.

Definition at line 655 of file emdata_core.cpp.

656{
657 ENTERFUNC;
658 if ( f == 0 ) {
659 throw InvalidValueException(f,"Can not divide by zero");
660 }
661 mult(1.0f/f);
662 EXITFUNC;
663}
void mult(int n)
multiply an integer number to each pixel value of the image.
Definition: emdata_core.h:97
#define InvalidValueException(val, desc)
Definition: exception.h:285

References ENTERFUNC, EXITFUNC, InvalidValueException, and mult().

Referenced by EMAN::Util::calc_least_square_fit(), EMAN::EMAN2Ctf::compute_1d(), and EMAN::AmpMultProcessor::process_inplace().

◆ dot()

float dot ( EMData *  with)

Dot product 2 images.

The 2 images must be of same size. If 'evenonly' is true, only calculates pixels with even positions assuming all pixels are in a single array. If 'evenonly' is false, calculates all pixels. Shortcut for cmp("dot")

Parameters
withThe image to do dot product with.
Exceptions
NullPointerExceptionif with is a NULL image.
Returns
The dot product result.

◆ equal()

bool equal ( const EMData &  that) const

compare the equality of two EMData object based on their pixel values

◆ free_memory()

void free_memory ( )

Free memory associated with this EMData Called in destructor and in assignment operator.

Referenced by EMAN::EMData::operator=(), and EMAN::EMData::~EMData().

◆ free_rdata()

void EMData::free_rdata ( )

Free rdata memory associated with this EMData Called in CUDA.

Definition at line 79 of file emdata_core.cpp.

80{
82 if (rdata) {
83 EMUtil::em_free(rdata);
84 rdata = 0;
85 }
87}

References EMAN::EMUtil::em_free(), ENTERFUNC, EXITFUNC, and EMAN::EMData::rdata.

◆ get_array_offsets()

vector< int > get_array_offsets ( )

Definition at line 771 of file emdata_core.h.

771 {
772 vector<int> offsets;
773 offsets.push_back(xoff);
774 offsets.push_back(yoff);
775 offsets.push_back(zoff);
776 return offsets;
777}

◆ get_col()

EMData * EMData::get_col ( int  col_index) const

Get one column of a 2D images.

Parameters
col_indexIndex of the column.
Exceptions
ImageDimensionExceptionIf this image is not 2D.
Returns
A 1D image with the column data.

Definition at line 780 of file emdata_core.cpp.

781{
782 ENTERFUNC;
783
784 if (get_ndim() != 2) {
785 throw ImageDimensionException("2D image only");
786 }
787
788 EMData *ret = new EMData();
789 ret->set_size(ny, 1, 1);
790 float *dst = ret->get_data();
791 float *src = get_data();
792
793 for (int i = 0; i < ny; i++) {
794 dst[i] = src[i * nx + col_index];
795 }
796
797 ret->update();
798 EXITFUNC;
799 return ret;
800}
int get_ndim() const
Get image dimension.
#define ImageDimensionException(desc)
Definition: exception.h:166

References EMAN::EMData::EMData(), ENTERFUNC, EXITFUNC, get_data(), get_ndim(), ImageDimensionException, EMAN::EMData::nx, and EMAN::EMData::ny.

◆ get_complex_at() [1/2]

std::complex< float > EMData::get_complex_at ( const int &  x,
const int &  y 
) const

Get complex<float> value at x,y.

This assumes the image is a standard real/imaginary image with the complex origin in the first memory location. If you take the fft of a real nx x ny image, a nx+2 x ny image will be produced, and values using this function can go from -nx/2-1 to nx/2+1 and -ny/2 to ny/2. It will automatically deal with wraparound and complex conjugate issues for -x. This function differs from cmplx() which will interpret x,y directly as pixel coordinates

Parameters
xx coordinate
yy coordinate
Returns
The complex pixel at x,y

Definition at line 126 of file emdata_core.cpp.

126 {
127 if (abs(x)>=nx/2 || abs(y)>ny/2) return std::complex<float>(0,0);
128 if (x>=0 && y>=0) return std::complex<float>(rdata[ x*2+y*nx],rdata[x*2+y*nx+1]);
129 if (x>0 && y<0) return std::complex<float>(rdata[ x*2+(ny+y)*nx],rdata[x*2+(ny+y)*nx+1]);
130 if (x<0 && y>0) return std::complex<float>( rdata[-x*2+(ny-y)*nx],-rdata[-x*2+(ny-y)*nx+1]);
131 return std::complex<float>(rdata[-x*2-y*nx],-rdata[-x*2-y*nx+1]);
132}

References EMAN::EMData::nx, EMAN::EMData::ny, EMAN::EMData::rdata, x, and y.

Referenced by EMAN::CtfWtFiltAverager::finish(), get_complex_at_3ginterp(), get_complex_at_ginterp(), and get_complex_at_interp().

◆ get_complex_at() [2/2]

std::complex< float > EMData::get_complex_at ( const int &  x,
const int &  y,
const int &  z 
) const

Get complex<float> value at x,y,z.

This assumes the image is a standard real/imaginary image with the complex origin in the first memory location. If you take the fft of a real nx x ny x nz image, a nx+2 x ny x nz image will be produced, and values using this function can go from -nx/2 to nx/2 and -ny/2 to ny/2. It will automatically deal with wraparound and complex conjugate issues for -x. This function differs from cmplx() which will interpret x,y directly as pixel coordinates

Parameters
xx coordinate
yy coordinate
zz coordinate
Returns
The complex pixel at x,y

Definition at line 134 of file emdata_core.cpp.

134 {
135 if (abs(x)>=nx/2 || abs(y)>ny/2 || abs(z)>nz/2) return std::complex<float>(0,0);
136
137 if (x<0) {
138 int idx=-x*2+(y<=0?-y:ny-y)*nx+(z<=0?-z:nz-z)*nxy;
139 return std::complex<float>(rdata[idx],-rdata[idx+1]);
140 }
141
142 int idx=x*2+(y<0?ny+y:y)*nx+(z<0?nz+z:z)*nxy;
143 return std::complex<float>(rdata[idx],rdata[idx+1]);
144}

References EMAN::EMData::nx, EMAN::EMData::nxy, EMAN::EMData::ny, EMAN::EMData::nz, EMAN::EMData::rdata, x, and y.

◆ get_complex_at_3ginterp()

std::complex< float > EMData::get_complex_at_3ginterp ( float  x,
float  y 
) const

Gets 3x3 Gaussian interpolated complex values note that with Gaussian interpolation, there is a discontinuity in the interpolated values as you shift from one set of 3x3 samples to the next.

Parameters
xThe x coordinate (float).
yThe y coordinate (float).
Returns
The complex value at coordinates (x,y).

Definition at line 954 of file emdata_core.cpp.

955{
956 int x0 = static_cast < int >(Util::fast_floor(xx-0.5));
957 int y0 = static_cast < int >(Util::fast_floor(yy-0.5));
958
959 std::complex<float> p[9];
960 for (int y=0,i=0; y<3; y++) {
961 for (int x=0; x<3; x++,i++) {
962 p[i]=get_complex_at(x+x0,y+y0);
963 }
964 }
965
966 return Util::gauss3_interpolate_cmplx(p, xx-x0, yy-y0);
967}
std::complex< float > get_complex_at(const int &x, const int &y) const
Get complex<float> value at x,y.

References EMAN::Util::fast_floor(), EMAN::Util::gauss3_interpolate_cmplx(), get_complex_at(), x, and y.

◆ get_complex_at_ginterp()

std::complex< float > EMData::get_complex_at_ginterp ( float  x,
float  y 
) const

Gets 2x2 Gaussian interpolated complex values note that with Gaussian interpolation, there is a discontinuity in the interpolated values as you shift from one set of 2x2 samples to the next.

This is at the ~5% level

Parameters
xThe x coordinate (float).
yThe y coordinate (float).
Returns
The complex value at coordinates (x,y).

Definition at line 941 of file emdata_core.cpp.

942{
943 int x = static_cast < int >(Util::fast_floor(xx));
944 int y = static_cast < int >(Util::fast_floor(yy));
945
946 std::complex<float> p1 = get_complex_at(x, y);
947 std::complex<float> p2 = get_complex_at(x + 1, y);
948 std::complex<float> p3 = get_complex_at(x, y + 1);
949 std::complex<float> p4 = get_complex_at(x + 1, y + 1);
950
951 return Util::gauss_interpolate_cmplx(p1, p2, p3, p4, xx - x, yy - y);
952}

References EMAN::Util::fast_floor(), EMAN::Util::gauss_interpolate_cmplx(), get_complex_at(), x, and y.

◆ get_complex_at_interp()

std::complex< float > EMData::get_complex_at_interp ( float  x,
float  y 
) const

Gets bilinear interpolated complex values.

Parameters
xThe x coordinate (float).
yThe y coordinate (float).
Returns
The complex value at coordinates (x,y).

Definition at line 928 of file emdata_core.cpp.

929{
930 int x = static_cast < int >(Util::fast_floor(xx));
931 int y = static_cast < int >(Util::fast_floor(yy));
932
933 std::complex<float> p1 = get_complex_at(x, y);
934 std::complex<float> p2 = get_complex_at(x + 1, y);
935 std::complex<float> p3 = get_complex_at(x, y + 1);
936 std::complex<float> p4 = get_complex_at(x + 1, y + 1);
937
938 return Util::bilinear_interpolate_cmplx(p1, p2, p3, p4, xx - x, yy - y);
939}

References EMAN::Util::bilinear_interpolate_cmplx(), EMAN::Util::fast_floor(), get_complex_at(), x, and y.

◆ get_complex_index() [1/2]

size_t EMData::get_complex_index ( const int &  x,
const int &  y,
const int &  z 
) const

Get complex<float> index for coords x,y,z.

This assumes the image is a standard real/imaginary image with the complex origin in the first memory location. If you take the fft of a real nx x ny x nz image, a nx+2 x ny x nz image will be produced, and values using this function can go from -nx/2 to nx/2 and -ny/2 to ny/2. It will automatically deal with wraparound and complex conjugate issues for -x. Note that if a pixel is accessed at this location, a complex conjugate may be required if x<0, and this fact is not returned.

Parameters
xx coordinate
yy coordinate
zz coordinate
Returns
The complex pixel at x,y

Definition at line 146 of file emdata_core.cpp.

146 {
147 if (abs(x)>=nx/2 || abs(y)>ny/2 || abs(z)>nz/2) return nxyz;
148 if (x<0) {
149 return -x*2+(y<=0?-y:ny-y)*(size_t)nx+(z<=0?-z:nz-z)*(size_t)nxy;
150 }
151 return x*2+(y<0?ny+y:y)*(size_t)nx+(z<0?nz+z:z)*(size_t)nxy;
152}

References EMAN::EMData::nx, EMAN::EMData::nxy, EMAN::EMData::nxyz, EMAN::EMData::ny, EMAN::EMData::nz, x, and y.

◆ get_complex_index() [2/2]

size_t EMData::get_complex_index ( int  x,
int  y,
int  z,
const int &  subx0,
const int &  suby0,
const int &  subz0,
const int &  fullnx,
const int &  fullny,
const int &  fullnz 
) const

Definition at line 154 of file emdata_core.cpp.

154 {
155if (abs(x)>=fullnx/2 || abs(y)>fullny/2 || abs(z)>fullnz/2) return nxyz;
156
157if (x<0) {
158 x*=-1;
159 y*=-1;
160 z*=-1;
161}
162if (y<0) y=fullny+y;
163if (z<0) z=fullnz+z;
164
165if (x<subx0||y<suby0||z<subz0||x>=subx0+nx||y>=suby0+ny||z>=subz0+nz) return nxyz;
166
167return (x-subx0)*2+(y-suby0)*(size_t)nx+(z-subz0)*(size_t)nx*(size_t)ny;
168}

References EMAN::EMData::nx, EMAN::EMData::nxyz, EMAN::EMData::ny, EMAN::EMData::nz, x, and y.

◆ get_complex_index_fast()

size_t get_complex_index_fast ( const int &  x,
const int &  y,
const int &  z 
) const
inline

Definition at line 302 of file emdata_core.h.

302 {
303// if (abs(x)>=nx/2 || abs(y)>ny/2 || abs(z)>nz/2) return nxyz;
304 if (x<0) {
305 return (size_t)x*-2+(y<=0?-y:ny-y)*(size_t)nx+(z<=0?-z:nz-z)*(size_t)nxy;
306 }
307 return x*2+(y<0?ny+y:y)*(size_t)nx+(z<0?nz+z:z)*(size_t)nxy;
308}

References x, and y.

◆ get_row()

EMData * EMData::get_row ( int  row_index) const

Get one row of a 1D/2D image.

Parameters
row_indexIndex of the row.
Exceptions
ImageDimensionExceptionIf this image is 3D.
Returns
A 1D image with the row data.

Definition at line 745 of file emdata_core.cpp.

746{
747 ENTERFUNC;
748
749 if (get_ndim() > 2) {
750 throw ImageDimensionException("1D/2D image only");
751 }
752
753 EMData *ret = new EMData();
754 ret->set_size(nx, 1, 1);
755 memcpy(ret->get_data(), get_data() + nx * row_index, nx * sizeof(float));
756 ret->update();
757 EXITFUNC;
758 return ret;
759}

References EMAN::EMData::EMData(), ENTERFUNC, EXITFUNC, get_data(), get_ndim(), ImageDimensionException, and EMAN::EMData::nx.

◆ get_value_at() [1/3]

float get_value_at ( int  x,
int  y 
) const
inline

Get the pixel density value at coordinates (x,y).

2D only. The validity of x, y is not checked.

Parameters
xThe x coordinate.
yThe y coordinate.
Returns
The pixel density value at coordinates (x,y).

Definition at line 241 of file emdata_core.h.

242{
243 return get_data()[x + y * nx];
244}

References get_data(), x, and y.

◆ get_value_at() [2/3]

float get_value_at ( int  x,
int  y,
int  z 
) const
inline

Get the pixel density value at coordinates (x,y,z).

The validity of x, y, and z is not checked.

Parameters
xThe x coordinate.
yThe y coordinate.
zThe z coordinate.
Returns
The pixel density value at coordinates (x,y,z).

Definition at line 221 of file emdata_core.h.

222{
223 return get_data()[(size_t)x + (size_t)y * (size_t)nx + (size_t)z * (size_t)nxy];
224}

References get_data(), x, and y.

Referenced by bispecRotTransInvDirect(), bispecRotTransInvN(), EMAN::EMData::common_lines(), find_pixels_with_value(), get_attr(), EMAN::RotateInFSProcessor::process_inplace(), EMAN::ObjLabelProcessor::process_inplace(), and EMAN::Util::svdcmp().

◆ get_value_at() [3/3]

float get_value_at ( size_t  i) const
inline

Get the pixel density value given an index 'i' assuming the pixles are stored in a 1D array.

The validity of i is not checked.

Parameters
i1D data array index.
Returns
The pixel density value

Definition at line 254 of file emdata_core.h.

255{
256 return get_data()[i];
257}

References get_data().

◆ get_value_at_index()

float get_value_at_index ( size_t  i) const
inline

Get the pixel density value at index i.

Parameters
aThe index.

Definition at line 229 of file emdata_core.h.

230{
231 return *(rdata + i);
232}

References rdata.

◆ get_value_at_wrap() [1/3]

float & get_value_at_wrap ( int  x) const

Get the pixel density value at coordinates (x).

Should only be called on 1D images - no errors are thrown Wraps pixel values if they are negative - i.e. is circulant For example, if x = -1, then the pixel at nx-1 is returned

Parameters
xThe x coordinate.
Returns
The pixel density value at circulant coordinates (x).

Definition at line 825 of file emdata_core.cpp.

826{
827 if (x < 0) x = nx + x;
828 return get_data()[x];
829}

References get_data(), EMAN::EMData::nx, and x.

◆ get_value_at_wrap() [2/3]

float & get_value_at_wrap ( int  x,
int  y 
) const

Get the pixel density value at coordinates (x,y).

Should only be called on 2D images - no errors are thrown Wraps pixel values if they are negative - i.e. is circulant For example, if x = -1, then the pixel at nx-1 is returned

Parameters
xThe x coordinate.
yThe y coordinate.
Returns
The pixel density value at circulant coordinates (x,y).

Definition at line 831 of file emdata_core.cpp.

832{
833 if (x < 0) x = nx + x;
834 if (y < 0) y = ny + y;
835
836 return get_data()[x + y * nx];
837}

References get_data(), EMAN::EMData::nx, EMAN::EMData::ny, x, and y.

◆ get_value_at_wrap() [3/3]

float & get_value_at_wrap ( int  x,
int  y,
int  z 
) const

Get the pixel density value at coordinates (x,y,z).

Should only be called on 3D images - no errors are thrown Wraps pixel values if they are negative - i.e. is circulant For example, if x = -1, then the pixel at nx-1 is returned

Parameters
xThe x coordinate.
yThe y coordinate.
zThe z coordinate.
Returns
The pixel density value at circulant coordinates (x,y,z).

Definition at line 839 of file emdata_core.cpp.

840{
841
842#ifdef EMAN2_USING_CUDA
843 if(EMData::usecuda == 1 && cudarwdata){
844 float result = get_value_at_wrap_cuda(cudarwdata, x, y, z, nx, ny, nz); // this should work....
845 return result;
846 }
847#endif
848 int lx = x;
849 int ly = y;
850 int lz = z;
851
852 if (lx < 0) lx = nx + lx;
853 if (ly < 0) ly = ny + ly;
854 if (lz < 0) lz = nz + lz;
855
856 return get_data()[lx + ly * (size_t)nx + lz * (size_t)nxy];
857}
float get_value_at_wrap_cuda(float *data, int tx, int ty, int tz, int nx, int ny, int nz)

References get_data(), get_value_at_wrap_cuda(), EMAN::EMData::nx, EMAN::EMData::nxy, EMAN::EMData::ny, EMAN::EMData::nz, x, and y.

Referenced by calc_max_location_wrap(), calc_max_location_wrap_intp(), EMAN::EMData::compute_missingwedge(), and EMAN::EMData::zero_corner_circulant().

◆ imag()

EMData * imag ( ) const

return imaginary part of a complex image as a real image format.

Returns
a real image which is the imaginary part of this image.
Exceptions
InvalidCallExceptionif this image is a real image
InvalidCallExceptionif this image is a complex image in amplitude/phase format

◆ log()

EMData * EMData::log ( ) const

return natural logarithm image for a image

Returns
a image which is the natural logarithm of this image
Exceptions
InvalidValueExceptionpixel value must be >= 0
ImageFormatExceptionreal image only

Definition at line 1114 of file emdata_core.cpp.

1115{
1116 ENTERFUNC;
1117
1118 if (is_complex()) {
1119 throw ImageFormatException("real image only");
1120 }
1121
1122 EMData * r = this->copy();
1123 float * new_data = r->get_data();
1124 float * data = get_data();
1125 size_t size = nxyz;
1126 for (size_t i = 0; i < size; ++i) {
1127 if(data[i] < 0) {
1128 throw InvalidValueException(data[i], "pixel value must be non-negative for logrithm");
1129 }
1130 else {
1131 if(data[i]) { //do nothing with pixel has value zero
1132 new_data[i] = std::log(data[i]);
1133 }
1134 }
1135 }
1136
1137 r->update();
1138 return r;
1139
1140 EXITFUNC;
1141}
EMData * log() const
return natural logarithm image for a image
bool is_complex() const
Is this a complex image?
#define ImageFormatException(desc)
Definition: exception.h:147

References copy(), ENTERFUNC, EXITFUNC, get_data(), ImageFormatException, InvalidValueException, is_complex(), log(), and EMAN::EMData::nxyz.

Referenced by EMAN::LowpassAutoBProcessor::create_radial_func(), EMAN::LocalWeightAverager::finish(), EMAN::Randnum::get_gauss_rand(), EMAN::EMUtil::getRenderMinMax(), log(), EMAN::Util::log_2(), EMAN::PointArray::pdb2mrc_by_summation(), EMAN::PointArray::projection_by_summation(), EMAN::PointArray::replace_by_summation(), and EMAN::PointArray::set_from_density_map().

◆ log10()

EMData * EMData::log10 ( ) const

return base 10 logarithm image for a image

Returns
a image which is the base 10 logarithm of this image
Exceptions
InvalidValueExceptionpixel value must be >= 0
ImageFormatExceptionreal image only

Definition at line 1144 of file emdata_core.cpp.

1145{
1146 ENTERFUNC;
1147
1148 if (is_complex()) {
1149 throw ImageFormatException("real image only");
1150 }
1151
1152 EMData * r = this->copy();
1153 float * new_data = r->get_data();
1154 float * data = get_data();
1155 size_t size = nxyz;
1156 for (size_t i = 0; i < size; ++i) {
1157 if(data[i] < 0) {
1158 throw InvalidValueException(data[i], "pixel value must be non-negative for logrithm");
1159 }
1160 else {
1161 if(data[i]) { //do nothing with pixel has value zero
1162 new_data[i] = std::log10(data[i]);
1163 }
1164 }
1165 }
1166
1167 r->update();
1168 return r;
1169
1170 EXITFUNC;
1171}
EMData * log10() const
return base 10 logarithm image for a image

References copy(), ENTERFUNC, EXITFUNC, get_data(), ImageFormatException, InvalidValueException, is_complex(), log10(), and EMAN::EMData::nxyz.

Referenced by log10(), EMAN::SNRProcessor::process_inplace(), and EMAN::LogProcessor::process_pixel().

◆ mult() [1/3]

void mult ( const EMData &  image,
bool  prevent_complex_multiplication = false 
)

multiply each pixel of this image with each pixel of some other same-size image.

Parameters
imageThe image multiplied to 'this' image.
prevent_complex_multiplicationif the image is complex, this flag will override complex multiplication and just multiply each pixel by the other
Exceptions
ImageFormatExceptionIf the 2 images are not same size.

◆ mult() [2/3]

void mult ( float  f)

multiply a float number to each pixel value of the image.

Parameters
fThe float multiplied to 'this' image.

◆ mult() [3/3]

void mult ( int  n)

multiply an integer number to each pixel value of the image.

Parameters
nThe integer multiplied to 'this' image.

Definition at line 97 of file emdata_core.h.

98{
99 mult((float)n);
100}

References mult().

Referenced by div(), do_ift_inplace(), mult(), and EMAN::AmpMultProcessor::process_inplace().

◆ mult_complex_efficient()

void mult_complex_efficient ( const EMData &  em,
const int  radius 
)

◆ mult_ri()

void mult_ri ( const EMData &  image)

multiply each complex RI pixel of this image with each pixel of some other same-size image.

No type checking. Images must both known to be complex RI checking for complex/ri is expensive!

Parameters
imageThe image multiplied to 'this' image.
prevent_complex_multiplicationif the image is complex, this flag will override complex multiplication and just multiply each pixel by the other
Exceptions
ImageFormatExceptionIf the 2 images are not same size.

◆ mult_value_at_fast()

void mult_value_at_fast ( int  x,
int  y,
int  z,
float  v 
)
inline

Multiplies the pixel density value at coordinates (x,y,z).

The validity of x, y, and z is not checked. This implementation has no bounds checking.

Parameters
xThe x coordinate.
yThe y coordinate.
zThe z coordinate.
vThe pixel density value at coordinates (x,y,z).

Definition at line 594 of file emdata_core.h.

595{
596 get_data()[(size_t)x + (size_t)y * (size_t)nx + (size_t)z * (size_t)nxy] *= v;
597 update();
598}
void update()
Mark EMData as changed, statistics, etc will be updated at need.

References get_data(), update(), x, and y.

◆ operator()() [1/3]

float & operator() ( const int  ix,
const int  iy 
) const
inline

Definition at line 737 of file emdata_core.h.

737 {
738 ptrdiff_t pos = (ix - xoff) + (iy-yoff)*nx;
739#ifdef BOUNDS_CHECKING
740 if (pos < 0 || pos >= (size_t)nx*ny*nz)
741 {
742 throw OutofRangeException(0, (size_t)nx*ny*nz-1, pos, "EMData");
743 }
744#endif // BOUNDS_CHECKING
745 return *(get_data() + pos);
746}

References get_data(), and OutofRangeException.

◆ operator()() [2/3]

float & operator() ( const int  ix,
const int  iy,
const int  iz 
) const
inline

Overload operator() for array indexing.

Definition at line 727 of file emdata_core.h.

727 {
728 ptrdiff_t pos = (size_t)(ix-xoff) + ((iy-yoff) + (size_t)(iz-zoff)*ny)*nx;
729#ifdef BOUNDS_CHECKING
730 if (pos < 0 || pos >= (size_t)nx*ny*nz) {
731 throw OutofRangeException(0, (size_t)nx*ny*nz-1, pos, "EMData");
732 }
733#endif // BOUNDS_CHECKING
734 return *(get_data() + pos);
735}

References get_data(), and OutofRangeException.

◆ operator()() [3/3]

float & operator() ( const size_t  ix) const
inline

Definition at line 749 of file emdata_core.h.

749 {
750 ptrdiff_t pos = ix - xoff;
751#ifdef BOUNDS_CHECKING
752 if (pos < 0 || pos >= (size_t)nx*ny*nz)
753 throw OutofRangeException(0, (size_t)nx*ny*nz-1, pos, "EMData");
754#endif // BOUNDS_CHECKING
755 return *(get_data() + pos);
756}

References get_data(), and OutofRangeException.

◆ operator*=() [1/2]

EMData & operator*= ( const EMData &  em)

◆ operator*=() [2/2]

EMData & operator*= ( float  n)

◆ operator+=() [1/2]

EMData & operator+= ( const EMData &  em)

◆ operator+=() [2/2]

EMData & operator+= ( float  n)

◆ operator-=() [1/2]

EMData & operator-= ( const EMData &  em)

◆ operator-=() [2/2]

EMData & operator-= ( float  n)

◆ operator/=() [1/2]

EMData & operator/= ( const EMData &  em)

◆ operator/=() [2/2]

EMData & operator/= ( float  n)

◆ operator==()

bool operator== ( const EMData &  that) const

◆ phase()

EMData * EMData::phase ( ) const

return phase part of a complex image as a real image format

Returns
EMData * a real image which is the phase part of this image
Exceptions
InvalidCallExceptionif this image is a real image or is in real/imaginary format

Definition at line 1384 of file emdata_core.cpp.

1385{
1386 ENTERFUNC;
1387
1388 EMData * e = new EMData();
1389
1390 if( is_real() ) {
1391 delete e;
1392 throw InvalidCallException("No imaginary part for a real image, this function call require a complex image.");
1393 }
1394 else {
1395 if(is_ri()) {
1396 delete e;
1397 throw InvalidCallException("This image is in real/imaginary format, this function call require a complex image in amplitude/phase format.");
1398 }
1399
1400 int nx = get_xsize();
1401 int ny = get_ysize();
1402 int nz = get_zsize();
1403 e->set_size(nx/2, ny, nz);
1404 float * edata = e->get_data();
1405 float * data = get_data();
1406 size_t idx1, idx2;
1407 for( int i=0; i<nx; ++i ) {
1408 for( int j=0; j<ny; ++j ) {
1409 for( int k=0; k<nz; ++k ) {
1410 if( i%2 == 1 ) {
1411 idx1 = i/2+j*(nx/2)+k*(nx/2)*ny;
1412 idx2 = i+j*nx+k*nx*ny;
1413 //complex data in format [real, complex, real, complex...]
1414 edata[idx1] = data[idx2];
1415 }
1416 }
1417 }
1418 }
1419 }
1420
1421 e->set_complex(false);
1422 if(e->get_ysize()==1 && e->get_zsize()==1) {
1423 e->set_complex_x(false);
1424 }
1425 e->update();
1426 return e;
1427
1428 EXITFUNC;
1429}

References EMAN::EMData::EMData(), ENTERFUNC, EXITFUNC, get_data(), get_xsize(), get_ysize(), get_zsize(), InvalidCallException, is_real(), is_ri(), EMAN::EMData::nx, EMAN::EMData::ny, and EMAN::EMData::nz.

Referenced by EMAN::TestImageFourierNoiseGaussian::process_inplace(), EMAN::TestImageFourierNoiseProfile::process_inplace(), EMAN::TestImageSphericalWave::process_inplace(), EMAN::TestImageSinewave::process_inplace(), EMAN::TestImageSinewaveCircular::process_inplace(), EMAN::EMAN2Ctf::set_phase(), and EMAN::TransformProcessor::transform().

◆ power()

EMData * EMData::power ( int  n) const

return a image to the power of n

Parameters
nthe power of this image
Returns
a image which is the nth power of this image
Exceptions
InvalidValueExceptionn must be >= 0

Definition at line 1059 of file emdata_core.cpp.

1060{
1061 ENTERFUNC;
1062
1063 if( n<0 ) {
1064 throw InvalidValueException(n, "the power of negative integer not supported.");
1065 }
1066
1067 EMData * r = this->copy();
1068 if( n == 0 ) {
1069 r->to_one();
1070 }
1071 else if( n>1 ) {
1072 for( int i=1; i<n; i++ ) {
1073 *r *= *this;
1074 }
1075 }
1076
1077 r->update();
1078 return r;
1079
1080 EXITFUNC;
1081}

References copy(), ENTERFUNC, EXITFUNC, and InvalidValueException.

Referenced by EMAN::FourierReconstructor::do_compare_slice_work(), and EMAN::WienerFourierReconstructor::do_compare_slice_work().

◆ real()

EMData * real ( ) const

return real part of a complex image as a real image format, if this image is a real image, return a copy of this image.

Returns
a real image which is the real part of this image.

Referenced by EMAN::BispecSliceProcessor::process(), and EMAN::GridKernelFixProcessor::process_inplace().

◆ real2complex()

EMData * EMData::real2complex ( float  img = 0.0f) const

create a complex image from a real image, this complex image is in real/imaginary format

Parameters
imggive an artificial imaginary part
Returns
a complex image which is generated from a real image
Exceptions
InvalidCallExceptionthis function can not be called by complex image

Definition at line 1431 of file emdata_core.cpp.

1432{
1433 ENTERFUNC;
1434
1435 if( is_complex() ) {
1436 throw InvalidCallException("This function call only apply to real image");
1437 }
1438
1439 EMData * e = new EMData();
1440 int nx = get_xsize();
1441 int ny = get_ysize();
1442 int nz = get_zsize();
1443 e->set_size(nx*2, ny, nz);
1444
1445 for( int k=0; k<nz; ++k ) {
1446 for( int j=0; j<ny; ++j ) {
1447 for( int i=0; i<nx; ++i ) {
1448 (*e)(i*2,j,k) = (*this)(i,j,k);
1449 (*e)(i*2+1,j,k) = img;
1450 }
1451 }
1452 }
1453
1454 e->set_complex(true);
1455 if(e->get_ysize()==1 && e->get_zsize()==1) {
1456 e->set_complex_x(true);
1457 }
1458 e->set_ri(true);
1459 e->update();
1460 return e;
1461
1462 EXITFUNC;
1463}

References EMAN::EMData::EMData(), ENTERFUNC, EXITFUNC, get_xsize(), get_ysize(), get_zsize(), InvalidCallException, is_complex(), EMAN::EMData::nx, EMAN::EMData::ny, and EMAN::EMData::nz.

◆ set_array_offsets() [1/2]

void set_array_offsets ( const int  xoff_ = 0,
const int  yoff_ = 0,
const int  zoff_ = 0 
)

Set the array offsets.

Definition at line 760 of file emdata_core.h.

761 {
762 xoff=xoff_; yoff=yoff_; zoff=zoff_;
763}

Referenced by set_array_offsets().

◆ set_array_offsets() [2/2]

void set_array_offsets ( vector< int >  offsets)

Definition at line 766 of file emdata_core.h.

766 {
767 set_array_offsets(offsets[0],offsets[1],offsets[2]);
768}
void set_array_offsets(const int xoff_=0, const int yoff_=0, const int zoff_=0)
Set the array offsets.
Definition: emdata_core.h:760

References set_array_offsets().

◆ set_col()

void set_col ( const EMData *  data,
int  col_index 
)

Set one column of a 2D image.

Parameters
dataThe column image data.
col_indexIndex of the column.
Exceptions
ImageDimensionExceptionIf this image is not 2D.

◆ set_complex_at() [1/2]

void EMData::set_complex_at ( const int &  x,
const int &  y,
const int &  z,
const std::complex< float > &  val 
)

Set complex<float> value at x,y,z.

This assumes the image is a standard real/imaginary image with the complex origin in the first memory location. If you take the fft of a real nx x ny x nz image, a nx+2 x ny x nz image will be produced, and values using this function can go from -nx/2 to nx/2 and -ny/2 to ny/2. It will automatically deal with wraparound and complex conjugate issues for -x. This function differs from cmplx() which will interpret x,y directly as pixel coordinates

Parameters
xx coordinate
yy coordinate
zz coordinate
valcomplex<float> value to set
Returns
The complex pixel at x,y

Definition at line 208 of file emdata_core.cpp.

208 {
209if (abs(x)>=nx/2 || abs(y)>ny/2 || abs(z)>nz/2) return;
210
211size_t idx;
212
213// for x=0, we need to insert the value in 2 places
214// complex conjugate insertion. Removed due to ambiguity with returned index
215if (x==0) {
216 if (y==0 && z==0) {
217 rdata[0]=(float)val.real();
218 rdata[1]=0;
219 return;
220 }
221 // complex conjugate in x=0 plane
222 size_t idx=(y<=0?-y:ny-y)*(size_t)nx+(z<=0?-z:nz-z)*(size_t)nxy;
223 rdata[idx]=(float)val.real();
224 rdata[idx+1]=(float)-val.imag();
225}
226if (abs(x)==nx/2-1) {
227 if (y==0 && z==0) {
228 rdata[nx-2]=(float)val.real();
229 rdata[nx-1]=0;
230 return;
231 }
232 // complex conjugate in x=0 plane
233 size_t idx=nx-2+(y<=0?-y:ny-y)*(size_t)nx+(z<=0?-z:nz-z)*(size_t)nxy;
234 rdata[idx]=(float)val.real();
235 rdata[idx+1]=(float)-val.imag();
236}
237if (x<0) {
238 idx=-x*2+(y<=0?-y:ny-y)*(size_t)nx+(z<=0?-z:nz-z)*(size_t)nxy;
239 rdata[idx]=(float)val.real();
240 rdata[idx+1]=-(float)val.imag();
241 return;
242}
243
244idx=x*2+(y<0?ny+y:y)*(size_t)nx+(z<0?nz+z:z)*(size_t)nxy;
245rdata[idx]=(float)val.real();
246rdata[idx+1]=(float)val.imag();
247
248return;
249}

References EMAN::EMData::nx, EMAN::EMData::nxy, EMAN::EMData::ny, EMAN::EMData::nz, EMAN::EMData::rdata, x, and y.

◆ set_complex_at() [2/2]

void EMData::set_complex_at ( const int &  x,
const int &  y,
const std::complex< float > &  val 
)

Set complex<float> value at x,y.

This assumes the image is a standard real/imaginary image with the complex origin in the first memory location. If you take the fft of a real nx x ny image, a nx+2 x ny image will be produced, and values using this function can go from -nx/2-1 to nx/2+1 and -ny/2 to ny/2. It will automatically deal with wraparound and complex conjugate issues for -x. This function differs from cmplx() which will interpret x,y directly as pixel coordinates

Parameters
xx coordinate
yy coordinate
valcomplex<float> value to set
Returns
The complex pixel at x,y

Definition at line 171 of file emdata_core.cpp.

171 {
172 if (abs(x)>=nx/2 || abs(y)>ny/2) return;
173 if (x==0) {
174 if (y==0) { rdata[0]=val.real(); rdata[1]=0; }
175 else if (y==ny/2 || y==-ny/2) { rdata[ny/2*nx]=val.real(); rdata[ny/2*nx+1]=0; }
176 else if (y>0) {
177 rdata[y*nx]=rdata[(ny-y)*nx]=val.real();
178 rdata[y*nx+1]=val.imag();
179 rdata[(ny-y)*nx+1]=-val.imag();
180 }
181 else {
182 rdata[(ny+y)*nx]=rdata[-y*nx]=val.real();
183 rdata[(ny+y)*nx+1]=val.imag();
184 rdata[-y*nx+1]=-val.imag();
185 }
186 }
187 else if (x==nx/2-1) {
188 if (y==0) { rdata[nx-2]=val.real(); rdata[nx-1]=0; }
189 else if (y==ny/2 || y==-ny/2) { rdata[ny/2*nx+nx-2]=val.real(); rdata[ny/2*nx+nx-1]=0; }
190 else if (y>0) {
191 rdata[y*nx+nx-2]=rdata[(ny-y)*nx+nx-2]=val.real();
192 rdata[y*nx+nx-1]=val.imag();
193 rdata[(ny-y)*nx+nx-1]=-val.imag();
194 }
195 else {
196 rdata[(ny+y)*nx+nx-2]=rdata[-y*nx+nx-2]=val.real();
197 rdata[(ny+y)*nx+nx-1]=val.imag();
198 rdata[-y*nx+nx-1]=-val.imag();
199 }
200 }
201 else if (x>0 && y>=0) { rdata[ x*2+y*nx]=val.real(); rdata[x*2+y*nx+1]=val.imag(); }
202 else if (x>0 && y<0) { rdata[ x*2+(ny+y)*nx]=val.real(); rdata[x*2+(ny+y)*nx+1]=val.imag(); /*printf("%d %d %d %f\n",x,y,x*2+(ny+y)*nx,val.real());*/ }
203 else if (x<0 && y>0) { rdata[-x*2+(ny-y)*nx]=val.real(); rdata[-x*2+(ny-y)*nx+1]=-val.imag(); }
204 else { rdata[-x*2-y*nx]=val.real(); rdata[-x*2+-y*nx+1]=-val.imag(); }
205 return;
206}

References EMAN::EMData::nx, EMAN::EMData::ny, EMAN::EMData::rdata, x, and y.

◆ set_complex_at_idx()

void set_complex_at_idx ( const int &  x,
const int &  y,
const int &  z,
const std::complex< float > &  val 
)
inline

Set complex<float> value at x,y,z without reinterpreting the coordinates.

That is, x=y=z=0 will be inserted in the first data element. The x coordinate is still multiplied by 2 to compensate for the complex being 2 floats.

Parameters
xx coordinate
yy coordinate
zz coordinate
valcomplex<float> value to set

Definition at line 318 of file emdata_core.h.

318 {
319 size_t idx=x*2+y*(size_t)nx+z*(size_t)nxy;
320 rdata[idx]=(float)val.real();
321 rdata[idx+1]=(float)val.imag();
322}

References rdata, x, and y.

◆ set_row()

void set_row ( const EMData *  data,
int  row_index 
)

Set one row of a 1D/2D image.

Parameters
dataThe row image data.
row_indexIndex of the row.
Exceptions
ImageDimensionExceptionIf this image is 3D.

◆ set_value_at() [1/4]

void set_value_at ( int  x,
float  v 
)
inline

Set the pixel density value at coordinate (x).

1D image only.

Parameters
xThe x coordinate.
vThe pixel density value at coordinate (x).
Exceptions
OutofRangeExceptionwehn index out of image data's range.

Definition at line 674 of file emdata_core.h.

675{
676 if( x>=nx || x<0 )
677 {
678 throw OutofRangeException(0, nx-1, x, "x dimension index");
679 }
680 else
681 {
682 get_data()[x] = v;
683
684 update();
685 }
686}

References get_data(), OutofRangeException, update(), and x.

◆ set_value_at() [2/4]

void set_value_at ( int  x,
int  y,
float  v 
)
inline

Set the pixel density value at coordinates (x,y).

2D image only.

Parameters
xThe x coordinate.
yThe y coordinate.
vThe pixel density value at coordinates (x,y).
Exceptions
OutofRangeExceptionwehn index out of image data's range.

Definition at line 634 of file emdata_core.h.

635{
636 if( x>=nx || x<0 )
637 {
638 throw OutofRangeException(0, nx-1, x, "x dimension index");
639 }
640 else if( y>=ny || y<0 )
641 {
642 throw OutofRangeException(0, ny-1, y, "y dimension index");
643 }
644 else
645 {
646 get_data()[x + y * nx] = v;
647 update();
648
649 }
650}

References get_data(), OutofRangeException, update(), x, and y.

◆ set_value_at() [3/4]

void set_value_at ( int  x,
int  y,
int  z,
float  v 
)
inline

Set the pixel density value at coordinates (x,y,z).

This implementation does bounds checking.

Parameters
xThe x coordinate.
yThe y coordinate.
zThe z coordinate.
vThe pixel density value at coordinates (x,y,z).
Exceptions
OutofRangeExceptionwehn index out of image data's range.

Definition at line 563 of file emdata_core.h.

564{
565 if( x>=nx || x<0 )
566 {
567 throw OutofRangeException(0, nx-1, x, "x dimension index");
568 }
569 else if( y>=ny || y<0 )
570 {
571 throw OutofRangeException(0, ny-1, y, "y dimension index");
572 }
573 else if( z>=nz || z<0 )
574 {
575 throw OutofRangeException(0, nz-1, z, "z dimension index");
576 }
577 else
578 {
579 get_data()[(size_t)x + (size_t)y * (size_t)nx + (size_t)z * (size_t)nxy] = v;
580 update();
581 }
582}

References get_data(), OutofRangeException, update(), x, and y.

◆ set_value_at() [4/4]

void set_value_at ( Vec3i  loc,
float  val 
)
inline

set_value_at with Vec3i

Parameters
loclocation
vvalue

Definition at line 552 of file emdata_core.h.

552{ set_value_at(loc[0],loc[1],loc[2],val); }
void set_value_at(Vec3i loc, float val)
set_value_at with Vec3i
Definition: emdata_core.h:552

References set_value_at().

Referenced by bispecRotTransInvDirect(), bispecRotTransInvN(), EMAN::EMData::common_lines(), EMAN::RotateInFSProcessor::process_inplace(), and set_value_at().

◆ set_value_at_fast() [1/3]

void set_value_at_fast ( int  x,
float  v 
)
inline

Set the pixel density value at coordinate (x).

1D image only.

Parameters
xThe x coordinate.
vThe pixel density value at coordinate (x).

Definition at line 694 of file emdata_core.h.

695{
696 get_data()[x] = v;
697
698 update();
699}

References get_data(), update(), and x.

◆ set_value_at_fast() [2/3]

void set_value_at_fast ( int  x,
int  y,
float  v 
)
inline

Set the pixel density value at coordinates (x,y).

2D image only. The validity of x, y, is not checked.

Parameters
xThe x coordinate.
yThe y coordinate.
vThe pixel density value at coordinates (x,y).

Definition at line 660 of file emdata_core.h.

661{
662 get_data()[x + y * nx] = v;
663 update();
664}

References get_data(), update(), x, and y.

◆ set_value_at_fast() [3/3]

void set_value_at_fast ( int  x,
int  y,
int  z,
float  v 
)
inline

Set the pixel density value at coordinates (x,y,z).

The validity of x, y, and z is not checked. This implementation has no bounds checking.

Parameters
xThe x coordinate.
yThe y coordinate.
zThe z coordinate.
vThe pixel density value at coordinates (x,y,z).

Definition at line 609 of file emdata_core.h.

610{
611 get_data()[(size_t)x + (size_t)y * (size_t)nx + (size_t)z * (size_t)nxy] = v;
612 update();
613}

References get_data(), update(), x, and y.

◆ set_value_at_index()

void set_value_at_index ( size_t  i,
float  v 
)
inline

Set the pixel density value at index.

Parameters
iThe index.
vThe value.

Definition at line 621 of file emdata_core.h.

622{
623 *(rdata + i) = v;
624}

References rdata.

◆ sget_value_at() [1/4]

float EMData::sget_value_at ( int  x,
int  y 
) const

A safer, slower way to get the pixel density value at coordinates (x,y).

2D only. The validity of x, y is checked. If the coordinates are out of range, return 0;

Parameters
xThe x coordinate.
yThe y coordinate.
Returns
The pixel density value at coordinates (x,y).

Definition at line 894 of file emdata_core.cpp.

895{
896 if (x < 0 || x >= nx || y < 0 || y >= ny) {
897 return 0;
898 }
899 return get_data()[x + y * nx];
900}

References get_data(), EMAN::EMData::nx, EMAN::EMData::ny, x, and y.

◆ sget_value_at() [2/4]

float EMData::sget_value_at ( int  x,
int  y,
int  z 
) const

A safer, slower way to get the pixel density value at coordinates (x,y,z).

The validity of x, y, and z is checked. If the coordinates are out of range, return 0;

Parameters
xThe x coordinate.
yThe y coordinate.
zThe z coordinate.
Returns
The pixel density value at coordinates (x,y,z).

Definition at line 885 of file emdata_core.cpp.

886{
887 if (x < 0 || x >= nx || y < 0 || y >= ny || z < 0 || z >= nz) {
888 return 0;
889 }
890 return get_data()[(size_t)x + (size_t)y * (size_t)nx + (size_t)z * (size_t)nxy];
891}

References get_data(), EMAN::EMData::nx, EMAN::EMData::nxy, EMAN::EMData::ny, EMAN::EMData::nz, x, and y.

◆ sget_value_at() [3/4]

float EMData::sget_value_at ( size_t  i) const

A safer, slower way to get the pixel density value given an index 'i' assuming the pixles are stored in a 1D array.

The validity of i is checked. If i is out of range, return 0;

Parameters
i1D data array index.
Returns
The pixel density value

Definition at line 903 of file emdata_core.cpp.

904{
905 size_t size = nx*ny;
906 size *= nz;
907 if (i >= size) {
908 return 0;
909 }
910 return get_data()[i];
911}

References get_data(), EMAN::EMData::nx, EMAN::EMData::ny, and EMAN::EMData::nz.

◆ sget_value_at() [4/4]

float sget_value_at ( Vec3i  v)
inline

Vec3i version of save routines below.

Parameters
coord

Definition at line 465 of file emdata_core.h.

465{ return sget_value_at(v[0],v[1],v[2]); }
float sget_value_at(Vec3i v)
Vec3i version of save routines below.
Definition: emdata_core.h:465

References sget_value_at().

Referenced by sget_value_at(), and sget_value_at_interp().

◆ sget_value_at_interp() [1/2]

float EMData::sget_value_at_interp ( float  x,
float  y 
) const

Get pixel density value at interpolation of (x,y).

The validity of x, y is checked.2D image only.

Parameters
xThe x coordinate.
yThe y coordinate.
Returns
The pixel density value at coordinates (x,y).

Definition at line 914 of file emdata_core.cpp.

915{
916 int x = static_cast < int >(Util::fast_floor(xx));
917 int y = static_cast < int >(Util::fast_floor(yy));
918
919 float p1 = sget_value_at(x, y);
920 float p2 = sget_value_at(x + 1, y);
921 float p3 = sget_value_at(x, y + 1);
922 float p4 = sget_value_at(x + 1, y + 1);
923
924 float result = Util::bilinear_interpolate(p1, p2, p3, p4, xx - x, yy - y);
925 return result;
926}

References EMAN::Util::bilinear_interpolate(), EMAN::Util::fast_floor(), sget_value_at(), x, and y.

Referenced by EMAN::EMData::get_rotated_clip().

◆ sget_value_at_interp() [2/2]

float EMData::sget_value_at_interp ( float  x,
float  y,
float  z 
) const

Get the pixel density value at interpolation of (x,y,z).

The validity of x, y, and z is checked.

Parameters
xThe x coordinate.
yThe y coordinate.
zThe z coordinate.
Returns
The pixel density value at coordinates (x,y,z).

Definition at line 970 of file emdata_core.cpp.

971{
972 int x = (int) Util::fast_floor(xx);
973 int y = (int) Util::fast_floor(yy);
974 int z = (int) Util::fast_floor(zz);
975
976 float p1 = sget_value_at(x, y, z);
977 float p2 = sget_value_at(x + 1, y, z);
978 float p3 = sget_value_at(x, y + 1, z);
979 float p4 = sget_value_at(x + 1, y + 1, z);
980
981 float p5 = sget_value_at(x, y, z + 1);
982 float p6 = sget_value_at(x + 1, y, z + 1);
983 float p7 = sget_value_at(x, y + 1, z + 1);
984 float p8 = sget_value_at(x + 1, y + 1, z + 1);
985
986 float result = Util::trilinear_interpolate(p1, p2, p3, p4, p5, p6, p7, p8,
987 xx - x, yy - y, zz - z);
988
989 return result;
990}

References EMAN::Util::fast_floor(), sget_value_at(), EMAN::Util::trilinear_interpolate(), x, and y.

◆ sqrt()

EMData * EMData::sqrt ( ) const

return square root of current image

Returns
a image which is the square root of this image
Exceptions
ImageFormatExceptionreal image only

Definition at line 1084 of file emdata_core.cpp.

1085{
1086 ENTERFUNC;
1087
1088 if (is_complex()) {
1089 throw ImageFormatException("real image only");
1090 }
1091
1092 EMData * r = this->copy();
1093 float * new_data = r->get_data();
1094 float * data = get_data();
1095 size_t size = nxyz;
1096 for (size_t i = 0; i < size; ++i) {
1097 if(data[i] < 0) {
1098 throw InvalidValueException(data[i], "pixel value must be non-negative for logrithm");
1099 }
1100 else {
1101 if(data[i]) { //do nothing with pixel has value zero
1102 new_data[i] = std::sqrt(data[i]);
1103 }
1104 }
1105 }
1106
1107 r->update();
1108 return r;
1109
1110 EXITFUNC;
1111}

References copy(), ENTERFUNC, EXITFUNC, get_data(), ImageFormatException, InvalidValueException, is_complex(), EMAN::EMData::nxyz, and sqrt().

Referenced by EMAN::Quaternion::abs(), absi(), EMAN::newfile_store::add_image(), EMAN::ShapeAnalyzer::analyze(), EMAN::EMData::apply_radial_func(), bispecRotTransInvDirect(), bispecRotTransInvN(), EMAN::EMAN1Ctf::calc_amp1(), EMAN::EMAN1Ctf::calc_amplitude(), EMAN::EMData::calc_ccfx(), EMAN::XYData::calc_correlation(), EMAN::EMData::calc_dist(), EMAN::EMAN1Ctf::calc_lambda(), EMAN::MaskEdgeMeanProcessor::calc_locals(), EMAN::EMData::calc_mutual_correlation(), EMAN::EMAN1Ctf::calc_noise(), EMAN::EMData::calc_radial_dist(), EMAN::NormalizeUnitProcessor::calc_sigma(), calc_sigma_diff(), EMAN::PointArray::calc_total_length(), EMAN::CccCmp::cmp(), EMAN::DotCmp::cmp(), EMAN::TomoCccCmp::cmp(), EMAN::TomoWedgeCccCmp::cmp(), EMAN::TomoWedgeFscCmp::cmp(), EMAN::TomoFscCmp::cmp(), EMAN::QuadMinDotCmp::cmp(), EMAN::EMData::common_lines(), EMAN::EMData::common_lines_real(), EMAN::EMAN1Ctf::compute_1d(), EMAN::EMData::compute_missingwedge(), EMAN::DoGFourierProcessor::create_radial_func(), EMAN::MatchSFProcessor::create_radial_func(), EMAN::SetSFProcessor::create_radial_func(), EMAN::Point3::distanceFromOrigin(), EMAN::Point3::distanceTo(), DistToLine(), EMAN::FourierReconstructor::do_compare_slice_work(), EMAN::WienerFourierReconstructor::do_compare_slice_work(), EMAN::ImageAverager::finish(), EMAN::LocalWeightAverager::finish(), EMAN::SigmaAverager::finish(), EMAN::nn4_ctfwReconstructor::finish(), EMAN::nn4_ctfwsReconstructor::finish(), EMAN::RealMedianReconstructor::finish(), EMAN::nnSSNR_Reconstructor::finish(), EMAN::nn4_ctfReconstructor::finish(), EMAN::nn4_ctf_rectReconstructor::finish(), EMAN::nnSSNR_ctfReconstructor::finish(), EMAN::PointArray::fit_helix(), EMAN::SaffOrientationGenerator::gen_orientations(), get_attr(), get_fft_amplitude2D(), EMAN::Randnum::get_gauss_rand(), EMAN::SaffOrientationGenerator::get_orientations_tally(), EMAN::Transform::get_rotation(), EMAN::Util::get_stats(), EMAN::Util::get_stats_cstyle(), EMAN::EMUtil::getRenderMinMax(), EMAN::Util::hypot3(), EMAN::FourierInserter3DMode9::insert_pixel(), EMAN::FourierInserter3DMode10::insert_pixel(), EMAN::nn4_rectReconstructor::insert_slice(), EMAN::GaussFFTProjector::interp_ft_3d(), EMAN::EMAN2Ctf::lambda(), EMAN::Vec4< Type >::length(), EMAN::Vec3< Type >::length(), EMAN::Vec2< Type >::length(), EMAN::ScreenVector::length(), EMAN::Vector3::length(), EMAN::Vector4::length(), EMAN::EMData::little_big_dot(), EMAN::PointArray::mask_asymmetric_unit(), EMAN::EMData::max_3D_pixel_error(), EMAN::Quaternion::normalize(), EMAN::Vector3::normalize(), EMAN::ReconstructorVolumeData::normalize_threed(), EMAN::PointArray::pdb2mrc_by_summation(), EMAN::FourierReconstructor::preprocess_slice(), EMAN::FourierIterReconstructor::preprocess_slice(), EMAN::BispecSliceProcessor::process(), EMAN::SubtractOptProcessor::process(), EMAN::ConvolutionKernelProcessor::process(), EMAN::MaskSoftProcessor::process_dist_pixel(), EMAN::MaskGaussProcessor::process_dist_pixel(), EMAN::MakeRadiusProcessor::process_dist_pixel(), EMAN::RadialProcessor::process_dist_pixel(), EMAN::FourierAnlProcessor::process_inplace(), EMAN::Axis0FourierProcessor::process_inplace(), EMAN::FFTPeakProcessor::process_inplace(), EMAN::BeamstopProcessor::process_inplace(), EMAN::NormalizeMaskProcessor::process_inplace(), EMAN::NormalizeRowProcessor::process_inplace(), EMAN::NormalizeToLeastSquareProcessor::process_inplace(), EMAN::AddRandomNoiseProcessor::process_inplace(), EMAN::PaintProcessor::process_inplace(), EMAN::SetIsoPowProcessor::process_inplace(), EMAN::SmartMaskProcessor::process_inplace(), EMAN::TestImagePureGaussian::process_inplace(), EMAN::TestImageFourierNoiseGaussian::process_inplace(), EMAN::TestImageFourierGaussianBand::process_inplace(), EMAN::TestImageFourierNoiseProfile::process_inplace(), EMAN::CTFSNRWeightProcessor::process_inplace(), EMAN::TestImageGaussian::process_inplace(), EMAN::TestImageSinewaveCircular::process_inplace(), EMAN::RotateInFSProcessor::process_inplace(), EMAN::BoxSigmaProcessor::process_pixel(), EMAN::MaskGaussNonuniformProcessor::process_pixel(), EMAN::PolyMaskProcessor::process_pixel(), EMAN::ValueSqrtProcessor::process_pixel(), EMAN::PointArray::projection_by_summation(), EMAN::Quaternion::Quaternion(), refalin3d_perturbquat(), EMAN::PointArray::replace_by_summation(), EMAN::PointArray::set_from_density_map(), sqrt(), EMAN::EMAN2Ctf::stos2(), EMAN::TransformProcessor::transform(), EMAN::EMData::unwrap_largerR(), EMAN::KMeansAnalyzer::update_centers(), EMAN::EMData::update_stat(), EMAN::MrcIO::update_stats(), EMAN::Util::windowdot(), EMAN::RT3DGridAligner::xform_align_nbest(), EMAN::RT3DSphereAligner::xform_align_nbest(), and EMAN::EMAN2Ctf::zero().

◆ sub() [1/2]

void sub ( const EMData &  image)

subtract a same-size image from this image pixel by pixel.

Parameters
imageThe image subtracted from 'this' image.
Exceptions
ImageFormatExceptionIf the 2 images are not same size.

◆ sub() [2/2]

void sub ( float  f)

◆ subsquare()

void subsquare ( const EMData &  image)

subtract the squared value of each pixel from a same-size image to this image.

Parameters
imageThe image whose square is subtracted from 'this' image.
Exceptions
ImageFormatExceptionIf the 2 images are not same size.

◆ to_one()

void EMData::to_one ( )

set all the pixel values = 1.

Definition at line 1482 of file emdata_core.cpp.

1483{
1484 ENTERFUNC;
1485
1486 if (is_complex()) {
1487 set_ri(true);
1488 }
1489 else {
1490 set_ri(false);
1491 }
1492 to_value(1.0);
1493
1494 update();
1495 EXITFUNC;
1496}
void to_value(const float &value)
set all the pixel values to a value.
void set_ri(bool is_ri)
Mark this image as a real/imaginary format complex image.

References ENTERFUNC, EXITFUNC, is_complex(), set_ri(), to_value(), and update().

◆ to_value()

void EMData::to_value ( const float &  value)

set all the pixel values to a value.

Definition at line 1498 of file emdata_core.cpp.

1499{
1500 ENTERFUNC;
1501
1502#ifdef EMAN2_USING_CUDA
1503 if(EMData::usecuda == 1 && cudarwdata){
1504 to_value_cuda(cudarwdata, value, nx, ny, nz);
1505 return;
1506 }
1507#endif // EMAN2_USING_CUDA
1508 float* data = get_data();
1509
1510 //the em_memset has segfault for >8GB image, use std::fill() instead, though may be slower
1511// if ( value != 0 ) std::fill(data,data+get_size(),value);
1512// else EMUtil::em_memset(data, 0, nxyz * sizeof(float)); // This might be faster, I don't know
1513
1514 std::fill(data,data+get_size(),value);
1515
1516 update();
1517 EXITFUNC;
1518}
void to_value_cuda(float *data, const float value, const int nx, const int ny, const int nz)
size_t get_size() const
Get the number of allocated floats in the image (nx*ny*nz)

References ENTERFUNC, EXITFUNC, get_data(), get_size(), EMAN::EMData::nx, EMAN::EMData::ny, EMAN::EMData::nz, to_value_cuda(), and update().

Referenced by to_one(), and to_zero().

◆ to_zero()

void EMData::to_zero ( )

Set all the pixel value = 0.

Definition at line 1465 of file emdata_core.cpp.

1466{
1467 ENTERFUNC;
1468
1469 if (is_complex()) {
1470 set_ri(true);
1471 }
1472 else {
1473 set_ri(false);
1474 }
1475
1476 //EMUtil::em_memset(get_data(), 0, nxyz * sizeof(float));
1477 to_value(0.0);
1478 update();
1479 EXITFUNC;
1480}

References ENTERFUNC, EXITFUNC, is_complex(), set_ri(), to_value(), and update().

Referenced by EMAN::EMData::EMData(), and EMAN::IterAverager::finish().

◆ update_min()

void update_min ( const EMData &  image)

Replaces the value of each pixel with the minimum of the current value and the value in the provided image.

An Averager can be used to do this across many images. This permits a strategy where the intermediate values are needed, not just the final minimum.

Parameters
imageThe image 'this' image divided by.
Exceptions
ImageFormatExceptionIf the 2 images are not same size.