EMAN::EMData Class Reference
[unit test in Python]

EMData stores an image's data and defines core image processing routines. More...

#include <emdata.h>

Collaboration diagram for EMAN::EMData:

Collaboration graph
[legend]
List of all members.

Public Types

 FFT_OUT_OF_PLACE
 FFT_IN_PLACE
 WINDOW_OUT_OF_PLACE
 WINDOW_IN_PLACE
enum  FFTPLACE { FFT_OUT_OF_PLACE, FFT_IN_PLACE }
enum  WINDOWPLACE { WINDOW_OUT_OF_PLACE, WINDOW_IN_PLACE }

Public Member Functions

void read_image (const string &filename, int img_index=0, bool header_only=false, const Region *region=0, bool is_3d=false)
 read an image file and stores its information to this EMData object.
void write_image (const string &filename, int img_index=0, EMUtil::ImageType imgtype=EMUtil::IMAGE_UNKNOWN, bool header_only=false, const Region *region=0, EMUtil::EMDataType filestoragetype=EMUtil::EM_FLOAT, bool use_host_endian=true)
 write the header and data out to an image.
void append_image (const string &filename, EMUtil::ImageType imgtype=EMUtil::IMAGE_UNKNOWN, bool header_only=false)
 append to an image file; If the file doesn't exist, create one.
void write_lst (const string &filename, const string &reffile="", int refn=-1, const string &comment="")
 Append data to a LST image file.
void print_image (const string str=string(""), ostream &out=std::cout)
 Print the image data to a file stream (standard out by default).
EMDataget_fft_amplitude ()
 return the amplitudes of the FFT including the left half
EMDataget_fft_amplitude2D ()
 return the amplitudes of the 2D FFT including the left half PRB
Exceptions:
ImageFormatException If the image is not a complex image.

EMDataget_fft_phase ()
 return the phases of the FFT including the left half
float * get_data () const
 Get the image pixel density data in a 1D float array.
const float *const get_const_data () const
 Get the image pixel density data in a 1D float array - const version of get_data.
void set_data (float *data, const int x, const int y, const int z)
 Set the data explicitly data pointer must be allocated using malloc!
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.
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.
void update ()
 Mark EMData as changed, statistics, etc will be updated at need.
bool has_ctff () const
 check whether the image physical file has the CTF info or not.
float calc_center_density ()
 Calculates the density value at the peak of the image histogram, sort of like the mode of the density.
float calc_sigma_diff ()
 Calculates sigma above and below the mean and returns the difference between them.
IntPoint calc_min_location () const
 Calculates the coordinates of the minimum-value pixel.
IntPoint calc_max_location () const
 Calculates the coordinates of the maximum-value pixel.
IntPoint calc_max_location_wrap (const int maxshiftx=-1, const int maxshifty=-1, const int maxshiftz=-1)
 Calculates the wrapped coordinates of the maximum value This function is useful in the context of Fourier correlation you can call this function to find the correct translational shift when using calc_ccf etc.
FloatPoint calc_center_of_mass ()
 Calculate the center of mass using an algorithm written by S Ludtke.
int calc_min_index () const
 Calculates the index of minimum-value pixel when assuming all pixels are in a 1D array.
int calc_max_index () const
 Calculates the index of maximum-value pixel when assuming all pixels are in a 1D array.
vector< Pixelcalc_highest_locations (float threshold)
 Calculate and return a sorted list of pixels whose values are above a specified threshold.
vector< Pixelcalc_n_highest_locations (int n)
 Calculate and return a sorted list of N highest pixels in the map.
float get_edge_mean () const
 Calculates the mean pixel values around the (1 pixel) edge of the image.
float get_circle_mean ()
 Calculates the circular edge mean by applying a circular mask on 'this' image.
Ctfget_ctf () const
 Get ctf parameter of this image.
void set_ctf (Ctf *ctf)
 Set the CTF parameter of this image.
Vec3f get_translation () const
 Get 'this' image's translation vector from the original location.
void set_translation (const Vec3f &t)
 Set 'this' images' translation vector from the original location.
void set_translation (float dx, float dy, float dz)
 Set 'this' images' translation vector from the original location.
Transform get_transform () const
 Get the 3D orientation of 'this' image.
void set_rotation (float az, float alt, float phi)
 Define the 3D orientation of this particle, also used to indicate relative rotations for reconstructions.
void set_rotation (const Transform3D &t3d)
 Define the 3D orientation of this particle Orientation information is extracted from a Transform3D object and stored internally in EMAN (az,alt,phi) format.
void set_size (int nx, int ny=1, int nz=1)
 Resize this EMData's main board memory pointer.
void set_complex_size (int nx, int ny=1, int nz=1)
 Resize 'this' complex image.
void set_path (const string &new_path)
 Set the path.
void set_pathnum (int n)
 Set the number of paths.
MArray2D get_2dview () const
 Get image raw pixel data in a 2D multi-array format.
MArray3D get_3dview () const
 Get image raw pixel data in a 3D multi-array format.
MCArray2D get_2dcview () const
 Get complex image raw pixel data in a 2D multi-array format.
MCArray3D get_3dcview () const
 Get complex image raw pixel data in a 3D multi-array format.
MCArray3Dget_3dcviewptr () const
 Get pointer to a complex image raw pixel data in a 3D multi-array format.
MArray2D get_2dview (int x0, int y0) const
 Get image raw pixel data in a 2D multi-array format.
MArray3D get_3dview (int x0, int y0, int z0) const
 Get image raw pixel data in a 3D multi-array format.
MCArray2D get_2dcview (int x0, int y0) const
 Get complex image raw pixel data in a 2D multi-array format.
MCArray3D get_3dcview (int x0, int y0, int z0) const
 Get complex image raw pixel data in a 3D multi-array format.
EMObject get_attr (const string &attr_name) const
 The generic way to get any image header information given a header attribute name.
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.
void set_attr (const string &key, EMObject val)
 Set a header attribute's value.
void set_attr_python (const string &key, EMObject val)
 Set a header attribute's value from Python.
bool has_attr (const string &key) const
 Ask if the header has a particular attribute.
Dict get_attr_dict () const
 Get the image attribute dictionary containing all the image attribute names and attribute values.
void set_attr_dict (const Dict &new_dict)
 Merge the new values with the existing dictionary.
void del_attr (const string &attr_name)
 Delete the attribute from dictionary.
void del_attr_dict (const vector< string > &del_keys)
 Delete the attributes from the dictionary.
int get_xsize () const
 Get the image x-dimensional size.
int get_ysize () const
 Get the image y-dimensional size.
int get_zsize () const
 Get the image z-dimensional size.
size_t get_size () const
 Get the number of allocated floats in the image (nx*ny*nz).
vector< float > get_data_as_vector () const
 Get the pixel data as a vector.
int get_ndim () const
 Get image dimension.
bool is_shuffled () const
 Has this image been shuffled?
bool is_FH () const
 Is this a FH image?
bool is_complex () const
 Is this a complex image?
bool is_real () const
 Is this a real image?
void set_shuffled (bool is_shuffled)
 Mark this image as a shuffled image.
void set_FH (bool is_FH)
 Mark this complex image as a FH image.
void set_complex (bool is_complex)
 Mark this image as a complex image.
bool is_complex_x () const
 Is this image a 1D FFT image in X direction?
void set_complex_x (bool is_complex_x)
 Marks this image a 1D FFT image in X direction.
bool is_flipped () const
 Is this image flipped?
void set_flipped (bool is_flipped)
 Mark this image as flipped.
bool is_ri () const
 Is this image a real/imaginary format complex image?
void set_ri (bool is_ri)
 Mark this image as a real/imaginary format complex image.
bool is_fftpadded () const
 Is this image already extended along x for ffts?
void set_fftpad (bool is_fftpadded)
 Mark this image as already extended along x for ffts.
bool is_fftodd () const
 Does this image correspond to a (real-space) odd nx?
void set_fftodd (bool is_fftodd)
 Mark this image as having (real-space) odd nx.
void set_nxc (int nxc)
 Set the number of complex elements along x.
int get_flags () const
void set_flags (int f)
int get_changecount () const
void set_changecount (int c)
int get_xoff () const
int get_yoff () const
int get_zoff () const
void set_xyzoff (int x, int y, int z)
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 make this function public for access from the Processors (David Woolford).
string get_path () const
int get_pathnum () const
std::string get_data_pickle () const
void set_data_pickle (std::string vf)
int get_supp_pickle () const
void set_supp_pickle (int i)
vector< Vec3imask_contig_region (const float &val, const Vec3i &seed)
void process_inplace (const string &processorname, const Dict &params=Dict())
 Apply a processor with its parameters on this image.
void process_inplace (Processor *p)
 Call the process_inplace with an instance od Processor, usually this instancecan be get by (in Python) Processors.get("name", {'k':v, 'k':v}).
EMDataprocess (const string &processorname, const Dict &params=Dict()) const
 Apply a processor with its parameters on a copy of this image, return result as a a new image.
EMDataprocess (Processor *p) const
 Call the process with an instance od Processor, usually this instance can be get by (in Python) Processors.get("name", {'k':v, 'k':v}).
float cmp (const string &cmpname, EMData *with, const Dict &params=Dict())
 Compare this image with another image.
EMDataalign (const string &aligner_name, EMData *to_img, const Dict &params=Dict(), const string &cmp_name="dot", const Dict &cmp_params=Dict())
 Align this image with another image and return the result image.
vector< Dictxform_align_nbest (const string &aligner_name, EMData *to_img, const Dict &params=Dict(), const unsigned int nsoln=1, const string &cmp_name="dot", const Dict &cmp_params=Dict())
 Align this image with another image, return the parameters of the "n best" solutions See Aligner::xform_align_nbest for more comments.
EMDataproject (const string &projector_name, const Dict &params=Dict())
 Calculate the projection of this image and return the result.
EMDataproject (const string &projector_name, const Transform &t3d)
 Calculate the projection of this image and return the result.
EMDatabackproject (const string &projector_name, const Dict &params=Dict())
 Calculate the backprojection of this image (stack) and return the result.
EMDatado_fft () const
 return the fast fourier transform (FFT) image of the current image.
EMDatado_fft_inplace ()
 Do FFT inplace.
EMDatado_ift ()
 return the inverse fourier transform (IFT) image of the current image.
EMDatado_ift_inplace ()
std::string render_amp8 (int x, int y, int xsize, int ysize, int bpl, float scale, int min_gray, int max_gray, float min_render, float max_render, float gamma, int flags)
 Render the image into an 8-bit image.
std::string render_ap24 (int x, int y, int xsize, int ysize, int bpl, float scale, int min_gray, int max_gray, float min_render, float max_render, float gamma, int flags)
 Render the image into an 8-bit image.
void render_amp24 (int x, int y, int xsize, int ysize, int bpl, float scale, int min_gray, int max_gray, float min_render, float max_render, void *ref, void cmap(void *, int coord, unsigned char *tri))
 Render the image into a 24-bit image.
void ri2ap ()
 convert the complex image from real/imaginary to amplitude/phase
void ap2ri ()
 convert the complex image from amplitude/phase to real/imaginary
void ri2inten ()
 convert the complex image from real/imaginary to Intensity/0.
EMDatabispecRotTransInvN (int N, int NK)
 This computes the rotational and translational bispectral invariants of an image.
EMDatabispecRotTransInvDirect (int type=0)
 This computes the rotational and translational bispectral invariants of an image.
void insert_clip (const EMData *const block, const IntPoint &origin)
 Insert a clip into this image.
void insert_scaled_sum (EMData *block, const FloatPoint &center, float scale=1.0, float mult_factor=1.0)
 Add a scaled image into another image at a specified location.
EMDatacopy () const
 Make a copy of this image including both data and header.
EMDatacopy_head () const
 Make an image with a copy of the current image's header.
void add (float f, int keepzero=0)
 add a number to each pixel value of the image.
void add (const EMData &image)
 add a same-size image to this image pixel by pixel.
void addsquare (const EMData &image)
 add the squared value of each pixel from a same-size image to this image.
void sub (float f)
 subtract a float number to each pixel value of the image.
void sub (const EMData &image)
 subtract a same-size image from this image pixel by pixel.
void subsquare (const EMData &image)
 subtract the squared value of each pixel from a same-size image to this image.
void mult (int n)
 multiply an integer number to each pixel value of the image.
void mult (float f)
 multiply a float number to each pixel value of the image.
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.
void mult_complex_efficient (const EMData &em, const int radius)
void div (float f)
 make each pixel value divided by a float number.
void div (const EMData &image)
 make each pixel value divided by pixel value of another same-size image.
void to_zero ()
 Set all the pixel value = 0.
void to_one ()
 set all the pixel values = 1.
void to_value (const float &value)
 set all the pixel values to a value.
float dot (EMData *with)
 Dot product 2 images.
EMDataget_row (int row_index) const
 Get one row of a 1D/2D image.
void set_row (const EMData *data, int row_index)
 Set one row of a 1D/2D image.
EMDataget_col (int col_index) const
 Get one column of a 2D images.
void set_col (const EMData *data, int col_index)
 Set one column of a 2D image.
float get_value_at (int x, int y, int z) const
 Get the pixel density value at coordinates (x,y,z).
float get_value_at (int x, int y) const
 Get the pixel density value at coordinates (x,y).
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.
std::complex< float > get_complex_at (const int &x, const int &y) const
 Get complex<float> value at x,y.
std::complex< float > get_complex_at (const int &x, const int &y, const int &z) const
 Get complex<float> value at x,y,z.
size_t get_complex_index (const int &x, const int &y, const int &z) const
 Get complex<float> index for coords x,y,z.
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 (const int &x, const int &y, const std::complex< float > &val)
 Set complex<float> value at x,y.
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.
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.
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.
float get_value_at_wrap (int x, int y, int z) const
 Get the pixel density value at coordinates (x,y,z).
float & get_value_at_wrap (int x, int y, int z)
float get_value_at_wrap (int x, int y) const
 Get the pixel density value at coordinates (x,y).
float & get_value_at_wrap (int x, int y)
float get_value_at_wrap (int x) const
 Get the pixel density value at coordinates (x).
float & get_value_at_wrap (int x)
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).
float sget_value_at (int x, int y) const
 A safer, slower way to get the pixel density value at coordinates (x,y).
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.
float sget_value_at_interp (float x, float y) const
 Get pixel density value at interpolation of (x,y).
float sget_value_at_interp (float x, float y, float z) const
 Get the pixel density value at interpolation of (x,y,z).
void set_value_at (int x, int y, int z, float v)
 Set the pixel density value at coordinates (x,y,z).
void set_value_at_fast (int x, int y, int z, float v)
 Set the pixel density value at coordinates (x,y,z).
void set_value_at (int x, int y, float v)
 Set the pixel density value at coordinates (x,y).
void set_value_at_fast (int x, int y, float v)
 Set the pixel density value at coordinates (x,y).
void set_value_at (int x, float v)
 Set the pixel density value at coordinate (x).
void set_value_at_fast (int x, float v)
 Set the pixel density value at coordinate (x).
void free_memory ()
 Free memory associated with this EMData Called in destructor and in assignment operator.
EMDataoperator+= (float n)
EMDataoperator-= (float n)
EMDataoperator *= (float n)
EMDataoperator/= (float n)
EMDataoperator+= (const EMData &em)
EMDataoperator-= (const EMData &em)
EMDataoperator *= (const EMData &em)
EMDataoperator/= (const EMData &em)
bool operator== (const EMData &that) const
float & operator() (const int ix, const int iy, const int iz) const
 Overload operator() for array indexing.
float & operator() (const int ix, const int iy) const
float & operator() (const int ix) const
void set_array_offsets (const int xoff_=0, const int yoff_=0, const int zoff_=0)
 Set the array offsets.
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.
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
EMDatasqrt () const
 return square root of current image
EMDatalog () const
 return natural logarithm image for a image
EMDatalog10 () const
 return base 10 logarithm image for a image
EMDatareal () 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.
EMDataimag () const
 return imaginary part of a complex image as a real image format.
EMDataabsi () const
 For a real image, it returns a same size image with abs() of each pixel.
EMDataamplitude () const
 return amplitude part of a complex image as a real image format
EMDataphase () const
 return phase part of a complex image as a real image format
EMDatareal2complex (float img=0.0f) const
 create a complex image from a real image, this complex image is in real/imaginary format
EMDatareal2FH (float OverSamplekB)
 returns the fourier harmonic transform (FH) image of the current image (in real space).
EMDataFH2F (int Size, float OverSamplekB, int IntensityFlag=0)
 returns the fourier version of the image from the FH version.
EMDataFH2Real (int Size, float OverSamplekB, int IntensityFlag=0)
 returns the real version of the image from the FH version.
EMDatarotavg ()
 Create a (1-D) rotationally averaged image.
EMDatarotavg_i ()
 Create a 2-D or 3-D rotationally averaged image.
EMDatamult_radial (EMData *radial)
 Multiply radially a 2-D or 3-D image by a 1-D image.
vector< float > cog ()
 Calculates the Center of Gravity and the Radius of Gyration of the image.
vector< float > calc_fourier_shell_correlation (EMData *with, float w=1.0f)
 Calculate CCF in Fourier space as a function of spatial frequency between a pair of 2-3D images (corners not included).
EMDataaverage_circ_sub () const
 Subtract average outside of a circle.
void onelinenn (int j, int n, int n2, EMData *wptr, EMData *bi, const Transform &tf)
 Helper function for method nn.
void onelinenn_mult (int j, int n, int n2, EMData *wptr, EMData *bi, const Transform &tf, int mult)
void nn (EMData *wptr, EMData *myfft, const Transform &tf, int mult=1)
 Nearest Neighbor interpolation.
void nn_SSNR (EMData *wptr, EMData *wptr2, EMData *myfft, const Transform &tf, int mult=1)
 Nearest Neighbor interpolation, meanwhile return necessary data such as Kn, sum_k(F_k^n) ans sum_k(|F_k^n|^2) Modifies the current object.
void nn_SSNR_ctf (EMData *wptr, EMData *wptr2, EMData *wptr3, EMData *myfft, const Transform &tf, int mult=1)
 Nearest Neighbor interpolation, meanwhile return necessary data such as Kn, sum_k(F_k^n) ans sum_k(|F_k^n|^2) Modifies the current object.
void symplane0 (EMData *norm)
 Calculate Wiener summation from the inserted 2D slice put the summation into 3D grids using nearest neighbour approximation a.
void symplane1 (EMData *norm, EMData *norm2)
 Symmetrize plane 0 Modifies the current object.
void symplane2 (EMData *norm, EMData *norm2, EMData *norm3)
 Symmetrize plane 0 Modifies the current object.
void onelinenn_ctf (int j, int n, int n2, EMData *w, EMData *bi, const Transform &tf, int mult)
 Helper function for method nn4_ctf.
void nn_ctf (EMData *w, EMData *myfft, const Transform &tf, int mult)
 Nearest Neighbor interpolation.
void onelinenn_ctf_applied (int j, int n, int n2, EMData *w, EMData *bi, const Transform &tf, int mult)
 Helper function for method nn4_ctf.
void nn_ctf_applied (EMData *w, EMData *myfft, const Transform &tf, int mult)
 Nearest Neighbor interpolation.
void symplane0_ctf (EMData *w)
 Symmetrize plane 0 Modifies the current object.
EMDatasymvol (string symmetry)
 Symmetrize volume in real space.
EMDatarot_scale_trans2D (float ang, float delx=0.0f, float dely=0.0f, float scale=1.0f)
 Rotate-Shift-Scale-Circulantly image.
EMDatarot_scale_trans2D_background (float ang, float delx=0.0f, float dely=0.0f, float scale=1.0f)
 Rotate-Shift-Scale image.
EMDatarot_scale_trans (const Transform &RA)
 Rotate-Shift-Scale-Circulantly image.
EMDatarot_scale_trans_background (const Transform &RA)
 Rotate-Shift-Scale image.
float cm_euc (EMData *sinoj, int n1, int n2)
 euclidean distance between two line
EMDatarot_scale_conv (float ang, float delx, float dely, Util::KaiserBessel &kb, float scale=1.0)
 Rotate-Shift-Scale-Circulantly image using convolution.
EMDatadownsample (Util::sincBlackman &kb, float scale=1.0)
EMDatarot_scale_conv7 (float ang, float delx, float dely, Util::KaiserBessel &kb, float scale_input)
EMDatarot_scale_conv_new (float ang, float delx, float dely, Util::KaiserBessel &kb, float scale=1.0)
EMDatarot_scale_conv_new_background (float ang, float delx, float dely, Util::KaiserBessel &kb, float scale=1.0)
float get_pixel_conv (float delx, float dely, float delz, Util::KaiserBessel &kb)
 Get pixel value image using convolution.
float get_pixel_filtered (float delx, float dely, float delz, Util::sincBlackman &kb)
float get_pixel_conv7 (float delx, float dely, float delz, Util::KaiserBessel &kb)
float getconvpt2d_kbi0 (float x, float y, Util::KaiserBessel::kbi0_win win, int size=7)
 Value of 2-D analytic masking (or 2-D convolution) at off-grid point.
void fft_shuffle ()
 fft_shuffle -- Shuffle a Fourier image to put the origin at (0,ny/2)
void pad_corner (float *pad_image)
void shuffle_pad_corner (float *pad_image)
std::complex< float > extractpoint (float xin, float yin, Util::KaiserBessel &kb)
 extractpoint -- Gridding convolution
EMDataextract_plane (const Transform &tf, Util::KaiserBessel &kb)
 extractplane -- Gridding convolution in 3D along a plane
EMDatafouriergridrot2d (float ang, float scale, Util::KaiserBessel &kb)
EMDatafouriergridrot_shift2d (float ang, float sx, float sy, Util::KaiserBessel &kb)
void divkbsinh (const Util::KaiserBessel &kb)
 divkbsinh -- Divide image by a Kaiser-Bessel sinh window.
vector< float > max_search ()
 Search specified number peaks in 1D, 2D, or 3D real images.
vector< float > peak_search (int ml, float invert)
vector< float > phase_cog ()
 Calculate the Phase approximation to center of gravity This operations works for 1-2-3-d images.
float find_3d_threshold (float mass, float pixel_size)
vector< float > peak_ccf (float hf_p)
 Peak (with a radius of hf_p) search for particle picking:.
EMDataget_pow (float n_pow)
EMDataconjg ()
EMDataextractline (Util::KaiserBessel &kb, float nuxnew, float nuynew)
EMDatadelete_disconnected_regions (int ix=0, int iy=0, int iz=0)
 Delete disconnected regions in a binary image.
EMDatahelicise (float pixel_size, float dp, float dphi, float section_use=1.0f, float radius=-1.0f, float minrad=-1.0f)
 Apply helical symmetry.
void depad ()
 De-pad, and and remove Fourier extension convenience function.
void depad_corner ()
 De-pad, and and remove Fourier extension convenience function.
EMDatanorm_pad (bool do_norm, int npad=1, int valtype=0)
 Normalize, pad, and Fourier extend convenience function.
void center_origin ()
void center_origin_yz ()
void center_origin_fft ()
 Multiply a Fourier image by (-1)**(ix+iy+iz) to center it.
EMDataFourInterpol (int nxni, int nyni=0, int nzni=0, bool RetReal=true)
EMDataFourTruncate (int nxni, int nyni=0, int nzni=0, bool RetReal=true)
 Truncate Fourier transform of an image, it will reduce its size.
EMDataFour_ds (int nxni, int nyni=0, int nzni=0, bool RetReal=true)
EMDataFour_shuf_ds_cen_us (int nxni, int nyni=0, int nzni=0, bool RetReal=true)
EMDatafilter_by_image (EMData *image, bool RetReal=true)
EMDatareplace_amplitudes (EMData *image, bool RetReal=true)
 EMData ()
 Construct an empty EMData instance.
 ~EMData ()
 EMData (const string &filename, int image_index=0)
 Construct from an image file.
 EMData (int nx, int ny, int nz=1, bool is_real=true)
 # makes an image of the specified size, either real or complex.
 EMData (float *data, const int nx, const int ny, const int nz, const Dict &attr_dict=Dict())
 Construction from a data pointer, dimensions must be supplied.
 EMData (const EMData &that)
 Construct from an EMData (copy constructor).
EMDataoperator= (const EMData &that)
 EMData assignment operator Performs a deep copy.
EMDataget_clip (const Region &area, const float fill=0) const
 Get an inclusive clip.
void clip_inplace (const Region &area, const float &fill_value=0)
 Clip the image inplace - clipping region must be smaller than the current region internally memory is reallocated
Exceptions:
ImageDimensionException if any of the dimensions of the argument region are negative.

EMDataget_top_half () const
 Get the top half of this 3D image.
EMDataget_rotated_clip (const Transform &xform, const IntSize &size, float scale=1.0)
 This will extract an arbitrarily oriented and sized region from the image.
EMDatawindow_center (int l)
 Window the center of an image.
float * setup4slice (bool redo=true)
 Set up for fftslice operations.
void scale (float scale_factor)
 scale the image by a factor.
void translate (float dx, float dy, float dz)
 Translate this image.
void translate (const Vec3f &translation)
 Translate this image.
void translate (int dx, int dy, int dz)
 Translate this image.
void translate (const Vec3i &translation)
 Translate this image.
void rotate (const Transform3D &t)
 Rotate this image.
float max_3D_pixel_error (const Transform &t1, const Transform &t2, float r)
void rotate (float az, float alt, float phi)
 Rotate this image.
void rotate_translate (const Transform3D &t)
 Rotate then translate the image.
void transform (const Transform &t)
 Transform the image.
void rotate_translate (const Transform &t)
 Apply a transformation to the image.
void rotate_translate (float az, float alt, float phi, float dx, float dy, float dz)
 Rotate then translate the image.
void rotate_translate (float az, float alt, float phi, float dx, float dy, float dz, float pdx, float pdy, float pdz)
 Rotate then translate the image.
void rotate_x (int dx)
 This performs a translation of each line along x with wraparound.
void rotate_180 ()
 Fast rotation by 180 degrees.
double dot_rotate_translate (EMData *with, float dx, float dy, float da, const bool mirror=false)
 dot product of 2 images.
EMDatalittle_big_dot (EMData *little_img, bool do_sigma=false)
 This does a normalized dot product of a little image with a big image using real-space methods.
EMDatado_radon ()
 Radon Transform: an algorithm that transforms an original image into a series of equiangular projections.
EMDatacalc_ccf (EMData *with, fp_flag fpflag=CIRCULANT, bool center=false)
 Calculate Cross-Correlation Function (CCF).
void zero_corner_circulant (const int radius=0)
 Zero the pixels in the bottom left corner of the image If radius is greater than 1, than circulant zeroing occurs assuming that the center of operation starts in the bottom left corner and proceed outwards to the NE and backwards in a circulant fashion towards the SW.
EMDatacalc_ccfx (EMData *const with, int y0=0, int y1=-1, bool nosum=false)
 Calculate Cross-Correlation Function (CCF) in the x-direction and adds them up, result in 1D.
EMDatamake_rotational_footprint (bool unwrap=true)
 Makes a 'rotational footprint', which is an 'unwound' autocorrelation function.
EMDatamake_rotational_footprint_e1 (bool unwrap=true)
EMDatamake_rotational_footprint_cmc (bool unwrap=true)
EMDatamake_footprint (int type=0)
 Makes a 'footprint' for the current image.
EMDatacalc_mutual_correlation (EMData *with, bool tocorner=false, EMData *filter=0)
 Calculates mutual correlation function (MCF) between 2 images.
EMDataunwrap (int r1=-1, int r2=-1, int xs=-1, int dx=0, int dy=0, bool do360=false, bool weight_radial=true) const
 Maps to polar coordinates from Cartesian coordinates.
EMDataunwrap_largerR (int r1, int r2, int xs, float rmax_f)
void apply_radial_func (float x0, float dx, vector< float >array, bool interp=true)
 multiplies by a radial function in fourier space.
vector< float > calc_radial_dist (int n, float x0, float dx, bool inten)
 calculates radial distribution.
vector< float > calc_radial_dist (int n, float x0, float dx, int nwedge, bool inten)
 calculates radial distribution subdivided by angle.
void cconj ()
 Replace the image its complex conjugate.
void add_incoherent (EMData *obj)
 Adds 'obj' to 'this' incoherently.
vector< float > calc_hist (int hist_size=128, float hist_min=0, float hist_max=0, const float &brt=0.0f, const float &cont=1.0f)
 Calculates the histogram of 'this' image.
vector< float > calc_az_dist (int n, float a0, float da, float rmin, float rmax)
 Caculates the azimuthal distributions.
float calc_dist (EMData *second_img, int y_index=0) const
 Calculates the distance between 2 vectors.
EMDatacalc_flcf (EMData *with)
 Calculates the cross correlation with local normalization between 2 images.
EMDatacalc_fast_sigma_image (EMData *mask)
 Calculates the local standard deviation (sigma) image using the given mask image.
EMDataconvolute (EMData *with)
 Convolutes 2 data sets.
void common_lines (EMData *image1, EMData *image2, int mode=0, int steps=180, bool horizontal=false)
 Finds common lines between 2 complex images.
void common_lines_real (EMData *image1, EMData *image2, int steps=180, bool horizontal=false)
 Finds common lines between 2 real images.
void cut_slice (const EMData *const map, const Transform &tr, bool interpolate=true)
 cut a 2D slice out of a real 3D map.
void uncut_slice (EMData *const map, const Transform &tr) const
 Opposite of the cut_slice().
int getResolution () const
 function for MarchingCubes, for 3D image display
void debug_print_parms ()
 Printing EMData params for debugging purpose.
void set_xyz_origin (float origin_x, float origin_y, float origin_z)
 Set the x,y,z origin of the image.

Static Public Member Functions

static vector< EMData * > read_images (const string &filename, vector< int >img_indices=vector< int >(), bool header_only=false)
 Read a set of images from file specified by 'filename'.
static vector< EMData * > read_images_ext (const string &filename, int img_index_start, int img_index_end, bool header_only=false, const string &ext="")
 Read a set of images from file specified by 'filename'.
static float restrict1 (float x, int nx)
static float restrict2 (float x, int nx)

Static Public Attributes

static int totalalloc = 0

Private Types

 EMDATA_BUSY = 1 << 3
 EMDATA_HASCTFF = 1 << 4
 EMDATA_NEEDUPD = 1 << 5
 EMDATA_FLIP = 1 << 7
 EMDATA_PAD = 1 << 8
 EMDATA_FFTODD = 1 << 9
 EMDATA_SHUFFLE = 1 << 10
 EMDATA_FH = 1 << 11
 EMDATA_CPU_NEEDS_UPDATE = 1 << 12
 EMDATA_GPU_NEEDS_UPDATE = 1 << 13
 EMDATA_GPU_RO_NEEDS_UPDATE = 1 << 14
enum  EMDataFlags {
  EMDATA_BUSY = 1 << 3, EMDATA_HASCTFF = 1 << 4, EMDATA_NEEDUPD = 1 << 5, EMDATA_FLIP = 1 << 7,
  EMDATA_PAD = 1 << 8, EMDATA_FFTODD = 1 << 9, EMDATA_SHUFFLE = 1 << 10, EMDATA_FH = 1 << 11,
  EMDATA_CPU_NEEDS_UPDATE = 1 << 12, EMDATA_GPU_NEEDS_UPDATE = 1 << 13, EMDATA_GPU_RO_NEEDS_UPDATE = 1 << 14
}
 This EMDataFlags is deprecated. More...

Private Member Functions

void set_attr_dict_explicit (const Dict &new_dict)
 Make the attributes of this EMData exactly equal to the argument dictionary Originally introduced because set_attr_dict does automatic resizing, which is undersirable in some circumstances.
void update_stat () const
void save_byteorder_to_dict (ImageIO *imageio)

Static Private Member Functions

static bool peakcmp (const Pixel &p1, const Pixel &p2)

Private Attributes

Dict attr_dict
 to store all image header info
float * rdata
 image real data
float * supp
 supplementary data array
int flags
 flags
int changecount
int nx
 image size
int ny
int nz
int nxy
size_t nxyz
int xoff
 array index offsets
int yoff
int zoff
Vec3f all_translation
 translation from the original location
string path
int pathnum
EMDatarot_fp
 This is a cached rotational footprint, can save much time.

Friends

class GLUtil

Classes

class  ClipInplaceVariables

Detailed Description

EMData stores an image's data and defines core image processing routines.

The image is 1D, 2D or 3D, in real space or fourier space (complex image).

Data are ordered with x increasing fastest, then y, then z.

Definition at line 88 of file emdata.h.


Member Enumeration Documentation

enum EMAN::EMData::EMDataFlags [private]

This EMDataFlags is deprecated.

For anything which is currently handled by setting a bit in 'flags', instead, set or read an appropriately named attribute in the attributes dictionary. While there is a small overhead in the string lookup, none of these things should be called in the innermost loop anywhere, so it should be fine. --Grant

Enumerator:
EMDATA_BUSY 
EMDATA_HASCTFF 
EMDATA_NEEDUPD 
EMDATA_FLIP 
EMDATA_PAD 
EMDATA_FFTODD 
EMDATA_SHUFFLE 
EMDATA_FH 
EMDATA_CPU_NEEDS_UPDATE 
EMDATA_GPU_NEEDS_UPDATE 
EMDATA_GPU_RO_NEEDS_UPDATE 

Definition at line 3756 of file emdata.h.

enum EMAN::EMData::FFTPLACE

Enumerator:
FFT_OUT_OF_PLACE 
FFT_IN_PLACE 

Definition at line 3087 of file emdata.h.

enum EMAN::EMData::WINDOWPLACE

Enumerator:
WINDOW_OUT_OF_PLACE 
WINDOW_IN_PLACE 

Definition at line 3088 of file emdata.h.


Constructor & Destructor Documentation

EMData::EMData (  ) 

Construct an empty EMData instance.

It has no image data.

Definition at line 72 of file emdata.cpp.

References attr_dict, EMAN::EMUtil::EM_FLOAT, ENTERFUNC, and totalalloc.

Referenced by absi(), amplitude(), bispecRotTransInvDirect(), bispecRotTransInvN(), calc_ccfx(), calc_fast_sigma_image(), calc_flcf(), copy(), copy_head(), do_radon(), EMData(), extract_plane(), extractline(), get_circle_mean(), get_clip(), get_col(), get_rotated_clip(), get_row(), get_top_half(), imag(), make_footprint(), make_rotational_footprint(), make_rotational_footprint_cmc(), make_rotational_footprint_e1(), operator=(), phase(), read_images(), read_images_ext(), real(), real2complex(), rotavg(), rotavg_i(), and unwrap().

00072                :
00073 #ifdef EMAN2_USING_CUDA
00074                 cuda_cache_handle(-1),
00075 #endif //EMAN2_USING_CUDA
00076                 attr_dict(), rdata(0), supp(0), flags(0), changecount(0), nx(0), ny(0), nz(0), nxy(0), nxyz(0), xoff(0), yoff(0),
00077                 zoff(0), all_translation(),     path(""), pathnum(0), rot_fp(0)
00078 
00079 {
00080         ENTERFUNC;
00081 
00082         attr_dict["apix_x"] = 1.0f;
00083         attr_dict["apix_y"] = 1.0f;
00084         attr_dict["apix_z"] = 1.0f;
00085 
00086         attr_dict["is_complex"] = int(0);
00087         attr_dict["is_complex_x"] = int(0);
00088         attr_dict["is_complex_ri"] = int(1);
00089 
00090         attr_dict["datatype"] = (int)EMUtil::EM_FLOAT;
00091 
00092         EMData::totalalloc++;
00093 #ifdef MEMDEBUG
00094         printf("EMDATA+  %4d    %p\n",EMData::totalalloc,this);
00095 #endif
00096 
00097 }

EMData::~EMData (  ) 

Definition at line 288 of file emdata.cpp.

References ENTERFUNC, EXITFUNC, free_memory(), and totalalloc.

00289 {
00290         ENTERFUNC;
00291         free_memory();
00292 #ifdef EMAN2_USING_CUDA
00293 //      cout << "Death comes to " << cuda_cache_handle << " " << this << endl;
00294         free_cuda_memory();
00295 #endif // EMAN2_USING_CUDA
00296         EMData::totalalloc--;
00297 #ifdef MEMDEBUG
00298         printf("EMDATA-  %4d    %p\n",EMData::totalalloc,this);
00299 #endif
00300         EXITFUNC;
00301 }

EMData::EMData ( const string &  filename,
int  image_index = 0 
) [explicit]

Construct from an image file.

Parameters:
filename the image file name
image_index the image index for stack image file, default 0

Definition at line 99 of file emdata.cpp.

References attr_dict, ENTERFUNC, EXITFUNC, read_image(), totalalloc, and update().

00099                                                       :
00100 #ifdef EMAN2_USING_CUDA
00101                 cuda_cache_handle(-1),
00102 #endif //EMAN2_USING_CUDA
00103                 attr_dict(), rdata(0), supp(0), flags(0), changecount(0), nx(0), ny(0), nz(0), nxy(0), nxyz(0), xoff(0), yoff(0), zoff(0),
00104                 all_translation(),      path(filename), pathnum(image_index), rot_fp(0)
00105 {
00106         ENTERFUNC;
00107 
00108         attr_dict["apix_x"] = 1.0f;
00109         attr_dict["apix_y"] = 1.0f;
00110         attr_dict["apix_z"] = 1.0f;
00111 
00112         attr_dict["is_complex"] = int(0);
00113         attr_dict["is_complex_x"] = int(0);
00114         attr_dict["is_complex_ri"] = int(1);
00115 
00116         this->read_image(filename, image_index);
00117 
00118         update();
00119         EMData::totalalloc++;
00120 
00121         EXITFUNC;
00122 }

EMData::EMData ( int  nx,
int  ny,
int  nz = 1,
bool  is_real = true 
)

# makes an image of the specified size, either real or complex.

For complex image, the user would specify the real-space dimensions.

Parameters:
nx size for x dimension
ny size for y dimension
nz size for z dimension, default 1
is_real boolean to specify real(true) or complex(false) image, default real

Definition at line 216 of file emdata.cpp.

References attr_dict, ENTERFUNC, EXITFUNC, set_size(), to_zero(), totalalloc, and update().

00216                                                    :
00217 #ifdef EMAN2_USING_CUDA
00218                 cuda_cache_handle(-1),
00219 #endif //EMAN2_USING_CUDA
00220                 attr_dict(), rdata(0), supp(0), flags(0), changecount(0), nx(0), ny(0), nz(0), nxy(0), nxyz(0), xoff(0), yoff(0), zoff(0),
00221                 all_translation(),      path(""), pathnum(0), rot_fp(0)
00222 {
00223         ENTERFUNC;
00224 
00225         // used to replace cube 'pixel'
00226         attr_dict["apix_x"] = 1.0f;
00227         attr_dict["apix_y"] = 1.0f;
00228         attr_dict["apix_z"] = 1.0f;
00229 
00230         if(is_real) {   // create a real image [nx, ny, nz]
00231                 attr_dict["is_complex"] = int(0);
00232                 attr_dict["is_complex_x"] = int(0);
00233                 attr_dict["is_complex_ri"] = int(1);
00234                 set_size(nx, ny, nz);
00235         }
00236         else {  //create a complex image which real dimension is [ny, ny, nz]
00237                 int new_nx = nx + 2 - nx%2;
00238                 set_size(new_nx, ny, nz);
00239 
00240                 attr_dict["is_complex"] = int(1);
00241 
00242                 if(ny==1 && nz ==1)     {
00243                         attr_dict["is_complex_x"] = int(1);
00244                 }
00245                 else {
00246                         attr_dict["is_complex_x"] = int(0);
00247                 }
00248 
00249                 attr_dict["is_complex_ri"] = int(1);
00250                 attr_dict["is_fftpad"] = int(1);
00251 
00252                 if(nx%2 == 1) {
00253                         attr_dict["is_fftodd"] = 1;
00254                 }
00255         }
00256 
00257         this->to_zero();
00258         update();
00259         EMData::totalalloc++;
00260 
00261         EXITFUNC;
00262 }

EMData::EMData ( float *  data,
const int  nx,
const int  ny,
const int  nz,
const Dict attr_dict = Dict() 
)

Construction from a data pointer, dimensions must be supplied.

Takes possession of the pointer. data pointer must be allocated using malloc!

Parameters:
data a pointer to the pixel data which is stored in memory. Takes possession
nx the number of pixels in the x direction
ny the number of pixels in the y direction
nz the number of pixels in the z direction
attr_dict attribute dictionary for this image

Definition at line 265 of file emdata.cpp.

References attr_dict, ENTERFUNC, EXITFUNC, totalalloc, and update().

00265                                                                                         :
00266 #ifdef EMAN2_USING_CUDA
00267                 cuda_cache_handle(-1),
00268 #endif //EMAN2_USING_CUDA
00269                 attr_dict(attr_dict), rdata(data), supp(0), flags(0), changecount(0), nx(x), ny(y), nz(z), nxy(x*y), nxyz(x*y*z), xoff(0),
00270                 yoff(0), zoff(0), all_translation(), path(""), pathnum(0), rot_fp(0)
00271 {
00272         ENTERFUNC;
00273 
00274         // used to replace cube 'pixel'
00275         attr_dict["apix_x"] = 1.0f;
00276         attr_dict["apix_y"] = 1.0f;
00277         attr_dict["apix_z"] = 1.0f;
00278 
00279         EMData::totalalloc++;
00280 
00281         update();
00282         EXITFUNC;
00283 }


Member Function Documentation

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:
InvalidCallException this function call require a complex image in real/imaginary format.

Definition at line 1134 of file emdata_core.cpp.

References abs, copy(), data, EMData(), ENTERFUNC, EXITFUNC, get_data(), get_xsize(), get_ysize(), get_zsize(), InvalidCallException, is_real(), is_ri(), nx, ny, nz, set_complex(), set_complex_x(), set_size(), sqrt(), and update().

01135 {
01136         ENTERFUNC;
01137 
01138         EMData * e = new EMData();
01139 
01140         if( is_real() ) // a real image
01141         {
01142                 e = this->copy();
01143                 int nx = get_xsize();
01144                 int ny = get_ysize();
01145                 int nz = get_zsize();
01146                 float *edata = e->get_data();
01147                 float * data = get_data();
01148                 size_t idx;
01149                 for( int i=0; i<nx; ++i ) {
01150                         for( int j=0; j<ny; ++j ) {
01151                                 for( int k=0; k<nz; ++k ) {
01152                                         idx = i+j*nx+k*nx*ny;
01153                                         edata[idx] = std::abs(data[idx]);
01154                                 }
01155                         }
01156                 }
01157         }
01158         else //for a complex image
01159         {
01160                 if( !is_ri() )
01161                 {
01162                         throw InvalidCallException("This image is in amplitude/phase format, this function call require a complex image in real/imaginary format.");
01163                 }
01164                 int nx = get_xsize();
01165                 int ny = get_ysize();
01166                 int nz = get_zsize();
01167                 e->set_size(nx/2, ny, nz);
01168                 float * edata = e->get_data();
01169                 float * data = get_data();
01170                 size_t idx1, idx2;
01171                 for( int i=0; i<nx; ++i )
01172                 {
01173                         for( int j=0; j<ny; ++j )
01174                         {
01175                                 for( int k=0; k<nz; ++k )
01176                                 {
01177                                         if( i%2 == 0 )
01178                                         {
01179                                                 idx1 = i/2+j*(nx/2)+k*(nx/2)*ny;
01180                                                 idx2 = i+j*nx+k*nx*ny;
01181                                                 //complex data in format [real, complex, real, complex...]
01182                                                 edata[idx1] =
01183                                                 std::sqrt(data[idx2]*data[idx2]+data[idx2+1]*data[idx2+1]);
01184                                         }
01185                                 }
01186                         }
01187                 }
01188         }
01189 
01190         e->set_complex(false);
01191         if(e->get_ysize()==1 && e->get_zsize()==1) {
01192                 e->set_complex_x(false);
01193         }
01194         e->update();
01195         return e;
01196 
01197         EXITFUNC;
01198 }

void EMData::add ( const EMData image  ) 

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

Parameters:
image The image added to 'this' image.
Exceptions:
ImageFormatException If the 2 images are not same size.

Definition at line 325 of file emdata_core.cpp.

References data, ENTERFUNC, EXITFUNC, get_data(), get_xsize(), get_ysize(), get_zsize(), ImageFormatException, is_real(), nx, nxyz, ny, nz, and update().

00326 {
00327         ENTERFUNC;
00328         if (nx != image.get_xsize() || ny != image.get_ysize() || nz != image.get_zsize()) {
00329                 throw ImageFormatException( "images not same sizes");
00330         }
00331         else if( (is_real()^image.is_real()) == true )
00332         {
00333                 throw ImageFormatException( "not support add between real image and complex image");
00334         }
00335         else {
00336 
00337                 const float *src_data = image.get_data();
00338                 size_t size = nxyz;
00339                 float* data = get_data();
00340 
00341                 for (size_t i = 0; i < size; i++) {
00342                         data[i] += src_data[i];
00343                 }
00344                 update();
00345         }
00346         EXITFUNC;
00347 }

void EMData::add ( float  f,
int  keepzero = 0 
)

add a number to each pixel value of the image.

Image may be real or complex.

Parameters:
f The number added to 'this' image.
keepzero If set will not modify pixels that are exactly zero

Definition at line 260 of file emdata_core.cpp.

References data, emdata_processor_add(), ENTERFUNC, EXITFUNC, get_data(), ImageFormatException, is_complex(), is_real(), nx, nxyz, ny, nz, and update().

Referenced by EMAN::CtfCWautoAverager::add_image(), EMAN::BackProjectionReconstructor::finish(), EMAN::BackProjectionReconstructor::insert_slice(), EMAN::operator+(), operator+=(), EMAN::operator-(), EMAN::NormalizeRampNormVar::process_inplace(), and EMAN::SNREvalProcessor::process_inplace().

00261 {
00262         ENTERFUNC;
00263 
00264         float * data = get_data();
00265         if( is_real() )
00266         {
00267                 if (f != 0) {
00268 
00269 
00270 #ifdef EMAN2_USING_CUDA
00271                         if ( gpu_operation_preferred () && !keepzero ) {
00272                                 EMDataForCuda tmp = get_data_struct_for_cuda();
00273                                 emdata_processor_add(&tmp,f);
00274                                 gpu_update();
00275                                 EXITFUNC;
00276                                 return;
00277                         }
00278 #endif // EMAN2_USING_CUDA
00279                         size_t size = nxyz;
00280                         if (keepzero) {
00281                                 for (size_t i = 0; i < size; i++) {
00282                                         if (data[i]) data[i] += f;
00283                                 }
00284                         }
00285                         else {
00286                                 for (size_t i = 0; i < size; i++) {
00287                                         data[i] += f;
00288                                 }
00289                         }
00290                         update();
00291                 }
00292         }
00293         else if( is_complex() )
00294         {
00295                 if( f!=0 )
00296                 {
00297                         update();
00298                         size_t size = nx*ny*nz; //size of data
00299                         if( keepzero )
00300                         {
00301                                 for(size_t i=0; i<size; i+=2)
00302                                 {
00303                                         if (data[i]) data[i] += f;
00304                                 }
00305                         }
00306                         else
00307                         {
00308                                 for(size_t i=0; i<size; i+=2)
00309                                 {
00310                                         data[i] += f;
00311                                 }
00312                         }
00313                 }
00314         }
00315         else
00316         {
00317                 throw ImageFormatException("This image is neither a real nor a complex image.");
00318         }
00319         update();
00320         EXITFUNC;
00321 }

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:
x x coordinate
y y coordinate
z z coordinate
val complex<float> value to set
Returns:
The complex pixel at x,y

Definition at line 227 of file emdata_core.cpp.

References abs, nx, nxyz, ny, nz, and rdata.

00227                                                                                                                                                                                      {
00228 if (abs(x)>=fullnx/2 || abs(y)>fullny/2 || abs(z)>fullnz/2) return nxyz;
00229 //if (x==0 && (y!=0 || z!=0)) add_complex_at(0,-y,-z,subx0,suby0,subz0,fullnx,fullny,fullnz,conj(val));
00230 // complex conjugate insertion. Removed due to ambiguity with returned index
00231 /*if (x==0&& (y!=0 || z!=0)) {
00232         int yy=y<=0?-y:fullny-y;
00233         int zz=z<=0?-z:fullnz-z;
00234 
00235         if (yy<suby0||zz<subz0||yy>=suby0+ny||zz>=subz0+nz) return nx*ny*nz;
00236 
00237         size_t idx=(yy-suby0)*nx+(zz-subz0)*nx*ny;
00238         rdata[idx]+=(float)val.real();
00239         rdata[idx+1]+=(float)-val.imag();
00240 }*/
00241 float cc=1.0;
00242 if (x<0) {
00243         x*=-1;
00244         y*=-1;
00245         z*=-1;
00246         cc=-1.0;
00247 }
00248 if (y<0) y=fullny+y;
00249 if (z<0) z=fullnz+z;
00250 
00251 if (x<subx0||y<suby0||z<subz0||x>=subx0+nx||y>=suby0+ny||z>=subz0+nz) return nxyz;
00252 
00253 size_t idx=(x-subx0)*2+(y-suby0)*(size_t)nx+(z-subz0)*(size_t)nx*ny;
00254 rdata[idx]+=(float)val.real();
00255 rdata[idx+1]+=cc*(float)val.imag();
00256 return idx;
00257 }

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:
x x coordinate
y y coordinate
z z coordinate
val complex<float> value to set
Returns:
The complex pixel at x,y

Definition at line 200 of file emdata_core.cpp.

References nx, nxy, nxyz, ny, nz, and rdata.

Referenced by EMAN::FourierInserter3DMode7::insert_pixel(), EMAN::FourierInserter3DMode6::insert_pixel(), EMAN::FourierInserter3DMode2::insert_pixel(), and EMAN::FourierInserter3DMode1::insert_pixel().

00200                                                                                                  {
00201 //if (abs(x)>=nx/2 || abs(y)>ny/2 || abs(z)>nz/2) return nxyz;
00202 if (x>=nx/2 || y>ny/2 || z>nz/2 || x<=-nx/2 || y<-ny/2 || z<-nz/2) return nxyz;
00203 
00204 // for x=0, we need to insert the value in 2 places
00205 // complex conjugate insertion. Removed due to ambiguity with returned index
00206 /*if (x==0 && (y!=0 || z!=0)) {
00207         size_t idx=(y<=0?-y:ny-y)*nx+(z<=0?-z:nz-z)*nx*ny;
00208         rdata[idx]+=(float)val.real();
00209         rdata[idx+1]-=(float)val.imag();
00210 }*/
00211 
00212 size_t idx;
00213 if (x<0) {
00214         idx=-x*2+(y<=0?-y:ny-y)*(size_t)nx+(z<=0?-z:nz-z)*(size_t)nxy;
00215         rdata[idx]+=(float)val.real();
00216         rdata[idx+1]-=(float)val.imag();
00217         return idx;
00218 }
00219 
00220 idx=x*2+(y<0?ny+y:y)*(size_t)nx+(z<0?nz+z:z)*(size_t)nxy;
00221 rdata[idx]+=(float)val.real();
00222 rdata[idx+1]+=(float)val.imag();
00223 
00224 return idx;
00225 }

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

Definition at line 1969 of file emdata.h.

Referenced by EMAN::FourierInserter3DMode5::insert_pixel(), EMAN::FourierInserter3DMode3::insert_pixel(), and EMAN::FourierInserter3DMode2::insert_pixel().

void EMData::add_incoherent ( EMData obj  ) 

Adds 'obj' to 'this' incoherently.

'obj' and 'this' should be same size. Both images should be complex images.

Parameters:
obj The image added to 'this' image.
Exceptions:
ImageFormatException If the 2 images are not same size; or if the 2 images are not complex images.

Definition at line 2944 of file emdata.cpp.

References ENTERFUNC, EXITFUNC, get_data(), ImageFormatException, is_complex(), EMAN::EMUtil::is_same_size(), LOGERR, NullPointerException, nx, ny, nz, ri2ap(), and update().

02945 {
02946         ENTERFUNC;
02947 
02948         if (!obj) {
02949                 LOGERR("NULL image");
02950                 throw NullPointerException("NULL image");
02951         }
02952 
02953         if (!obj->is_complex() || !is_complex()) {
02954                 throw ImageFormatException("complex images only");
02955         }
02956 
02957         if (!EMUtil::is_same_size(this, obj)) {
02958                 throw ImageFormatException("images not same size");
02959         }
02960 
02961         ri2ap();
02962         obj->ri2ap();
02963 
02964         float *dest = get_data();
02965         float *src = obj->get_data();
02966         size_t size = nx * ny * nz;
02967         for (size_t j = 0; j < size; j += 2) {
02968 #ifdef  _WIN32
02969                 dest[j] = (float) _hypot(src[j], dest[j]);
02970 #else
02971                 dest[j] = (float) hypot(src[j], dest[j]);
02972 #endif  //_WIN32
02973                 dest[j + 1] = 0;
02974         }
02975 
02976         obj->update();
02977         update();
02978         EXITFUNC;
02979 }

void EMData::addsquare ( const EMData image  ) 

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

Parameters:
image The image whose square is added to 'this' image.
Exceptions:
ImageFormatException If the 2 images are not same size.

Definition at line 350 of file emdata_core.cpp.

References data, ENTERFUNC, EXITFUNC, get_data(), get_xsize(), get_ysize(), get_zsize(), ImageFormatException, is_complex(), nx, nxyz, ny, nz, and update().

00351 {
00352         ENTERFUNC;
00353         if (nx != image.get_xsize() || ny != image.get_ysize() || nz != image.get_zsize()) {
00354                 throw ImageFormatException( "images not same sizes");
00355         }
00356         else if( this->is_complex() || image.is_complex() )
00357         {
00358                 throw ImageFormatException( "Cannot addsquare() with complex images");
00359         }
00360         else {
00361 
00362                 const float *src_data = image.get_data();
00363                 size_t size = nxyz;
00364                 float* data = get_data();
00365 
00366                 for (size_t i = 0; i < size; i++) {
00367                         data[i] += src_data[i]*src_data[i];
00368                 }
00369                 update();
00370         }
00371         EXITFUNC;
00372 }

EMData * EMData::align ( const string &  aligner_name,
EMData to_img,
const Dict params = Dict(),
const string &  cmp_name = "dot",
const Dict cmp_params = Dict() 
)

Align this image with another image and return the result image.

Parameters:
aligner_name Alignment algorithm name.
to_img The image 'this' image aligns to.
params Alignment algorithm parameters in a keyed dictionary.
cmp_name Comparison algorithm used in alignment.
cmp_params Parameter dictionary for comparison algorithm.
Exceptions:
NotExistingObjectError If the alignment algorithm doesn't exist.
Returns:
The result image.

Definition at line 116 of file emdata_modular.cpp.

References EMAN::Aligner::align(), ENTERFUNC, and EXITFUNC.

Referenced by EMAN::RotateFlipAligner::align(), EMAN::RotateTranslateFlipAligner::align(), EMAN::RotateTranslateAligner::align(), main(), and EMAN::ACFCenterProcessor::process_inplace().

00118 {
00119         ENTERFUNC;
00120         EMData *result = 0;
00121         Aligner *a = Factory < Aligner >::get(aligner_name, params);
00122         if (a) {
00123                 if (cmp_name == "") {
00124                         result = a->align(this, to_img);
00125                 }
00126                 else {
00127                         result = a->align(this, to_img, cmp_name, cmp_params);
00128                 }
00129                 if( a )
00130                 {
00131                         delete a;
00132                         a = 0;
00133                 }
00134         }
00135 
00136         EXITFUNC;
00137         return result;
00138 }

EMData * 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:
InvalidCallException if this image is a real image or is in real/imaginary format

Definition at line 1201 of file emdata_core.cpp.

References data, EMData(), ENTERFUNC, EXITFUNC, get_data(), get_xsize(), get_ysize(), get_zsize(), InvalidCallException, is_real(), is_ri(), nx, ny, nz, set_complex(), set_complex_x(), set_size(), and update().

01202 {
01203         ENTERFUNC;
01204 
01205         EMData * e = new EMData();
01206 
01207         if( is_real() ) {
01208                 throw InvalidCallException("No imaginary part for a real image, this function call require a complex image.");
01209         }
01210         else {
01211                 if(is_ri()) {
01212                         throw InvalidCallException("This image is in real/imaginary format, this function call require a complex image in amplitude/phase format.");
01213                 }
01214 
01215                 int nx = get_xsize();
01216                 int ny = get_ysize();
01217                 int nz = get_zsize();
01218                 e->set_size(nx/2, ny, nz);
01219                 float * edata = e->get_data();
01220                 float * data = get_data();
01221                 size_t idx1, idx2;
01222                 for( int i=0; i<nx; ++i )
01223                 {
01224                         for( int j=0; j<ny; ++j )
01225                         {
01226                                 for( int k=0; k<nz; ++k )
01227                                 {
01228                                         if( i%2 == 0 )
01229                                         {
01230                                                 idx1 = i/2+j*(nx/2)+k*(nx/2)*ny;
01231                                                 idx2 = i+j*nx+k*nx*ny;
01232                                                 //complex data in format [amp, phase, amp, phase...]
01233                                                 edata[idx1] = data[idx2];
01234                                         }
01235                                 }
01236                         }
01237                 }
01238         }
01239 
01240         e->set_complex(false);
01241         if(e->get_ysize()==1 && e->get_zsize()==1) {
01242                 e->set_complex_x(false);
01243         }
01244         e->update();
01245         return e;
01246 
01247         EXITFUNC;
01248 }

void EMData::append_image ( const string &  filename,
EMUtil::ImageType  imgtype = EMUtil::IMAGE_UNKNOWN,
bool  header_only = false 
)

append to an image file; If the file doesn't exist, create one.

Parameters:
filename The image file name.
imgtype Write to the given image format type. if not specified, use the 'filename' extension to decide.
header_only To write only the header or both header and data.

Definition at line 278 of file emdata_io.cpp.

References ENTERFUNC, EXITFUNC, and write_image().

Referenced by EMAN::IterationAverager::finish(), and main().

00280 {
00281         ENTERFUNC;
00282         write_image(filename, -1, imgtype, header_only, 0);
00283         EXITFUNC;
00284 }

void EMData::apply_radial_func ( float  x0,
float  dx,
vector< float >  array,
bool  interp = true 
)

multiplies by a radial function in fourier space.

Parameters:
x0 starting point x coordinate.
dx step of x.
array radial function data array.
interp Do the interpolation or not.

Definition at line 2373 of file emdata.cpp.

References ap2ri(), data, ENTERFUNC, EXITFUNC, get_data(), get_ndim(), ImageFormatException, is_complex(), nx, ny, nz, sqrt(), and update().

Referenced by main(), EMAN::FileFourierProcessor::process_inplace(), EMAN::SNRProcessor::process_inplace(), EMAN::FourierAnlProcessor::process_inplace(), and EMAN::FourierProcessor::process_inplace().

02374 {
02375         ENTERFUNC;
02376 
02377         if (!is_complex()) throw ImageFormatException("apply_radial_func requires a complex image");
02378 
02379         int n = static_cast < int >(array.size());
02380 
02381         if (n*step>2.0) printf("Warning, apply_radial_func takes x0 and step with respect to Nyquist (0.5)\n");
02382 
02383 //      printf("%f %f %f\n",array[0],array[25],array[50]);
02384 
02385         ap2ri();
02386 
02387         size_t ndims = get_ndim();
02388         float * data = get_data();
02389         if (ndims == 2) {
02390                 int k = 0;
02391                 for (int j = 0; j < ny; j++) {
02392                         for (int i = 0; i < nx; i += 2, k += 2) {
02393                                 float r;
02394 #ifdef  _WIN32
02395                                 if (j<ny/2) r = (float)_hypot(i/(float)(nx*2), j/(float)ny);
02396                                 else r = (float)_hypot(i/(float)(nx*2), (ny-j)/(float)ny);
02397 #else
02398                                 if (j<ny/2) r = (float)hypot(i/(float)(nx*2), j/(float)ny);
02399                                 else r = (float)hypot(i/(float)(nx*2), (ny-j)/(float)ny);
02400 #endif  //_WIN32
02401                                 r = (r - x0) / step;
02402 
02403                                 int l = 0;
02404                                 if (interp) {
02405                                         l = (int) floor(r);
02406                                 }
02407                                 else {
02408                                         l = (int) floor(r + 1);
02409                                 }
02410 
02411 
02412                                 float f = 0;
02413                                 if (l >= n - 2) {
02414                                         f = array[n - 1];
02415                                 }
02416                                 else {
02417                                         if (interp) {
02418                                                 r -= l;
02419                                                 f = (array[l] * (1.0f - r) + array[l + 1] * r);
02420                                         }
02421                                         else {
02422                                                 f = array[l];
02423                                         }
02424                                 }
02425 
02426                                 data[k] *= f;
02427                                 data[k + 1] *= f;
02428                         }
02429                 }
02430         }
02431         else if (ndims == 3) {
02432                 int k = 0;
02433                 for (int m = 0; m < nz; m++) {
02434                         float mnz;
02435                         if (m<nz/2) mnz=m*m/(float)(nz*nz);
02436                         else { mnz=(nz-m)/(float)nz; mnz*=mnz; }
02437 
02438                         for (int j = 0; j < ny; j++) {
02439                                 float jny;
02440                                 if (j<ny/2) jny= j*j/(float)(ny*ny);
02441                                 else { jny=(ny-j)/(float)ny; jny*=jny; }
02442 
02443                                 for (int i = 0; i < nx; i += 2, k += 2) {
02444                                         float r = std::sqrt((i * i / (nx*nx*4.0f)) + jny + mnz);
02445                                         r = (r - x0) / step;
02446 
02447                                         int l = 0;
02448                                         if (interp) {
02449                                                 l = (int) floor(r);
02450                                         }
02451                                         else {
02452                                                 l = (int) floor(r + 1);
02453                                         }
02454 
02455 
02456                                         float f = 0;
02457                                         if (l >= n - 2) {
02458                                                 f = array[n - 1];
02459                                         }
02460                                         else {
02461                                                 if (interp) {
02462                                                         r -= l;
02463                                                         f = (array[l] * (1.0f - r) + array[l + 1] * r);
02464                                                 }
02465                                                 else {
02466                                                         f = array[l];
02467                                                 }
02468                                         }
02469 
02470                                         data[k] *= f;
02471                                         data[k + 1] *= f;
02472                                 }
02473                         }
02474                 }
02475 
02476         }
02477 
02478         update();
02479         EXITFUNC;
02480 }

EMData * EMData::average_circ_sub (  )  const

Subtract average outside of a circle.

Returns:
image with sbtracted average outside of a circle.

Definition at line 966 of file emdata_sparx.cpp.

References copy_head(), ENTERFUNC, EXITFUNC, get_data(), nx, ny, nz, pnewimg, proj, and update().

Referenced by EMAN::padfft_slice().

00967 {
00968 //  this is written as though dimensions could be different, but in fact they should be all equal nx=ny=nz,
00969 //                                                           no check of this
00970         ENTERFUNC;
00971         const EMData* const image = this;
00972         EMData* newimg = copy_head();
00973         float *proj = image->get_data();
00974         float *pnewimg = newimg->get_data();
00975         //  Calculate average outside of a circle
00976         float r2 = static_cast<float>( (nx/2)*(nx/2) );
00977         float qs=0.0f;
00978         int m=0;
00979         int ncz = nz/2 + 1;
00980         int ncy = ny/2 + 1;
00981         int ncx = nx/2 + 1;
00982         for (int iz = 1; iz <= nz; iz++) {
00983                 float yy = static_cast<float>( (iz-ncz)*(iz-ncz) );
00984                 for (int iy = 1; iy <=ny; iy++) { float xx = yy + (iy-ncy)*(iy-ncy);
00985                         for (int ix = 1; ix <= nx; ix++) {
00986                                 if ( xx+float((ix-ncx)*(ix-ncx)) > r2 ) {
00987                                         qs += proj(ix,iy,iz);
00988                                         m++;
00989                                 }
00990                         }
00991                 }
00992         }
00993 
00994 
00995         if( m > 0 ) qs /= m;
00996 
00997         for (int iz = 1; iz <= nz; iz++)
00998                 for (int iy = 1; iy <= ny; iy++)
00999                         for (int ix = 1; ix <= nx; ix++)
01000                                         pnewimg(ix,iy,iz) = proj(ix,iy,iz) - qs;
01001         newimg->update();
01002         return newimg;
01003         EXITFUNC;
01004 }

EMData * EMData::backproject ( const string &  projector_name,
const Dict params = Dict() 
)

Calculate the backprojection of this image (stack) and return the result.

Parameters:
projector_name Projection algorithm name. (Only "pawel" and "chao" have been implemented now).
params Projection Algorithm parameters.
Exceptions:
NotExistingObjectError If the projection algorithm doesn't exist.
Returns:
The result image.

Definition at line 193 of file emdata_modular.cpp.

References EMAN::Projector::backproject3d(), ENTERFUNC, and EXITFUNC.

00194 {
00195         ENTERFUNC;
00196         EMData *result = 0;
00197         Projector *p = Factory < Projector >::get(projector_name, params);
00198         if (p) {
00199                 result = p->backproject3d(this);
00200                 if( p )
00201                 {
00202                         delete p;
00203                         p = 0;
00204                 }
00205         }
00206 
00207         EXITFUNC;
00208         return result;
00209 }

EMData * EMData::bispecRotTransInvDirect ( int  type = 0  ) 

This computes the rotational and translational bispectral invariants of an image.

the output is a single 3d Volume whose x,y labels are lengths, corresponding to the two lengths of sides of a triangle the z label is for the angle

Definition at line 1281 of file emdata_transform.cpp.

References do_fft(), EMData(), get_value_at(), get_xsize(), process_inplace(), set_value_at(), sqrt(), write_image(), and x.

01282 {
01283 
01284         int EndP = this -> get_xsize(); // length(fTrueVec);
01285         int Mid  = (int) ((1+EndP)/2);
01286         int End = 2*Mid-1;
01287 
01288         int CountxyMax = End*End;
01289 
01290         int   *SortfkInds       = new    int[CountxyMax];
01291         int   *kVecX            = new    int[CountxyMax];
01292         int   *kVecY            = new    int[CountxyMax];
01293         float *fkVecR           = new  float[CountxyMax];
01294         float *fkVecI           = new  float[CountxyMax];
01295         float *absD1fkVec       = new  float[CountxyMax];
01296         float *absD1fkVecSorted = new  float[CountxyMax];
01297 
01298 
01299         float *jxjyatan2         = new  float[End*End];
01300 
01301 
01302         EMData * ThisCopy = new EMData(End,End);
01303 
01304         for (int jx=0; jx <End ; jx++) {  // create jxjyatan2
01305                 for (int jy=0; jy <End ; jy++) {
01306                         float ValNow = this -> get_value_at(jx,jy);
01307                         ThisCopy -> set_value_at(jx,jy,ValNow);
01308                         jxjyatan2[jy*End + jx]  = atan2((float)(jy+1-Mid) , (float)(jx +1 -Mid));
01309 //              cout<< " jxM= " << jx+1<<" jyM= " << jy+1<< "ValNow" << ValNow << endl; //    Works
01310         }}
01311 
01312 
01313         EMData* fk = ThisCopy -> do_fft();
01314         fk          ->process_inplace("xform.fourierorigin.tocenter");
01315 
01316 //      Create kVecX , kVecy etc
01317 
01318         for (int kEx= 0; kEx<2*Mid; kEx=kEx+2) { // kEx twice the value of the Fourier
01319                                                 // x variable: EMAN index for real, imag
01320                 int kx    = kEx/2;              // kx  is  the value of the Fourier variable
01321                 int kIx   = kx+Mid-1; // This is the value of the index for a matlab image (-1)
01322                 int kCx   = -kx ;
01323                 int kCIx  = kCx+ Mid-1 ;
01324                 for (int kEy= 0 ; kEy<End; kEy++) { // This is the value of the EMAN index
01325                         int kIy              =  kEy       ; //  This is the value of the index for a matlab image (-1)
01326                         int ky               =  kEy+1-Mid; // (kEy+ Mid-1)%End - Mid+1 ;  // This is the actual value of the Fourier variable
01327                         float realVal        =  fk -> get_value_at(kEx  ,kEy) ;
01328                         float imagVal        =  fk -> get_value_at(kEx+1,kEy) ;
01329                         float absVal         =  ::sqrt(realVal*realVal+imagVal*imagVal);
01330                         float fkAng          =  atan2(imagVal,realVal);
01331 
01332                         float NewRealVal   ;
01333                         float NewImagVal   ;
01334                         float AngMatlab    ;
01335 
01336                         if (kIx==Mid-1) {
01337 //                              AngMatlab = -fkAng - 2.*M_PI*(kIy+ 1-Mid)*(Mid)/End;
01338                         }
01339 
01340                         if (kIx>Mid-1){
01341 //                      cout<< "i= " << i << " kIx= " << kIx << " kIy=" << kIy << " fkVecR[i] =" << fkVecR[i]<< " fkVecI[i]="  << fkVecI[i] <<"  angle[i]= "  << AngMatlab << endl;
01342                         }
01343 
01344                         AngMatlab = fkAng - 2.0f*M_PI*(kx +ky)*(Mid)/End;
01345                         NewRealVal  =   absVal*cos(AngMatlab);
01346                         NewImagVal  =   absVal*sin(AngMatlab);
01347 
01348 
01349                         fkVecR[ kIy +kIx *End] =  NewRealVal ;
01350                         fkVecR[(End-1-kIy)+kCIx*End] =  NewRealVal ;
01351                         fkVecI[ kIy +kIx *End] =  NewImagVal ;
01352                         fkVecI[(End-1-kIy)+kCIx*End] = -NewImagVal ;
01353                         absD1fkVec[(End-1-kIy) + kIx  *End] = absVal;
01354                         absD1fkVec[(End-1-kIy) + kCIx *End] = absVal;
01355                         kVecX[kIy+kIx  *End] =  kx      ;
01356                         kVecX[kIy+kCIx *End] =  kCx    ;
01357                         kVecY[kIy+kIx  *End] =  ky     ;
01358                         kVecY[kIy+kCIx *End] =  ky     ;
01359 
01360  //                     cout << " kIxM= " << kIx+1 << " kIy=" << kIy+1 << " fkVecR[i] =" << NewRealVal << " fkVecI[i]="  << NewImagVal <<"  angle[i]= "  << AngMatlab << " Total Index" << kIy+kIx *End << endl;
01361 
01362 //                      printf("kx=%d,ky=%d,tempVal =%f+ i %4.2f \n",kx,ky,realVal,imagVal );
01363 //                      cout << "kx = " << kx << "; ky = "<< ky << "; val is" << realVal<<"+ i "<<imagVal<< endl;
01364 
01365 //                      cout << "kIMx = "<< kIx+1 << "; kIMy = "<< kIy+1 <<"; fkAng*9/ 2pi is " << fkAng*9/2/M_PI<<  endl;
01366 //                      cout << "kIMx = "<< kIx+1 << "; kIMy = "<< kIy+1 <<"; absval is " << absVal<<  "; realval is " << NewRealVal<< "; imagval is " << NewImagVal<< endl;
01367                 }
01368         }
01369 
01370 
01371         for (int TotalInd = 0 ;  TotalInd < CountxyMax ; TotalInd++){
01372                 int kx     = kVecX[TotalInd]; // This is the value of the index for a matlab image (-1)
01373                 int kIx    = kx+Mid-1; // This is the value of the index for a matlab image (-1)
01374                 int ky     = kVecY[TotalInd];
01375                 int kIy    = ky+Mid-1; // This is the value of the index for a matlab image (-1)
01376                 float fkR  = fkVecR[kIy+kIx *End]  ;
01377                 float fkI  = fkVecI[kIy+kIx *End]  ;
01378         }
01379 
01380         float frR= 3.0/4.0;
01381         frR= 1;
01382         int LradRange= (int) (1+floor(Mid/frR -.1)) ;
01383 
01384         float *radRange = new float[LradRange]; //= 0:.75:(Mid-1);
01385         for (int irad=0; irad < LradRange; irad++){
01386                         radRange[irad] =  frR*irad;
01387 //                      cout << " irad = " << irad << " radRange[irad]= " <<  radRange[irad] <<  " LradRange= " << LradRange << endl;
01388         }
01389 
01390         cout << "Starting the calculation of invariants" << endl;
01391 
01392 
01393         if (type==0) {
01394                 int LthetaRange  = 59;
01395                 float ftR        = (2.0f*M_PI/LthetaRange );
01396                 float *thetaRange = new float[LthetaRange]; //= 0:.75:(Mid-1);
01397 
01398                 for (int ith=0; ith < LthetaRange; ith++){
01399                                 thetaRange[ith] =  ftR*ith; }
01400 
01401 
01402 
01403 
01404 
01405                 int TotalVol = LradRange*LradRange*LthetaRange;
01406 
01407                 float *RotTransInv   = new  float[TotalVol];
01408                 float *WeightInv     = new  float[TotalVol];
01409 
01410                 for (int jW=0; jW<TotalVol; jW++) {
01411                         RotTransInv[jW] = 0;
01412                         WeightInv[jW]   = 0;
01413                 }
01414 
01415 
01416                 for (int jW=0; jW<TotalVol; jW++) {
01417                         RotTransInv[jW] = 0;
01418                         WeightInv[jW]   = 0;
01419                 }
01420         //      float  *RotTransInv       = new float[LradRange*LradRange ] ;
01421         //      float  *RotTransInvN      = new float[LradRange*LradRange*(NMax+1) ] ;
01422 
01423                 for (int Countkxy =0; Countkxy<CountxyMax; Countkxy++){  // Main Section for type 0
01424                         int kx = kVecX[Countkxy] ;
01425                         int ky = kVecY[Countkxy] ;
01426                         float k2 = ::sqrt((float)(kx*kx+ky*ky));
01427                         float phiK =0;
01428                         if (k2>0)    phiK = jxjyatan2[ (ky+Mid-1)*End + kx+Mid-1]; //  phiK=atan2(ky,kx);
01429                         float fkR     = fkVecR[(ky+Mid-1) + (kx+Mid-1) *End] ;
01430                         float fkI     = fkVecI[(ky+Mid-1) + (kx+Mid-1) *End]  ;
01431         //              printf("Countkxy=%d,\t kx=%d, ky=%d, fkR=%3.2f,fkI=%3.2f \n", Countkxy, kx, ky, fkR, fkI);
01432 
01433                         if ((k2==0)|| (k2>Mid) ) { continue;}
01434 
01435                         for (int Countqxy =0; Countqxy<CountxyMax; Countqxy++){   // This is the innermost loop
01436                                 int qx   = kVecX[Countqxy] ;
01437                                 int qy   = kVecY[Countqxy] ;
01438                                 float q2   = ::sqrt((float)(qx*qx+qy*qy));
01439                                 if ((q2==0)|| (q2>Mid) ) {continue;}
01440                                 float phiQ =0;
01441                                 if (q2>0)   phiQ = jxjyatan2[ (qy+Mid-1)*End + qx+Mid-1]; // phiQ=atan2(qy,qx);
01442                                 float fqR     = fkVecR[(qy+Mid-1) + (qx+Mid-1) *End] ;
01443                                 float fqI     = fkVecI[(qy+Mid-1) + (qx+Mid-1) *End]  ;
01444                                 int kCx  = (-kx-qx);
01445                                 int kCy  = (-ky-qy);
01446                                 int kCIx = ((kCx+Mid+2*End)%End);// labels of the image in C
01447                                 int kCIy = ((kCy+Mid+2*End)%End);
01448                                 kCx  = ((kCIx+End-1)%End)+1-Mid; // correct
01449                                 kCy  = ((kCIy+End-1)%End)+1-Mid ; // correct
01450 
01451                                 float C2   = ::sqrt((float)(kCx*kCx+ kCy*kCy));
01452                                 int CountCxy  = (kCx+Mid-1)*End+(kCy+Mid-1);
01453                                 float fCR     = fkVecR[CountCxy];
01454                                 float fCI     = fkVecI[CountCxy];
01455         /*                      if (Countkxy==1) {
01456                                         printf(" Countqxy=%d, absD1fkVec(Countqxy)=%f,qx=%d, qy=%d \n", Countqxy, absD1fkVec[Countqxy],qx, qy);
01457                                         printf(" CountCxy=%d, absD1fkVec[CountCxy]=%f,kCx=%d,kCy=%d \n",CountCxy, absD1fkVec[CountCxy], kCx, kCy );
01458                                 }*/
01459                                 float   phiC = jxjyatan2[ (kCy+Mid-1)*End + kCx+Mid-1];
01460                                 float   phiQK = (4*M_PI+phiQ-phiK);
01461                                 while (phiQK> (2*M_PI)) phiQK -= (2*M_PI);
01462 
01463 
01464 
01465                                 float bispectemp  = (fkR*(fqR*fCR -fqI*fCI) -fkI*(fqI*fCR  +fqR*fCI));
01466 
01467                                 if  ((q2<k2) )  continue;
01468 //                              if  ((q2<k2) || (C2<k2) || (C2<q2))  continue;
01469 
01470         //                              printf(" CountCxy=%d, absD1fkVec[CountCxy]=%f,kCx=%d,kCy=%d \n",CountCxy, absD1fkVec[CountCxy], kCx, kCy );
01471 
01472         //                      up to here, matched perfectly with Matlab
01473 
01474                                 int k2IndLo  = 0; while ((k2>=radRange[k2IndLo+1]) && (k2IndLo+1 < LradRange ) ) k2IndLo +=1;
01475                                 int k2IndHi = k2IndLo;
01476                                 float k2Lo= radRange[k2IndLo];
01477                                 if (k2IndLo+1< LradRange) {
01478                                         k2IndHi   = k2IndLo+1;
01479                                 }
01480                                 float k2Hi= radRange[k2IndHi];
01481 
01482                                 float kCof =k2-k2Lo;
01483 
01484                                 int q2IndLo  = 0; while ((q2>=radRange[q2IndLo+1]) && (q2IndLo+1 < LradRange ) ) q2IndLo +=1;
01485                                 int q2IndHi=q2IndLo;
01486                                 float q2Lo= radRange[q2IndLo];
01487                                 if (q2IndLo+1 < LradRange)  {
01488                                         q2IndHi   = q2IndLo+1 ;
01489                                 }
01490                                 float qCof = q2-q2Lo;
01491 
01492                                 if ((qCof<0) || (qCof >1) ) {
01493                                         cout<< "Weird! qCof="<< qCof <<  " q2="<< q2 << " q2IndLo="<< q2IndLo << endl ;
01494                                         int x    ;
01495                                         cin >> x ;
01496                                 }
01497 
01498                                 int thetaIndLo = 0; while ((phiQK>=thetaRange[thetaIndLo+1])&& (thetaIndLo+1<LthetaRange)) thetaIndLo +=1;
01499                                 int thetaIndHi = thetaIndLo;
01500 
01501                                 float thetaLo  = thetaRange[thetaIndLo];
01502                                 float thetaHi = thetaLo;
01503                                 float thetaCof = 0;
01504 
01505                                 if (thetaIndLo+1< LthetaRange) {
01506                                         thetaIndHi = thetaIndLo +1;
01507                                 }else{
01508                                         thetaIndHi=0;
01509                                 }
01510 
01511                                 thetaHi    = thetaRange[thetaIndHi];
01512 
01513                                 if (thetaHi==thetaLo) {
01514                                         thetaCof =0 ;
01515                                 } else {
01516                                         thetaCof   = (phiQK-thetaLo)/(thetaHi-thetaLo);
01517                                 }
01518 
01519                                 if ((thetaCof>2*M_PI)  ) {
01520                                         cout<< "Weird! thetaCof="<< thetaCof <<endl ;
01521                                         thetaCof=0;
01522                                 }
01523 
01524 
01525         //                      if ((thetaIndLo>=58) || (k2IndLo >= LradRange-1) || (q2IndLo >= LradRange-1) ) {
01526 
01527 
01528                                 for (int jk =1; jk<=2; jk++){
01529                                 for (int jq =1; jq<=2; jq++){
01530                                 for (int jtheta =1; jtheta<=2; jtheta++){
01531 
01532                                         float Weight = (kCof+(1-2*kCof)*(jk==1))*(qCof+(1-2*qCof)*(jq==1))
01533                                                         * (thetaCof+(1-2*thetaCof)*(jtheta==1));
01534 
01535 
01536                                         int k2Ind      =  k2IndLo*(jk==1)      +   k2IndHi*(jk==2);
01537                                         int q2Ind      =  q2IndLo*(jq==1)      +   q2IndHi*(jq==2);
01538                                         int thetaInd   =  thetaIndLo*(jtheta==1)  + thetaIndHi*(jtheta ==2);
01539                                         int TotalInd   = thetaInd*LradRange*LradRange+q2Ind*LradRange+k2Ind;
01540         /*                              if (TotalInd+1 >=  LthetaRange*LradRange*LradRange) {
01541                                                 cout << "Weird!!! TotalInd="<< TotalInd << " IndMax" << LthetaRange*LradRange*LradRange << " LradRange=" << LradRange << endl;
01542                                                 cout << "k2Ind= "<< k2Ind  << " q2Ind="<< q2Ind  << " thetaInd="<< thetaInd  << " q2IndLo="<< q2IndLo  << " q2IndHi="<< q2IndHi  <<  endl;
01543                                                 cout << "k2=" << k2 << "q2=" << q2 << " phiQK=" << phiQK*180.0/M_PI<< endl;
01544                                         }*/
01545 
01546                                         RotTransInv[TotalInd] += Weight*bispectemp;
01547                                         WeightInv[TotalInd]   +=  Weight;
01548         //                              cout << "k2Ind= "<< k2Ind  << " q2Ind="<< q2Ind  << "Weight=" << Weight << endl;
01549                                 }}}
01550                         } // Countqxy
01551                 } // Countkxy
01552 
01553                 cout << "Finished Main Section " << endl;
01554 
01555         /*              RotTransInvN[jr1 + LradRange*jr2+LradRange*LradRange*N] = RotTransInvTemp  ;*/
01556 
01557                 cout << " LradRange " <<LradRange <<" LthetaRange " << LthetaRange << endl;
01558                 EMData *RotTransInvF  = new  EMData(LradRange,LradRange,LthetaRange);
01559                 EMData *WeightImage   = new  EMData(LradRange,LradRange,LthetaRange);
01560 
01561         //      cout << "FFFFFFF" << endl;
01562         //
01563         //      RotTransInvF -> set_size(LradRange,LradRange,LthetaRange);
01564         //
01565         //      cout << "GGGG" << endl;
01566 
01567                 for (int jtheta =0; jtheta < LthetaRange; jtheta++){    // write out to RotTransInvF
01568                 for (int jq =0; jq<LradRange; jq++){ // LradRange
01569                 for (int jk =0; jk<LradRange ; jk++){// LradRange
01570         //              cout << "Hi There" << endl;
01571                         int TotalInd   = jtheta*LradRange*LradRange+jq*LradRange+jk;
01572                         float Weight = WeightInv[TotalInd];
01573                         WeightImage    -> set_value_at(jk,jq,jtheta,Weight);
01574                         RotTransInvF   -> set_value_at(jk,jq,jtheta,0);
01575                         if (Weight <= 0) continue;
01576                         RotTransInvF -> set_value_at(jk,jq,jtheta,RotTransInv[TotalInd] / Weight);//  include /Weight
01577                         int newjtheta = (LthetaRange- jtheta)%LthetaRange;
01578                         RotTransInvF -> set_value_at(jq,jk,newjtheta,RotTransInv[TotalInd]/Weight );//  include /Weight
01579                                 }
01580                         }
01581                 }
01582 
01583                 cout << " Almost Done " << endl;
01584                 system("rm -f WeightImage.???");
01585                 WeightImage  -> write_image("WeightImage.img");
01586 
01587                 return  RotTransInvF ;
01588         } // Finish type 0
01589 
01590         if (type==1) {
01591                 int TotalVol = LradRange*LradRange;
01592 
01593                 float *RotTransInv   = new  float[TotalVol];
01594                 float *WeightInv     = new  float[TotalVol];
01595 
01596                 for (int jW=0; jW<TotalVol; jW++) {
01597                         RotTransInv[jW] = 0;
01598                         WeightInv[jW]   = 0;
01599                 }
01600 
01601 
01602                 for (int Countkxy =0; Countkxy<CountxyMax; Countkxy++){
01603                         int kx = kVecX[Countkxy] ;
01604                         int ky = kVecY[Countkxy] ;
01605                         float k2 = ::sqrt((float)(kx*kx+ky*ky));
01606                         float fkR     = fkVecR[(ky+Mid-1) + (kx+Mid-1) *End] ;
01607                         float fkI     = fkVecI[(ky+Mid-1) + (kx+Mid-1) *End]  ;
01608         //              printf("Countkxy=%d,\t kx=%d, ky=%d, fkR=%3.2f,fkI=%3.2f \n", Countkxy, kx, ky, fkR, fkI);
01609 
01610                         if ((k2==0)|| (k2>Mid) ) { continue;}
01611 
01612                         for (int Countqxy =0; Countqxy<CountxyMax; Countqxy++){   // This is the innermost loop
01613 
01614 //                      up to here, matched perfectly with Matlab
01615                                 int qx   = kVecX[Countqxy] ;
01616                                 int qy   = kVecY[Countqxy] ;
01617                                 float q2   = ::sqrt((float)(qx*qx+qy*qy));
01618                                 if ((q2==0)|| (q2>Mid) ) {continue;}
01619                                 if  ((q2<k2) )   continue;
01620 
01621                                 float fqR     = fkVecR[(qy+Mid-1) + (qx+Mid-1) *End] ;
01622                                 float fqI     = fkVecI[(qy+Mid-1) + (qx+Mid-1) *End]  ;
01623 
01624                                 int kCx  = (-kx-qx);
01625                                 int kCy  = (-ky-qy);
01626                                 int kCIx = ((kCx+Mid+2*End)%End);// labels of the image in C
01627                                 int kCIy = ((kCy+Mid+2*End)%End);
01628                                 kCx  = ((kCIx+End-1)%End)+1-Mid; // correct
01629                                 kCy  = ((kCIy+End-1)%End)+1-Mid ; // correct
01630 
01631                                 float C2   = ::sqrt((float)(kCx*kCx+ kCy*kCy));
01632                                 int CountCxy  = (kCx+Mid-1)*End+(kCy+Mid-1);
01633                                 float fCR     = fkVecR[CountCxy];
01634                                 float fCI     = fkVecI[CountCxy];
01635 
01636 
01637                                 float bispectemp  = (fkR*(fqR*fCR -fqI*fCI) -fkI*(fqI*fCR  +fqR*fCI));
01638 
01639 
01640                                 int k2IndLo  = 0; while ((k2>=radRange[k2IndLo+1]) && (k2IndLo+1 < LradRange ) ) k2IndLo +=1;
01641                                 int k2IndHi = k2IndLo;
01642                                 float k2Lo= radRange[k2IndLo];
01643                                 if (k2IndLo+1< LradRange) {
01644                                         k2IndHi   = k2IndLo+1;
01645                                 }
01646                                 float k2Hi= radRange[k2IndHi];
01647 
01648                                 float kCof =k2-k2Lo;
01649 
01650                                 int q2IndLo  = 0; while ((q2>=radRange[q2IndLo+1]) && (q2IndLo+1 < LradRange ) ) q2IndLo +=1;
01651                                 int q2IndHi=q2IndLo;
01652                                 float q2Lo= radRange[q2IndLo];
01653                                 if (q2IndLo+1 < LradRange)  {
01654                                         q2IndHi   = q2IndLo+1 ;
01655                                 }
01656                                 float qCof = q2-q2Lo;
01657 
01658 
01659                                 for (int jk =1; jk<=2; jk++){
01660                                 for (int jq =1; jq<=2; jq++){
01661 
01662                                         float Weight = (kCof+(1-2*kCof)*(jk==1))*(qCof+(1-2*qCof)*(jq==1));
01663 
01664                                         int k2Ind      =  k2IndLo*(jk==1)      +   k2IndHi*(jk==2);
01665                                         int q2Ind      =  q2IndLo*(jq==1)      +   q2IndHi*(jq==2);
01666                                         int TotalInd   = q2Ind*LradRange+k2Ind;
01667                                         RotTransInv[TotalInd] += Weight*bispectemp;
01668                                         WeightInv[TotalInd]   +=  Weight;
01669         //                              cout << "k2Ind= "<< k2Ind  << " q2Ind="<< q2Ind  << "Weight=" << Weight << endl;
01670                                 }}
01671                         } // Countqxy
01672                 } // Countkxy
01673 
01674 //              cout << "Finished Main Section " << endl;
01675 //              cout << " LradRange " <<LradRange <<  endl;
01676 
01677 
01678                 EMData *RotTransInvF  = new  EMData(LradRange,LradRange);
01679                 EMData *WeightImage   = new  EMData(LradRange,LradRange);
01680 
01681                 for (int jk =0; jk<LradRange ; jk++){// LradRange
01682                 for (int jq =jk; jq<LradRange; jq++){ // LradRange
01683                         int TotalInd      = jq*LradRange+jk;
01684                         int TotalIndBar   = jq*LradRange+jk;
01685                         float Weight = WeightInv[TotalInd] + WeightInv[TotalIndBar];
01686                         if (Weight <=0) continue;
01687                         WeightImage    -> set_value_at(jk,jq,Weight);
01688                         WeightImage    -> set_value_at(jq,jk,Weight);
01689 #ifdef _WIN32
01690                         float ValNow  = pow( (RotTransInv[TotalInd] + RotTransInv[TotalIndBar]) / Weight, 1.0f/3.0f )  ;
01691 #else
01692                         float ValNow  = cbrt( (RotTransInv[TotalInd] + RotTransInv[TotalIndBar]) / Weight )  ;
01693 #endif  //_WIN32
01694                         RotTransInvF -> set_value_at(jk,jq,ValNow);//  include /Weight
01695                         RotTransInvF -> set_value_at(jq,jk,ValNow );//  include /Weight
01696                 }}
01697 
01698                 system("rm -f WeightImage.???");
01699                 WeightImage  -> write_image("WeightImage.img");
01700 
01701                 return  RotTransInvF ;
01702         }
01703 }

EMData * EMData::bispecRotTransInvN ( int  N,
int  NK 
)

This computes the rotational and translational bispectral invariants of an image.

The invariants are labelled by the Fourier Harmonic label given by N. fVec is the real input image NK is the number of Fourier components one wishes to use in calculating this bispectrum the output is a single 2D image whose x,y labels are lengths, corresponding to the two lengths of sides of a triangle

Definition at line 989 of file emdata_transform.cpp.

References calc_bessel(), do_fft(), EMData(), get_value_at(), get_xsize(), process_inplace(), set_size(), set_value_at(), sqrt(), and write_image().

00990 {
00991 
00992         int EndP = this -> get_xsize(); // length(fTrueVec);
00993         int Mid  = (int) ((1+EndP)/2);
00994         int End = 2*Mid-1;
00995 
00996         int CountxyMax = End*End;
00997 
00998         int   *SortfkInds       = new    int[CountxyMax];
00999         int   *kVecX            = new    int[CountxyMax];
01000         int   *kVecY            = new    int[CountxyMax];
01001         float *fkVecR           = new  float[CountxyMax];
01002         float *fkVecI           = new  float[CountxyMax];
01003         float *absD1fkVec       = new  float[CountxyMax];
01004         float *absD1fkVecSorted = new  float[CountxyMax];
01005 
01006         float *jxjyatan2         = new  float[End*End]; //  jxjyatan2[jy*End + jx]  = atan2(jy+1-Mid , jx +1 -Mid);
01007 
01008         EMData * ThisCopy = new EMData(End,End);
01009 
01010         for (int jx=0; jx <End ; jx++) {
01011                 for (int jy=0; jy <End ; jy++) {
01012                         float ValNow = this -> get_value_at(jx,jy);
01013                         ThisCopy -> set_value_at(jx,jy,ValNow);
01014 //              cout<< " jxM= " << jx+1<<" jyM= " << jy+1<< "ValNow" << ValNow << endl; //    Works
01015         }}
01016 
01017 
01018         EMData* fk = ThisCopy -> do_fft();
01019         fk          ->process_inplace("xform.fourierorigin.tocenter");
01020 
01021 //      EMData* fk
01022         EMData* fkRCopy = new EMData(End,End);
01023         EMData* fkICopy = new EMData(End,End);
01024         EMData* fkCopy  = new EMData(End,End);
01025 
01026 
01027         for  (int jCount= 0; jCount<End*End; jCount++) {
01028 //              jCount = jy*End + jx;
01029                 int jx             = jCount%End ;
01030                 int jy             = (jCount-jx)/End ;
01031                 jxjyatan2[jCount]  = atan2((float)(jy+1-Mid) , (float)(jx +1-Mid));
01032         }
01033 
01034 
01035         for (int kEx= 0; kEx<2*Mid; kEx=kEx+2) { // kEx twice the value of the Fourier
01036                                                 // x variable: EMAN index for real, imag
01037                 int kx    = kEx/2;              // kx  is  the value of the Fourier variable
01038                 int kIx   = kx+Mid-1; // This is the value of the index for a matlab image (-1)
01039                 int kCx   =  -kx ;
01040                 int kCIx  = kCx+ Mid-1 ;
01041                 for (int kEy= 0 ; kEy<End; kEy++) { // This is the value of the EMAN index
01042                         int kIy              =  kEy       ; //  This is the value of the index for a matlab image (-1)
01043                         int ky               =  kEy+1-Mid; // (kEy+ Mid-1)%End - Mid+1 ;  // This is the actual value of the Fourier variable
01044                         float realVal        =  fk -> get_value_at(kEx  ,kEy) ;
01045                         float imagVal        =  fk -> get_value_at(kEx+1,kEy) ;
01046                         float absVal         =  ::sqrt(realVal*realVal+imagVal*imagVal);
01047                         float fkAng          =  atan2(imagVal,realVal);
01048 
01049                         float NewRealVal   ;
01050                         float NewImagVal   ;
01051                         float AngMatlab    ;
01052 
01053                         if (kIx==Mid-1) {
01054 //                              AngMatlab = -fkAng - 2.*M_PI*(kIy+ 1-Mid)*(Mid)/End;
01055 //                      cout<< "i= " << i << " kIx= " << kIx << " kIy=" << kIy << " fkVecR[i] =" << fkVecR[i]<< " fkVecI[i]="  << fkVecI[i] <<"  angle[i]= "  << AngMatlab << endl;
01056                         }
01057 
01058                         if (kIx>Mid-1){
01059 //                      cout<< "i= " << i << " kIx= " << kIx << " kIy=" << kIy << " fkVecR[i] =" << fkVecR[i]<< " fkVecI[i]="  << fkVecI[i] <<"  angle[i]= "  << AngMatlab << endl;
01060                         }
01061 
01062                         AngMatlab = fkAng - 2.0f*M_PI*(kx +ky)*(Mid)/End;
01063                         NewRealVal  =   absVal*cos(AngMatlab);
01064                         NewImagVal  =   absVal*sin(AngMatlab);
01065 
01066 
01067                         fkVecR[kIy+kIx *End] =  NewRealVal ;
01068                         fkVecR[kIy+kCIx*End] =  NewRealVal ;
01069                         fkVecI[kIy+kIx *End] =  NewImagVal ;
01070                         fkVecI[kIy+kCIx*End] = -NewImagVal ;
01071                         absD1fkVec[kIy + kIx  *End] = absVal;
01072                         absD1fkVec[kIy + kCIx *End] = absVal;
01073                         kVecX[kIy+kIx  *End] =  kx      ;
01074                         kVecX[kIy+kCIx *End] =  kCx    ;
01075                         kVecY[kIy+kIx  *End] =  ky     ;
01076                         kVecY[kIy+kCIx *End] =  ky     ;
01077 //                      printf("kx=%d,ky=%d,tempVal =%f+ i %4.2f \n",kx,ky,realVal,imagVal );
01078 //                      cout << "kx = " << kx << "; ky = "<< ky << "; val is" << realVal<<"+ i "<<imagVal<< endl;
01079 
01080 //                      cout << "kIMx = "<< kIx+1 << "; kIMy = "<< kIy+1 <<"; fkAng*9/ 2pi is " << fkAng*9/2/M_PI<<  endl;
01081 //                      cout << "kIMx = "<< kIx+1 << "; kIMy = "<< kIy+1 <<"; absval is " << absVal<<  "; realval is " << NewRealVal<< "; imagval is " << NewImagVal<< endl;
01082                         fkCopy  -> set_value_at(kIx ,kIy, absVal);
01083                         fkCopy  -> set_value_at(kCIx,kIy, absVal);
01084                         fkRCopy -> set_value_at(kIx, kIy, NewRealVal);
01085                         fkRCopy -> set_value_at(kCIx,kIy, NewRealVal);
01086                         fkICopy -> set_value_at(kIx, kIy, NewImagVal);
01087                         fkICopy -> set_value_at(kCIx,kIy,-NewImagVal);
01088 
01089                 }
01090         }
01091         system("rm -f fkCopy.???");
01092         system("rm -f fk?Copy.???");
01093         fkCopy  -> write_image("fkCopy.img");
01094         fkRCopy -> write_image("fkRCopy.img");
01095         fkICopy -> write_image("fkICopy.img");
01096 
01097         cout << "Starting the sort "<< endl;
01098 
01099         vector< pair<float, int> > absInds;
01100         for(int i  = 0; i < CountxyMax; ++i ) {
01101                 pair<float,int> p;
01102                 p = make_pair(absD1fkVec[i],i); // p = make_pair(rand(),i);
01103                 absInds.push_back( p);
01104         }
01105 
01106         std::sort(absInds.begin(),absInds.end());
01107 
01108         for(int i  = 0; i < CountxyMax; ++i ) {
01109                 pair<float,int> p   ;
01110                 p = absInds[i]         ;
01111                 absD1fkVecSorted[CountxyMax-1-i] =  p.first ;
01112                 SortfkInds[CountxyMax-1-i]       =  p.second ;
01113         }
01114 
01115         cout << "Ending the sort "<< endl;
01116 
01117 // float AngsMat[] ={2.8448, -0.3677,-0.2801,-1.0494,-1.7836,-2.5179, 2.9959, 3.0835,-0.1290,-0.8876,2.1829, 2.2705,1.5011,0.7669,0.0327,-0.7366,-0.6489,2.4215,-1.6029,1.4676,1.5552,0.7859,0.0517,-0.6825,-1.4518,-1.3642,1.7063,-1.7845,1.2859,1.3736,0.6043,-0.1299,-0.8642,-1.6335,-1.5459,1.5247,-1.6546,1.4159,1.5036,0.7342,0,-0.7342,-1.5036,-1.4159,1.6546,-1.5247,1.5459,1.6335,0.8642,0.1299,-0.6043,-1.3736,-1.286,1.7846,-1.7063,1.3642,1.4519,0.6825,-0.0517,-0.7859,-1.5553,-1.4676,1.6029,-2.4216,0.649,0.7366,-0.0327,-0.767,-1.5012,-2.2705,-2.1829,0.8877,0.1291,-3.0836,-2.9959,2.5179,1.7837,1.0495,0.2801,0.3677,-2.8449};
01118 
01119 
01120         for(int i  = 0; i < CountxyMax; ++i ) {  // creates a new fkVec
01121                 int Si  = SortfkInds[i];
01122                 int kIx = (int)  Si/End;  kIx = (int)  i/End; // i = kIx*End+kIy
01123                 int kIy = Si  - kIx*End;  kIy = i  - kIx*End;
01124                 int iC = (End-1-kIx)*End + (End-1-kIy);
01125 //              if (i<30) { cout<< "i= " << i << " kIx= " << kIx << " kIy=" << kIy << " valAft=" << absD1fkVecSorted[i]<< " valBef="  <<     absD1fkVec[Si] << "  SortfkInds = " << Si <<endl; }// This worked
01126 //              cout<< "i= " << i << " kIx= " << kIx << " kIy=" << kIy << " fkVecR[i] =" << fkVecR[i]<< " fkVecI[i]="  << fkVecI[i] <<"  angle[i]= "  << fkAng << endl;
01127         }
01128         cout<< "Ratio of Last Amplitude to First Amplitude= " << absD1fkVecSorted[NK] /absD1fkVecSorted[0]  << endl;
01129 
01130 //      pause;
01131 
01132         for(int i  = 0; i < NK; ++i ) { // Prints out the new fkVec ,  CountxyMax
01133                 int Si= SortfkInds[i];
01134                 int kIx = (int)  Si/End; // i = kIx*End+kIy
01135                 int kIy = Si  - kIx*End;
01136  //             cout << " kIxM= " << kIx+1 << " kIyM=" << kIy+1 << " fkVecAbs=" << ::sqrt(fkVecR[Si]*fkVecR[Si] +  fkVecI[Si]* fkVecI[Si]) << " fkVecAbs=" << absD1fkVecSorted[i] << " kx= " << kVecX[Si] <<  " ky=" << kVecY[Si] <<  endl;
01137         }
01138 
01139 //       angEMAN+angMat+angDiff    =0  mod 2 pi
01140 
01141 //      angDiff=  2*pi*((-4):4)*(Mid)/End; angEMAN+angMat+angDiff= integer*2 *pi
01142 //              [  absD1fkVecSorted, SortfkInds] =sort( absD1fkVec,'descend') ;
01143 //      Util::sort_mat(&absD1fkVec[0],&absD1fkVec[Countxy],&SortfkInds[0],&SortfkInds[Countxy]);
01144 
01145 
01146 //      Let radial sampling be 0:0.5:(Mid-1)
01147 
01148  //     int NK=  min(12,CountxyMax) ;
01149 
01150 
01151 
01152         cout << "NK = " << NK << endl;
01153         float frR= 3.0/4.0;
01154         int LradRange= (int) (floor(Mid/frR)) ;
01155 
01156         float *radRange = new float[LradRange]; //= 0:.75:(Mid-1);
01157         radRange[0]=0;
01158         for (int irad=1; irad < LradRange; irad++){
01159                         radRange[irad] = radRange[irad-1] + frR; }
01160 
01161 
01162 
01163          // should equal to (2*Mid-1)
01164         cout << "Starting the calculation of invariants for N= " << N << endl;
01165 
01166 /*      int NMax=5;            */
01167 
01168         EMData* RotTransInv = new EMData();
01169         RotTransInv -> set_size(LradRange,LradRange);
01170 
01171 
01172 //      float  *RotTransInv       = new float[LradRange*LradRange ] ;
01173 //      float  *RotTransInvN      = new float[LradRange*LradRange*(NMax+1) ] ;
01174 
01175 //      for (int N=0 ; N<NMax; N++) {
01176 
01177         for (int jr1=0; jr1 < LradRange ; jr1++ ) { // LradRange
01178                 float r1= radRange[jr1];
01179 //              cout << "Pre jr2 "<< endl;
01180                 for (int jr2=0;  jr2<LradRange;  jr2++ ) { //LradRange
01181                         float r2= radRange[jr2];
01182                         float RotTransInvTemp=0;
01183                         for (int jCountkxy =0; jCountkxy<NK; jCountkxy++){
01184                                 int Countkxy =SortfkInds[jCountkxy] ;   // 1: CountxyMax
01185                                 int kx = kVecX[Countkxy] ;
01186                                 int ky = kVecY[Countkxy] ;
01187                                 float k2 = (float)(kx*kx+ky*ky);
01188                                 if (k2==0) { continue;}
01189                                 float phiK =0;
01190                                 if (k2>0) phiK= jxjyatan2[ (ky+Mid-1)*End + kx+Mid-1];  phiK= atan2((float)ky,(float)kx);
01191 
01192                                 float fkR     = fkVecR[Countkxy] ;
01193                                 float fkI     = fkVecI[Countkxy]  ;
01194 /*                              printf("jCountkxy=%d, Countkxy=%d,absD1fkVec(Countkxy)=%f,\t\t kx=%d, ky=%d \n", jCountkxy, Countkxy, absD1fkVec[Countkxy], kx, ky);*/
01195 
01196                                 for (int jCountqxy =0; jCountqxy<NK; jCountqxy++){
01197                                         int Countqxy =SortfkInds[jCountqxy] ;   // Countqxy is the index for absD1fkVec
01198                                         int qx   = kVecX[Countqxy] ;
01199                                         int qy   = kVecY[Countqxy] ;
01200                                         int q2   = qx*qx+qy*qy;
01201                                         if (q2==0) {continue;}
01202                                         float phiQ =0;
01203                                         if (q2>0) phiQ = jxjyatan2[ (qy+Mid-1)*End + qx+Mid-1];   phiQ=atan2((float)qy,(float)qx);
01204                                         float fqR     = fkVecR[Countqxy]  ;
01205                                         float fqI     = fkVecI[Countqxy]  ;
01206                                         int kCx  = (-kx-qx);
01207                                         int kCy  = (-ky-qy);
01208                                         int kCIx = ((kCx+Mid+2*End)%End);// labels of the image in C
01209                                         int kCIy = ((kCy+Mid+2*End)%End);
01210                                         kCx  = kCIx-Mid; // correct
01211                                         kCy  = kCIy-Mid; // correct
01212                                         int CountCxy = kCIx*End+kCIy;
01213                                         float fCR     = fkVecR[CountCxy];
01214                                         float fCI     = fkVecI[CountCxy];
01215                                         if (jr1+jr2==-1) {
01216                                         printf("jCountqxy=%d , Countqxy=%d, absD1fkVec(Countqxy)=%f,qx=%d, qy=%d \n", jCountqxy, Countqxy, absD1fkVec[Countqxy],qx, qy);
01217                                         printf(" CountCxy=%d,absD1fkVec[CountCxy]=%f,  kCx=%d,     kCy=%d \n",CountCxy, absD1fkVec[CountCxy], kCx, kCy );
01218                                         }
01219                                         for (int p=0; p<NK; p++){
01220 //                                              printf("p=%d, SortfkInds[p]=%d, CountCxy =%d \n", p,SortfkInds[p], CountCxy);
01221                                                 if (SortfkInds[p]==CountCxy){
01222                                                         float Arg1 = 2.0f*M_PI*r1*::sqrt((float) q2)/End;
01223                                                         float Arg2 = 2.0f*M_PI*r2*::sqrt((float) k2)/End;
01224 //                                                      printf("Arg1=%4.2f, Arg2=%4.2f,  \n",Arg1, Arg2 );
01225 //                                                      if (Arg1+ Arg2<15) {
01226                                                                 float bispectemp  = (fkR*(fqR*fCR -fqI*fCI) -fkI*(fqI*fCR  +fqR*fCI))
01227                                                                 * cos(N*(phiK-phiQ+M_PI));
01228                                                                 bispectemp  -= (fkR*(fqR*fCI + fqI*fCR) +fkI*(fqR*fCR - fqI*fCI))
01229                                                                 * sin(N*(phiK-phiQ+M_PI));
01230                                                                 float bess1 = calc_bessel(N, Arg1 );
01231                                                                 float bess2 = calc_bessel(N, Arg2 );
01232 //                      printf("fkr=%4.2f, fqr=%4.2f, bess1=%4.2f,bess2=%4.2f \n",fkR, fqR, bess1, bess2);
01233 /*                      printf("p =%d, SortfkInds[p]=%d, CountCxy=%d, Arg1 =%4.2f, bess1=%4.2f,  \n",
01234                                 p, SortfkInds[p],CountCxy, Arg1, bess1);*/
01235                                                                 RotTransInvTemp   = RotTransInvTemp  + bispectemp  * bess1*bess2 ;
01236 //                                                      }
01237                                                 }
01238                                         }
01239                                 } // jCountqxy
01240                         } // jCountkxy
01241                         RotTransInv -> set_value_at(jr1,jr2, RotTransInvTemp)   ;
01242 /*              RotTransInvN[jr1 + LradRange*jr2+LradRange*LradRange*N] = RotTransInvTemp  ;*/
01243                 } //jr2
01244         } //jr1
01245 // }//N
01246 
01247         return  RotTransInv ;
01248 
01249 
01250 }

vector< float > EMData::calc_az_dist ( int  n,
float  a0,
float  da,
float  rmin,
float  rmax 
)

Caculates the azimuthal distributions.

works for real or complex images, 2D only.

Parameters:
n Number of elements.
a0 Starting angle.
da Angle step.
rmin Minimum radius.
rmax Maximum radius.
Exceptions:
ImageDimensionException If image is 3D.
Returns:
Float array to store the data.

Definition at line 2153 of file emdata.cpp.

References data, ENTERFUNC, EXITFUNC, get_data(), get_ndim(), EMAN::Util::hypot_fast(), ImageDimensionException, is_complex(), is_ri(), nx, ny, x, and y.

02154 {
02155         ENTERFUNC;
02156 
02157         a0=a0*M_PI/180.0f;
02158         da=da*M_PI/180.0f;
02159 
02160         if (get_ndim() > 2) {
02161                 throw ImageDimensionException("no 3D image");
02162         }
02163 
02164         float *yc = new float[n];
02165 
02166         vector<float>   vd(n);
02167         for (int i = 0; i < n; i++) {
02168                 yc[i] = 0.00001f;
02169         }
02170 
02171         float * data = get_data();
02172         if (is_complex()) {
02173                 int c = 0;
02174                 for (int y = 0; y < ny; y++) {
02175                         for (int x = 0; x < nx; x += 2, c += 2) {
02176                                 int x1 = x / 2;
02177                                 int y1 = y<ny/2?y:y-ny;
02178                                 float r = (float)Util::hypot_fast(x1,y1);
02179 
02180                                 if (r >= rmin && r <= rmax) {
02181                                         float a = 0;
02182 
02183                                         if (y != ny / 2 || x != 0) {
02184                                                 a = (atan2((float)y1, (float)x1) - a0) / da;
02185                                         }
02186 
02187                                         int i = (int)(floor(a));
02188                                         a -= i;
02189 
02190                                         if (i == 0) {
02191                                                 vd[0] += data[c] * (1.0f - a);
02192                                                 yc[0] += (1.0f - a);
02193                                         }
02194                                         else if (i == n - 1) {
02195                                                 vd[n - 1] += data[c] * a;
02196                                                 yc[n - 1] += a;
02197                                         }
02198                                         else if (i > 0 && i < (n - 1)) {
02199                                                 float h = 0;
02200                                                 if (is_ri()) {
02201 #ifdef  _WIN32
02202                                                         h = (float)_hypot(data[c], data[c + 1]);
02203 #else
02204                                                         h = (float)hypot(data[c], data[c + 1]);
02205 #endif  //_WIN32
02206                                                 }
02207                                                 else {
02208                                                         h = data[c];
02209                                                 }
02210 
02211                                                 vd[i] += h * (1.0f - a);
02212                                                 yc[i] += (1.0f - a);
02213                                                 vd[i + 1] += h * a;
02214                                                 yc[i + 1] += a;
02215                                         }
02216                                 }
02217                         }
02218                 }
02219         }
02220         else {
02221                 int c = 0;
02222                 float half_nx = (nx - 1) / 2.0f;
02223                 float half_ny = (ny - 1) / 2.0f;
02224 
02225                 for (int y = 0; y < ny; y++) {
02226                         for (int x = 0; x < nx; x++, c++) {
02227                                 float y1 = y - half_ny;
02228                                 float x1 = x - half_nx;
02229 #ifdef  _WIN32
02230                                 float r = (float)_hypot(x1, y1);
02231 #else
02232                                 float r = (float)hypot(x1, y1);
02233 #endif
02234 
02235                                 if (r >= rmin && r <= rmax) {
02236                                         float a = 0;
02237                                         if (x1 != 0 || y1 != 0) {
02238                                                 a = atan2(y1, x1);
02239                                                 if (a < 0) {
02240                                                         a += M_PI * 2;
02241                                                 }
02242                                         }
02243 
02244                                         a = (a - a0) / da;
02245                                         int i = static_cast < int >(floor(a));
02246                                         a -= i;
02247 
02248                                         if (i == 0) {
02249                                                 vd[0] += data[c] * (1.0f - a);
02250                                                 yc[0] += (1.0f - a);
02251                                         }
02252                                         else if (i == n - 1) {
02253                                                 vd[n - 1] += data[c] * a;
02254                                                 yc[n - 1] += (a);
02255                                         }
02256                                         else if (i > 0 && i < (n - 1)) {
02257                                                 vd[i] += data[c] * (1.0f - a);
02258                                                 yc[i] += (1.0f - a);
02259                                                 vd[i + 1] += data[c] * a;
02260                                                 yc[i + 1] += a;
02261                                         }
02262                                 }
02263                         }
02264                 }
02265         }
02266 
02267 
02268         for (int i = 0; i < n; i++) {
02269                 vd[i] /= yc[i];
02270         }
02271 
02272         if( yc )
02273         {
02274                 delete[]yc;
02275                 yc = 0;
02276         }
02277 
02278         return vd;
02279 
02280         EXITFUNC;
02281 }

float EMData::calc_center_density (  ) 

Calculates the density value at the peak of the image histogram, sort of like the mode of the density.

Returns:
The density value at the peak of the image histogram.

Definition at line 287 of file emdata_metadata.cpp.

References ENTERFUNC, EXITFUNC, get_attr(), get_data(), norm(), nx, ny, and nz.

00288 {
00289         ENTERFUNC;
00290 
00291         float center = get_attr("mean");
00292         float sigma = get_attr("sigma");
00293         float ds = sigma / 2;
00294         size_t size = nx * ny * nz;
00295         float *d = get_data();
00296         float sigma1 = sigma / 20;
00297         float sigma2 = sigma / 1000;
00298 
00299         while (ds > sigma1) {
00300                 double sum = 0;
00301                 int norm = 0;
00302 
00303                 for (size_t i = 0; i < size; i++) {
00304                         if (fabs(d[i] - center) < ds) {
00305                                 sum += d[i];
00306                                 norm++;
00307                         }
00308                 }
00309                 if (!norm) {
00310                         break;
00311                 }
00312                 float mean = (float)(sum / norm);
00313                 if (fabs(mean - center) < sigma2) {
00314                         ds *= 0.5f;
00315                 }
00316                 center = mean;
00317         }
00318         EXITFUNC;
00319 
00320         return center;
00321 }

FloatPoint EMData::calc_center_of_mass (  ) 

Calculate the center of mass using an algorithm written by S Ludtke.

Author:
David Woolford
Date:
Fri Jun 6th 2008

Definition at line 468 of file emdata_metadata.cpp.

References data, get_attr(), get_data(), nx, nxy, ny, and nz.

Referenced by EMAN::ToMassCenterProcessor::process_inplace().

00469 {
00470         float *data = get_data();
00471 
00472         float sigma = get_attr("sigma");
00473         float mean = get_attr("mean");
00474         float m = 0;
00475 
00476         FloatPoint com(0,0,0);
00477         for (int i = 0; i < nx; ++i) {
00478                 for (int j = 0; j < ny; ++j) {
00479                         int j2 = nx * j;
00480                         for (int k = 0; k < nz; ++k) {
00481                                 size_t l = i + j2 + k * nxy;
00482                                 if (data[l] >= sigma * 1.25 + mean) {           // arbitrary constant to threshold out noise
00483                                         com[0] += i * data[l];
00484                                         com[1] += j * data[l];
00485                                         com[2] += k * data[l];
00486                                         m += data[l];
00487                                 }
00488                         }
00489                 }
00490         }
00491 
00492         com[0] /= m;
00493         com[1] /= m;
00494         com[2] /= m;
00495 
00496         return com;
00497 }

float EMData::calc_dist ( EMData second_img,
int  y_index = 0 
) const

Calculates the distance between 2 vectors.

'this' image is 1D, which contains a vector; 'second_img' may be nD. One of its row is used as the second vector. 'second_img' and 'this' must have the same x size.

Parameters:
second_img The image used to caculate the distance.
y_index Specifies which row in 'second_img' is used to do the caculation.
Exceptions:
ImageDimensionException If 'this' image is not 1D.
ImageFormatException If the 2 images don't have same xsize.
Returns:
The distance between 2 vectors.

Definition at line 2982 of file emdata.cpp.

References ENTERFUNC, EXITFUNC, get_data(), get_ndim(), get_xsize(), get_ysize(), ImageDimensionException, ImageFormatException, nx, ny, sqrt(), and EMAN::Util::square().

02983 {
02984         ENTERFUNC;
02985 
02986         if (get_ndim() != 1) {
02987                 throw ImageDimensionException("'this' image is 1D only");
02988         }
02989 
02990         if (second_img->get_xsize() != nx || ny != 1) {
02991                 throw ImageFormatException("image xsize not same");
02992         }
02993 
02994         if (y_index > second_img->get_ysize() || y_index < 0) {
02995                 return -1;
02996         }
02997 
02998         float ret = 0;
02999         float *d1 = get_data();
03000         float *d2 = second_img->get_data() + second_img->get_xsize() * y_index;
03001 
03002         for (int i = 0; i < nx; i++) {
03003                 ret += Util::square(d1[i] - d2[i]);
03004         }
03005         EXITFUNC;
03006         return std::sqrt(ret);
03007 }

EMData * EMData::calc_fast_sigma_image ( EMData mask  ) 

Calculates the local standard deviation (sigma) image using the given mask image.

The mask image is typically much smaller than this image, and consists of ones, or is a small circle consisting of ones. The extent of the non zero neighborhood explicitly defines the range over which the local standard deviation is determined. Fourier convolution is used to do the math, ala Roseman (2003, Ultramicroscopy) However, Roseman was just working on methods Van Heel had presented earlier. The normalize flag causes the mask image to be processed so that it has a unit sum. Works in 1,2 and 3D

Parameters:
mask the image that will be used to define the neighborhood for determine the local standard deviation
Returns:
the sigma image, the phase origin is at the corner (not the center)
Exceptions:
ImageDimensionException if the dimensions of with do not match those of this
ImageDimensionException if any of the dimensions sizes of with exceed of this image's.
Author:
David Woolford
Date:
April 2008

Definition at line 3010 of file emdata.cpp.

References clip_inplace(), convolute(), copy(), EMData(), ENTERFUNC, EXITFUNC, get_clip(), get_edge_mean(), get_ndim(), get_size(), get_value_at(), get_xsize(), get_ysize(), get_zsize(), ImageDimensionException, mult(), nx, ny, nz, process_inplace(), and sub().

Referenced by calc_flcf().

03011 {
03012         ENTERFUNC;
03013 
03014         bool maskflag = false;
03015         if (mask == 0) {
03016                 mask = new EMData(nx,ny,nz);
03017                 mask->process_inplace("testimage.circlesphere");
03018                 maskflag = true;
03019         }
03020 
03021         if (get_ndim() != mask->get_ndim() ) throw ImageDimensionException("The dimensions do not match");
03022 
03023         int mnx = mask->get_xsize(); int mny = mask->get_ysize(); int mnz = mask->get_zsize();
03024 
03025         if ( mnx > nx || mny > ny || mnz > nz)
03026                 throw ImageDimensionException("Can not calculate variance map using an image that is larger than this image");
03027 
03028         size_t P = 0;
03029         for(size_t i = 0; i < mask->get_size(); ++i){
03030                 if (mask->get_value_at(i) != 0){
03031                         ++P;
03032                 }
03033         }
03034         float normfac = 1.0f/(float)P;
03035 
03036 //      bool undoclip = false;
03037 
03038         int nxc = nx+mnx; int nyc = ny+mny; int nzc = nz+mnz;
03039 //      if ( mnx < nx || mny < ny || mnz < nz) {
03040         Region r;
03041         if (ny == 1) r = Region((mnx-nxc)/2,nxc);
03042         else if (nz == 1) r = Region((mnx-nxc)/2, (mny-nyc)/2,nxc,nyc);
03043         else r = Region((mnx-nxc)/2, (mny-nyc)/2,(mnz-nzc)/2,nxc,nyc,nzc);
03044         mask->clip_inplace(r,0.0);
03045         //Region r((mnx-nxc)/2, (mny-nyc)/2,(mnz-nzc)/2,nxc,nyc,nzc);
03046         //mask->clip_inplace(r);
03047         //undoclip = true;
03048         //}
03049 
03050         // Here we generate the local average of the squares
03051         Region r2;
03052         if (ny == 1) r2 = Region((nx-nxc)/2,nxc);
03053         else if (nz == 1) r2 = Region((nx-nxc)/2, (ny-nyc)/2,nxc,nyc);
03054         else r2 = Region((nx-nxc)/2, (ny-nyc)/2,(nz-nzc)/2,nxc,nyc,nzc);
03055         EMData* squared = get_clip(r2,get_edge_mean());
03056 
03057         EMData* tmp = squared->copy();
03058         Dict pow;
03059         pow["pow"] = 2.0f;
03060         squared->process_inplace("math.pow",pow);
03061         EMData* s = mask->convolute(squared);//ming, mask squared exchange
03062         squared->mult(normfac);
03063 
03064         EMData* m = mask->convolute(tmp);//ming, tmp mask exchange
03065         m->mult(normfac);
03066         m->process_inplace("math.pow",pow);
03067         delete tmp; tmp = 0;
03068         s->sub(*m);
03069         // Here we finally generate the standard deviation image
03070         s->process_inplace("math.sqrt");
03071 
03072 //      if ( undoclip ) {
03073 //              Region r((nx-mnx)/2, (ny-mny)/2, (nz-mnz)/2,mnx,mny,mnz);
03074 //              mask->clip_inplace(r);
03075 //      }
03076 
03077         if (maskflag) {
03078                 delete mask;
03079                 mask = 0;
03080         } else {
03081                 Region r;
03082                 if (ny == 1) r = Region((nxc-mnx)/2,mnx);
03083                 else if (nz == 1) r = Region((nxc-mnx)/2, (nyc-mny)/2,mnx,mny);
03084                 else r = Region((nxc-mnx)/2, (nyc-mny)/2,(nzc-mnz)/2,mnx,mny,mnz);
03085                 mask->clip_inplace(r);
03086         }
03087 
03088         delete squared;
03089         delete m;
03090 
03091         s->process_inplace("xform.phaseorigin.tocenter");
03092         Region r3;
03093         if (ny == 1) r3 = Region((nxc-nx)/2,nx);
03094         else if (nz == 1) r3 = Region((nxc-nx)/2, (nyc-ny)/2,nx,ny);
03095         else r3 = Region((nxc-nx)/2, (nyc-ny)/2,(nzc-nz)/2,nx,ny,nz);
03096         s->clip_inplace(r3);
03097         EXITFUNC;
03098         return s;
03099 }

EMData * EMData::calc_flcf ( EMData with  ) 

Calculates the cross correlation with local normalization between 2 images.

This is a faster version of local correlation that make use of Fourier convolution and correlation. With is the template - the thing that you wish to find in the this image. It should not be unecessarily padded. The function uses the size of with to determine the extent of the local neighborhood used in the local normalization (for technical details, see calc_fast_sigma_image). Note that this function circularly masks the template at its radius so the calling function need not do this beforehand. Works in 1,2 and 3D.

Parameters:
with The image used to calculate cross correlation (the template)
Returns:
the local normalized cross correlation image - the phase origin is at the corner of the image
Author:
David Woolford
Date:
April 2008

Definition at line 3103 of file emdata.cpp.

References calc_ccf(), calc_fast_sigma_image(), clip_inplace(), copy(), div(), EMData(), ENTERFUNC, EXITFUNC, get_xsize(), get_ysize(), get_zsize(), mult(), nx, ny, nz, and process_inplace().

Referenced by EMAN::TranslationalAligner::align().

03104 {
03105         ENTERFUNC;
03106         EMData *this_copy=this;
03107         this_copy=copy();
03108 
03109         int mnx = with->get_xsize(); int mny = with->get_ysize(); int mnz = with->get_zsize();
03110         int nxc = nx+mnx; int nyc = ny+mny; int nzc = nz+mnz;
03111 
03112         // Ones is a circular/spherical mask, consisting of 1s.
03113         EMData* ones = new EMData(mnx,mny,mnz);
03114         ones->process_inplace("testimage.circlesphere");
03115 
03116         // Get a copy of with, we will eventually resize it
03117         EMData* with_resized = with->copy();
03118         with_resized->process_inplace("normalize");
03119         with_resized->mult(*ones);
03120 
03121         EMData* s = calc_fast_sigma_image(ones);// Get the local sigma image
03122 
03123         Region r1;
03124         if (ny == 1) r1 = Region((mnx-nxc)/2,nxc);
03125         else if (nz == 1) r1 = Region((mnx-nxc)/2, (mny-nyc)/2,nxc,nyc);
03126         else r1 = Region((mnx-nxc)/2, (mny-nyc)/2,(mnz-nzc)/2,nxc,nyc,nzc);
03127         with_resized->clip_inplace(r1,0.0);
03128 
03129         Region r2;
03130         if (ny == 1) r2 = Region((nx-nxc)/2,nxc);
03131         else if (nz == 1) r2 = Region((nx-nxc)/2, (ny-nyc)/2,nxc,nyc);
03132         else r2 = Region((nx-nxc)/2, (ny-nyc)/2,(nz-nzc)/2,nxc,nyc,nzc);
03133         this_copy->clip_inplace(r2,0.0);
03134 
03135         EMData* corr = this_copy->calc_ccf(with_resized); // the ccf results should have same size as sigma
03136 
03137         corr->process_inplace("xform.phaseorigin.tocenter");
03138         Region r3;
03139         if (ny == 1) r3 = Region((nxc-nx)/2,nx);
03140         else if (nz == 1) r3 = Region((nxc-nx)/2, (nyc-ny)/2,nx,ny);
03141         else r3 = Region((nxc-nx)/2, (nyc-ny)/2,(nzc-nz)/2,nx,ny,nz);
03142         corr->clip_inplace(r3);
03143 
03144         corr->div(*s);
03145 
03146         delete with_resized; delete ones; delete this_copy; delete s;
03147         EXITFUNC;
03148         return corr;
03149 }

vector< float > EMData::calc_fourier_shell_correlation ( EMData with,
float  w = 1.0f 
)

Calculate CCF in Fourier space as a function of spatial frequency between a pair of 2-3D images (corners not included).

The input image 'with' must have the same size to 'this' image. Input images can be either real or Fourier in arbitrary combination.

Parameters:
[in] with The image used to caculate the fourier shell
[in] w Ring/shell width in Fourier space.
Exceptions:
ImageFormatException If the 2 images are not same size.
NullPointerException if the input image is null
Cannot calculate FSC for 1D images
Returns:
Vector of 3*k FSC results (frequencies, FSC values, error) k - length of FSC curve, depends on dimensions of the image and ring width 1 column - normalized frequency [0,0.5] 2 column - FSC, 3 column - error of the FSC = 1/sqrt(n), where n is the number of Fourier coefficients within given shell.

Definition at line 782 of file emdata_sparx.cpp.

References do_fft_inplace(), ENTERFUNC, EXITFUNC, get_data(), get_xsize(), get_ysize(), get_zsize(), ImageFormatException, is_complex(), is_fftodd(), max, norm_pad(), NullPointerException, nx, ny, nz, EMAN::Util::round(), and sqrt().

Referenced by ali3d_d(), and EMAN::FRCCmp::cmp().

00783 {
00784         ENTERFUNC;
00785 
00786 /*
00787  ******************************************************
00788  *DISCLAIMER
00789  * 08/16/05 P.A.Penczek
00790  * The University of Texas
00791  * Pawel.A.Penczek@uth.tmc.edu
00792  * Please do not modify the content of calc_fourier_shell_correlation
00793  ******************************************************/
00794 /*
00795 Fourier Ring/Shell Correlation
00796 Purpose: Calculate CCF in Fourier space as a function of spatial frequency
00797          between a pair of 2-3D images.
00798 Method: Calculate FFT (if needed), calculate FSC.
00799 Input:  f - real or complex 2-3D image
00800         g - real or complex 2-3D image
00801         w - float ring width
00802 Output: 2D 3xk real image.
00803         k - length of FSC curve, depends on dimensions of the image and ring width
00804         1 column - FSC,
00805         2 column - normalized frequency [0,0.5]
00806         3 column - currently n /error of the FSC = 1/sqrt(n),
00807                      where n is the number of Fourier coefficients within given shell
00808 */
00809         int needfree=0, nx, ny, nz, nx2, ny2, nz2, ix, iy, iz, kz, ky, ii;
00810         float  dx2, dy2, dz2, argx, argy, argz;
00811 
00812         if (!with) {
00813                 throw NullPointerException("NULL input image");
00814         }
00815 
00816 
00817         EMData *f = this;
00818         EMData *g = with;
00819 
00820         nx  = f->get_xsize();
00821         ny  = f->get_ysize();
00822         nz  = f->get_zsize();
00823 
00824         if (ny==0 && nz==0) {
00825                 throw ImageFormatException( "Cannot calculate FSC for 1D images");
00826         }
00827 
00828         if (f->is_complex()) nx = (nx - 2 + f->is_fftodd()); // nx is the real-space size of the input image
00829         int lsd2 = (nx + 2 - nx%2) ; // Extended x-dimension of the complex image
00830 
00831 //  Process f if real
00832         EMData* fpimage = NULL;
00833         if(f->is_complex()) fpimage = f;
00834         else {fpimage= f->norm_pad(false, 1); fpimage->do_fft_inplace(); needfree|=1;} // Extend and do the FFT if f is real
00835 
00836 
00837 //  Process g if real
00838         EMData* gpimage = NULL;
00839         if(g->is_complex()) gpimage = g;
00840         else {gpimage= g->norm_pad(false, 1); gpimage->do_fft_inplace(); needfree|=2;} // Extend and do the FFT if f is real
00841 
00842 
00843         float *d1 = fpimage->get_data();
00844         float *d2 = gpimage->get_data();
00845 
00846         nx2=nx/2; ny2 = ny/2; nz2 = nz/2;
00847         dx2 = 1.0f/float(nx2)/float(nx2);
00848         dy2 = 1.0f/float(ny2)/float(ny2);
00849 
00850 #ifdef _WIN32
00851         dz2 = 1.0f / _MAX(float(nz2),1.0f)/_MAX(float(nz2),1.0f);
00852 
00853         int inc = Util::round(float( _MAX( _MAX(nx2,ny2),nz2) )/w );
00854 #else
00855         dz2 = 1.0f/std::max(float(nz2),1.0f)/std::max(float(nz2),1.0f);
00856 
00857         int inc = Util::round(float(std::max(std::max(nx2,ny2),nz2))/w);
00858 #endif  //_WIN32
00859 
00860         double *ret = new double[inc+1];
00861         double *n1  = new double[inc+1];
00862         double *n2  = new double[inc+1];
00863         float  *lr  = new float[inc+1];
00864         for (int i = 0; i <= inc; i++) {
00865                 ret[i] = 0; n1[i] = 0; n2[i] = 0; lr[i]=0;
00866         }
00867 
00868         for ( iz = 0; iz <= nz-1; iz++) {
00869                 if(iz>nz2) kz=iz-nz; else kz=iz; argz = float(kz*kz)*dz2;
00870                 for ( iy = 0; iy <= ny-1; iy++) {
00871                         if(iy>ny2) ky=iy-ny; else ky=iy; argy = argz + float(ky*ky)*dy2;
00872                         for ( ix = 0; ix <= lsd2-1; ix+=2) {
00873                         // Skip Friedel related values
00874                                 if(ix>0 || (kz>=0 && (ky>=0 || kz!=0))) {
00875                                         argx = 0.5f*std::sqrt(argy + float(ix*ix)*0.25f*dx2);
00876                                         int r = Util::round(inc*2*argx);
00877                                         if(r <= inc) {
00878                                                 ii = ix + (iy  + iz * ny)* lsd2;
00879                                                 ret[r] += d1[ii] * double(d2[ii]) + d1[ii + 1] * double(d2[ii + 1]);
00880                                                 n1[r]  += d1[ii] * double(d1[ii]) + d1[ii + 1] * double(d1[ii + 1]);
00881                                                 n2[r]  += d2[ii] * double(d2[ii]) + d2[ii + 1] * double(d2[ii + 1]);
00882                                                 lr[r]  += 2;
00883                                         }
00884                                 }
00885                         }
00886                 }
00887         }
00888 
00889         int  linc = 0;
00890         for (int i = 0; i <= inc; i++) if(lr[i]>0) linc++;
00891 
00892         vector < float >result(linc*3);
00893 
00894         ii = -1;
00895         for (int i = 0; i <= inc; i++) {
00896                 if(lr[i]>0) {
00897                         ii++;
00898                         result[ii]        = float(i)/float(2*inc);
00899                         result[ii+linc]   = float(ret[i] / (std::sqrt(n1[i] * n2[i])));
00900                         result[ii+2*linc] = lr[i]  /*1.0f/sqrt(float(lr[i]))*/;
00901                 }
00902                 /*else {
00903                         result[i]           = 0.0f;
00904                         result[i+inc+1]     = 0.0f;
00905                         result[i+2*(inc+1)] = 0.0f;}*/
00906         }
00907 
00908         if( ret ) {
00909                 delete[]ret;
00910                 ret = 0;
00911         }
00912 
00913         if( n1 ) {
00914                 delete[]n1;
00915                 n1 = 0;
00916         }
00917         if( n2 ) {
00918                 delete[]n2;
00919                 n2 = 0;
00920         }
00921 
00922         if (needfree&1) {
00923                 if( fpimage ) {
00924                         delete fpimage;
00925                         fpimage = 0;
00926                 }
00927         }
00928         if (needfree&2) {
00929                 if( gpimage ) {
00930                         delete gpimage;
00931                         gpimage = 0;
00932                 }
00933         }
00934 
00935         EXITFUNC;
00936         return result;
00937 }

vector< Pixel > EMData::calc_highest_locations ( float  threshold  ) 

Calculate and return a sorted list of pixels whose values are above a specified threshold.

The pixels are sorted from high to low.

Parameters:
threshold The specified pixel value. Returned pixels should have higher values than it.
Returns:
A sorted list of pixels with their values, and locations. Their values are higher than threshold.

Definition at line 516 of file emdata_metadata.cpp.

References data, ENTERFUNC, EXITFUNC, get_data(), is_complex(), is_ri(), nx, nxy, ny, nz, and v.

00517 {
00518         ENTERFUNC;
00519 
00520         vector<Pixel> result;
00521 
00522         int di = 1;
00523         if (is_complex() && !is_ri()) {
00524                 di = 2;
00525         }
00526 
00527         int nxy = nx * ny;
00528         float * data = get_data();
00529 
00530         for (int j = 0; j < nz; ++j) {
00531                 size_t cur_z = j * nxy;
00532 
00533                 for (int k = 0; k < ny; ++k) {
00534                         size_t cur_y = k * nx + cur_z;
00535 
00536                         for (int l = 0; l < nx; l += di) {
00537                                 float v =data[l + cur_y];
00538                                 if (v > threshold) {
00539                                         result.push_back(Pixel(l, k, j, v));
00540                                 }
00541                         }
00542                 }
00543         }
00544 
00545         std::sort(result.begin(), result.end());
00546 
00547         EXITFUNC;
00548         return result;
00549 }

vector< float > EMData::calc_hist ( int  hist_size = 128,
float  hist_min = 0,
float  hist_max = 0,
const float &  brt = 0.0f,
const float &  cont = 1.0f 
)

Calculates the histogram of 'this' image.

The result is stored in float array 'hist'. If hist_min = hist_max, use image data min as hist_min; use image data max as hist_max.

Parameters:
hist_size Histogram array's size.
hist_min Minimum histogram value.
hist_max Maximum histogram value.
brt 
cont 
Returns:
histogram array of this image.

Definition at line 2073 of file emdata.cpp.

References data, ENTERFUNC, EXITFUNC, get_attr(), get_data(), is_complex(), nx, ny, nz, and EMAN::Util::round().

02074 {
02075         ENTERFUNC;
02076 
02077         static size_t prime[] = { 1, 3, 7, 11, 17, 23, 37, 59, 127, 253, 511 };
02078 
02079         if (histmin == histmax) {
02080                 histmin = get_attr("minimum");
02081                 histmax = get_attr("maximum");
02082         }
02083 
02084         vector <float> hist(hist_size, 0.0);
02085 
02086         int p0 = 0;
02087         int p1 = 0;
02088         size_t size = nx * ny * nz;
02089         if (size < 300000) {
02090                 p0 = 0;
02091                 p1 = 0;
02092         }
02093         else if (size < 2000000) {
02094                 p0 = 2;
02095                 p1 = 3;
02096         }
02097         else if (size < 8000000) {
02098                 p0 = 4;
02099                 p1 = 6;
02100         }
02101         else {
02102                 p0 = 7;
02103                 p1 = 9;
02104         }
02105 
02106         if (is_complex() && p0 > 0) {
02107                 p0++;
02108                 p1++;
02109         }
02110 
02111         size_t di = 0;
02112 //      float norm = 0;
02113         size_t n = hist.size();
02114 
02115         float * data = get_data();
02116         for (int k = p0; k <= p1; ++k) {
02117                 if (is_complex()) {
02118                         di = prime[k] * 2;
02119                 }
02120                 else {
02121                         di = prime[k];
02122                 }
02123 
02124 //              norm += (float)size / (float) di;
02125                 float w = (float)n / (histmax - histmin);
02126 
02127                 for(size_t i=0; i<=size-di; i += di) {
02128                         float val;
02129                         if (cont != 1.0f || brt != 0)val = cont*(data[i]+brt);
02130                         else val = data[i];
02131                         int j = Util::round((val - histmin) * w);
02132                         if (j >= 0 && j < (int) n) {
02133                                 hist[j] += 1;
02134                         }
02135                 }
02136         }
02137 /*
02138         for (size_t i = 0; i < hist.size(); ++i) {
02139                 if (norm != 0) {
02140                         hist[i] = hist[i] / norm;
02141                 }
02142         }
02143 */
02144         return hist;
02145 
02146         EXITFUNC;
02147 }

int EMData::calc_max_index (  )  const

Calculates the index of maximum-value pixel when assuming all pixels are in a 1D array.

Returns:
Index of the maximum-value pixel.

Definition at line 508 of file emdata_metadata.cpp.

References calc_max_location(), nx, and ny.

Referenced by EMAN::RTFExhaustiveAligner::align().

00509 {
00510         IntPoint max_location = calc_max_location();
00511         int i = max_location[0] + max_location[1] * nx + max_location[2] * nx * ny;
00512         return i;
00513 }

IntPoint EMData::calc_max_location (  )  const

Calculates the coordinates of the maximum-value pixel.

Returns:
The coordinates of the maximum-value pixel.

Definition at line 399 of file emdata_metadata.cpp.

References data, ENTERFUNC, EXITFUNC, get_data(), is_complex(), is_ri(), max, nx, nxy, ny, nz, and t.

Referenced by calc_max_index().

00400 {
00401         ENTERFUNC;
00402 
00403         int di = 1;
00404         if (is_complex() && !is_ri()) {
00405                 di = 2;
00406         }
00407 
00408         float max = -FLT_MAX;
00409         int max_x = 0;
00410         int max_y = 0;
00411         int max_z = 0;
00412         int nxy = nx * ny;
00413         float * data = get_data();
00414 
00415         for (int j = 0; j < nz; ++j) {
00416                 size_t cur_z = j * nxy;
00417 
00418                 for (int k = 0; k < ny; ++k) {
00419                         size_t cur_y = k * nx + cur_z;
00420 
00421                         for (int l = 0; l < nx; l += di) {
00422                                 float t = data[l + cur_y];
00423                                 if (t > max) {
00424                                         max_x = l;
00425                                         max_y = k;
00426                                         max_z = j;
00427                                         max = t;
00428                                 }
00429                         }
00430                 }
00431         }
00432 
00433         EXITFUNC;
00434         return IntPoint(max_x, max_y, max_z);
00435 }

IntPoint EMData::calc_max_location_wrap ( const int  maxshiftx = -1,
const int  maxshifty = -1,
const int  maxshiftz = -1 
)

Calculates the wrapped coordinates of the maximum value This function is useful in the context of Fourier correlation you can call this function to find the correct translational shift when using calc_ccf etc.

Returns:
the wrapped coordinates of the maximum
Author:
David Woolford
Date:
Fri Jun 6th 2008

Definition at line 438 of file emdata_metadata.cpp.

References get_value_at_wrap(), get_xsize(), get_ysize(), and get_zsize().

Referenced by EMAN::TranslationalAligner::align(), EMAN::RT3DSphereAligner::xform_align_nbest(), and EMAN::RT3DGridAligner::xform_align_nbest().

00439 {
00440         int maxshiftx = maxdx, maxshifty = maxdy, maxshiftz = maxdz;
00441         if (maxdx == -1) maxshiftx = get_xsize()/4;
00442         if (maxdy == -1) maxshifty = get_ysize()/4;
00443         if (maxdz == -1) maxshiftz = get_zsize()/4;
00444 
00445         float max_value = -FLT_MAX;
00446 
00447         IntPoint peak(0,0,0);
00448         for (int k = -maxshiftz; k <= maxshiftz; k++) {
00449                 for (int j = -maxshifty; j <= maxshifty; j++) {
00450                         for (int i = -maxshiftx; i <= maxshiftx; i++) {
00451 
00452                                 float value = get_value_at_wrap(i,j,k);
00453 
00454                                 if (value > max_value) {
00455                                         max_value = value;
00456                                         peak[0] = i;
00457                                         peak[1] = j;
00458                                         peak[2] = k;
00459                                 }
00460                         }
00461                 }
00462         }
00463 
00464         return peak;
00465 }

int EMData::calc_min_index (  )  const

Calculates the index of minimum-value pixel when assuming all pixels are in a 1D array.

Returns:
Index of the minimum-value pixel.

Definition at line 500 of file emdata_metadata.cpp.

References calc_min_location(), nx, and ny.

00501 {
00502         IntPoint min_location = calc_min_location();
00503         int i = min_location[0] + min_location[1] * nx + min_location[2] * nx * ny;
00504         return i;
00505 }

IntPoint EMData::calc_min_location (  )  const

Calculates the coordinates of the minimum-value pixel.

Returns:
The coordinates of the minimum-value pixel.

Definition at line 361 of file emdata_metadata.cpp.

References data, ENTERFUNC, get_data(), is_complex(), is_ri(), min, nx, nxy, ny, nz, and t.

Referenced by calc_min_index().

00362 {
00363         ENTERFUNC;
00364 
00365         int di = 1;
00366         if (is_complex() && !is_ri()) {
00367                 di = 2;
00368         }
00369 
00370         float min = FLT_MAX;
00371         int min_x = 0;
00372         int min_y = 0;
00373         int min_z = 0;
00374         int nxy = nx * ny;
00375         float * data = get_data();
00376 
00377         for (int j = 0; j < nz; ++j) {
00378                 size_t cur_z = j * nxy;
00379 
00380                 for (int k = 0; k < ny; ++k) {
00381                         size_t cur_y = k * nx + cur_z;
00382 
00383                         for (int l = 0; l < nx; l += di) {
00384                                 float t = data[l + cur_y];
00385                                 if (t < min) {
00386                                         min_x = l;
00387                                         min_y = k;
00388                                         min_z = j;
00389                                         min = t;
00390                                 }
00391                         }
00392                 }
00393         }
00394 
00395         return IntPoint(min_x, min_y, min_z);
00396 }

EMData * EMData::calc_mutual_correlation ( EMData with,
bool  tocorner = false,
EMData filter = 0 
)

Calculates mutual correlation function (MCF) between 2 images.

If 'with' is NULL, this does mirror ACF.

Parameters:
with The image used to calculate MCF.
tocorner Set whether to translate the result image to the corner.
filter The filter image used in calculating MCF.
Exceptions:
ImageFormatException If 'with' is not NULL and it doesn't have the same size to 'this' image.
NullPointerException If FFT returns NULL image.
Returns:
Mutual correlation function image.

Definition at line 1968 of file emdata.cpp.

References ap2ri(), copy(), do_fft(), do_ift(), ENTERFUNC, EXITFUNC, get_data(), get_xsize(), get_ysize(), get_zsize(), ImageFormatException, EMAN::EMUtil::is_same_size(), LOGERR, mult(), mult_complex_efficient(), NullPointerException, process_inplace(), set_attr(), set_path(), sqrt(), EMAN::Util::square(), t, and update().

Referenced by make_rotational_footprint_cmc(), and make_rotational_footprint_e1().

01969 {
01970         ENTERFUNC;
01971 
01972         if (with && !EMUtil::is_same_size(this, with)) {
01973                 LOGERR("images not same size");
01974                 throw ImageFormatException( "images not same size");
01975         }
01976 
01977         EMData *this_fft = 0;
01978         this_fft = do_fft();
01979 
01980         if (!this_fft) {
01981 
01982                 LOGERR("FFT returns NULL image");
01983                 throw NullPointerException("FFT returns NULL image");
01984         }
01985 
01986         this_fft->ap2ri();
01987         EMData *cf = 0;
01988 
01989         if (with && with != this) {
01990                 cf = with->do_fft();
01991                 if (!cf) {
01992                         LOGERR("FFT returns NULL image");
01993                         throw NullPointerException("FFT returns NULL image");
01994                 }
01995                 cf->ap2ri();
01996         }
01997         else {
01998                 cf = this_fft->copy();
01999         }
02000 
02001         if (filter) {
02002                 if (!EMUtil::is_same_size(filter, cf)) {
02003                         LOGERR("improperly sized filter");
02004                         throw ImageFormatException("improperly sized filter");
02005                 }
02006 
02007                 cf->mult_complex_efficient(*filter,true);
02008                 this_fft->mult(*filter,true);
02009                 /*cf->mult_complex_efficient(*filter,5);
02010                 this_fft->mult_complex_efficient(*filter,5);*/
02011         }
02012 
02013         float *rdata1 = this_fft->get_data();
02014         float *rdata2 = cf->get_data();
02015         size_t this_fft_size = this_fft->get_xsize() * this_fft->get_ysize() * this_fft->get_zsize();
02016 
02017         if (with == this) {
02018                 for (size_t i = 0; i < this_fft_size; i += 2) {
02019                         rdata2[i] = std::sqrt(rdata1[i] * rdata2[i] + rdata1[i + 1] * rdata2[i + 1]);
02020                         rdata2[i + 1] = 0;
02021                 }
02022 
02023                 this_fft->update();
02024                 cf->update();
02025         }
02026         else {
02027                 for (size_t i = 0; i < this_fft_size; i += 2) {
02028                         rdata2[i] = (rdata1[i] * rdata2[i] + rdata1[i + 1] * rdata2[i + 1]);
02029                         rdata2[i + 1] = (rdata1[i + 1] * rdata2[i] - rdata1[i] * rdata2[i + 1]);
02030                 }
02031 
02032                 this_fft->update();
02033                 cf->update();
02034                 rdata1 = cf->get_data();
02035 
02036                 for (size_t i = 0; i < this_fft_size; i += 2) {
02037                         float t = Util::square(rdata1[i]) + Util::square(rdata1[i + 1]);
02038                         if (t != 0) {
02039                                 t = pow(t, (float) 0.25);
02040                                 rdata1[i] /= t;
02041                                 rdata1[i + 1] /= t;
02042                         }
02043                 }
02044                 cf->update();
02045         }
02046 
02047         EMData *f2 = cf->do_ift();
02048 
02049         if (tocenter) {
02050                 f2->process_inplace("xform.phaseorigin.tocenter");
02051         }
02052 
02053         if( cf )
02054         {
02055                 delete cf;
02056                 cf = 0;
02057         }
02058 
02059         if( this_fft )
02060         {
02061                 delete this_fft;
02062                 this_fft = 0;
02063         }
02064 
02065         f2->set_attr("label", "MCF");
02066         f2->set_path("/tmp/eman.mcf");
02067 
02068         EXITFUNC;
02069         return f2;
02070 }

vector< Pixel > EMData::calc_n_highest_locations ( int  n  ) 

Calculate and return a sorted list of N highest pixels in the map.

Parameters:
n The number of highest value pixels should be returned.
Returns:
A sorted list of N pixels with their values, and locations.

Definition at line 551 of file emdata_metadata.cpp.

References data, ENTERFUNC, EXITFUNC, get_data(), is_complex(), is_ri(), nx, nxy, ny, nz, and v.

Referenced by EMAN::AutoMask3D2Processor::process_inplace(), and EMAN::AutoMask2DProcessor::process_inplace().

00552 {
00553         ENTERFUNC;
00554 
00555         vector<Pixel> result;
00556 
00557         int di = 1;
00558         if (is_complex() && !is_ri()) {
00559                 di = 2;
00560         }
00561 
00562         // initialize with n elements
00563         float * data = get_data();
00564         for ( int i=0; i<n; i++) result.push_back(Pixel(0,0,0,data[0]));
00565 
00566         int nxy = nx * ny;
00567 
00568         for (int j = 0; j < nz; ++j) {
00569                 size_t cur_z = j * nxy;
00570 
00571                 for (int k = 0; k < ny; ++k) {
00572                         size_t cur_y = k * nx + cur_z;
00573 
00574                         for (int l = 0; l < nx; l += di) {
00575                                 float v =data[l + cur_y];
00576                                 if (v<result[n-1].value) continue;
00577                                 for (vector<Pixel>::iterator i=result.begin(); i<result.end(); i++) {
00578                                         if (v>(*i).value) { result.insert(i,Pixel(l, k, j, v)); result.pop_back(); break; }
00579                                 }
00580                         }
00581                 }
00582         }
00583 
00584         EXITFUNC;
00585         return result;
00586 }

vector< float > EMData::calc_radial_dist ( int  n,
float  x0,
float  dx,
int  nwedge,
bool  inten 
)

calculates radial distribution subdivided by angle.

works for real and imaginary images. 2-D only. The first returns a single vector of n*nwedge points, with radius varying first. That is, the first n points represent the radial profile in the first wedge.

Parameters:
n number of points.
x0 starting x coordinate.
dx step of x.
nwedge int number of wedges to divide the circle into
inten returns intensity (amp^2) rather than amplitude if set
Exceptions:
ImageDimensionException If 'this' image is not 2D.
Returns:
nwedge radial distributions packed into a single vector<float>

Definition at line 2590 of file emdata.cpp.

References data, ENTERFUNC, EXITFUNC, get_data(), ImageDimensionException, is_complex(), is_ri(), LOGERR, norm(), nx, ny, nz, v, x, and y.

02591 {
02592         ENTERFUNC;
02593 
02594         if (nz > 1) {
02595                 LOGERR("2D images only.");
02596                 throw ImageDimensionException("2D images only");
02597         }
02598 
02599         vector<float>ret(n*nwedge);
02600         vector<float>norm(n*nwedge);
02601 
02602         int x,y,i;
02603         int step=is_complex()?2:1;
02604         float astep=static_cast<float>(M_PI*2.0/nwedge);
02605         float* data = get_data();
02606         for (i=0; i<n*nwedge; i++) ret[i]=norm[i]=0.0;
02607 
02608         // We do 2D separately to avoid the hypot3 call
02609         for (y=i=0; y<ny; y++) {
02610                 for (x=0; x<nx; x+=step,i+=step) {
02611                         float r,v,a;
02612                         if (is_complex()) {
02613 #ifdef  _WIN32
02614                                 r=static_cast<float>(_hypot(x/2.0,y<ny/2?y:ny-y));              // origin at 0,0; periodic
02615 #else
02616                                 r=static_cast<float>(hypot(x/2.0,y<ny/2?y:ny-y));               // origin at 0,0; periodic
02617 #endif
02618                                 a=atan2(float(y<ny/2?y:ny-y),x/2.0f);
02619                                 if (!inten) {
02620 #ifdef  _WIN32
02621                                         if (is_ri()) v=static_cast<float>(_hypot(data[i],data[i+1]));   // real/imag, compute amplitude
02622 #else
02623                                         if (is_ri()) v=static_cast<float>(hypot(data[i],data[i+1]));    // real/imag, compute amplitude
02624 #endif  //_WIN32
02625                                         else v=data[i];                                                 // amp/phase, just get amp
02626                                 } else {
02627                                         if (is_ri()) v=data[i]*data[i]+data[i+1]*data[i+1];
02628                                         else v=data[i]*data[i];
02629                                 }
02630                         }
02631                         else {
02632 #ifdef  _WIN32
02633                                 r=static_cast<float>(_hypot(x-nx/2,y-ny/2));
02634 #else
02635                                 r=static_cast<float>(hypot(x-nx/2,y-ny/2));
02636 #endif  //_WIN32
02637                                 a=atan2(float(y-ny/2),float(x-nx/2));
02638                                 if (inten) v=data[i]*data[i];
02639                                 else v=data[i];
02640                         }
02641                         int bin=n*int((a+M_PI)/astep);
02642                         if (bin>=nwedge) bin=nwedge-1;
02643                         r=(r-x0)/dx;
02644                         int f=int(r);   // safe truncation, so floor isn't needed
02645                         r-=float(f);    // r is now the fractional spacing between bins
02646                         if (f>=0 && f<n) {
02647                                 ret[f+bin]+=v*(1.0f-r);
02648                                 norm[f+bin]+=(1.0f-r);
02649                                 if (f<n-1) {
02650                                         ret[f+1+bin]+=v*r;
02651                                         norm[f+1+bin]+=r;
02652                                 }
02653                         }
02654                 }
02655         }
02656 
02657         for (i=0; i<n*nwedge; i++) ret[i]/=norm[i]?norm[i]:1.0f;        // Normalize
02658         EXITFUNC;
02659 
02660         return ret;
02661 }

vector< float > EMData::calc_radial_dist ( int  n,
float  x0,
float  dx,
bool  inten 
)

calculates radial distribution.

works for real and imaginary images. Returns mean radial amplitude, or intensity if inten is set. Note that the complex origin is at (0,0), with periodic boundaries. Note that the inten option is NOT equivalent to returning amplitude and squaring the result.

Parameters:
n number of points.
x0 starting point x coordinate.
dx step of x.
inten returns intensity (amp^2) rather than amplitude if set
Returns:
The radial distribution in an array.

Definition at line 2482 of file emdata.cpp.

References data, ENTERFUNC, EXITFUNC, get_attr_default(), get_data(), EMAN::Util::hypot3(), EMAN::Util::hypot_fast(), InvalidParameterException, is_complex(), is_ri(), norm(), nx, ny, nz, v, x, and y.

Referenced by EMAN::FRCCmp::cmp(), EMAN::OptVarianceCmp::cmp(), EMAN::MatchSFProcessor::create_radial_func(), main(), EMAN::CTFSNRWeightProcessor::process_inplace(), EMAN::RotationalSubstractProcessor::process_inplace(), EMAN::RotationalAverageProcessor::process_inplace(), and EMAN::FourierAnlProcessor::process_inplace().

02483 {
02484         ENTERFUNC;
02485 
02486         vector<float>ret(n);
02487         vector<float>norm(n);
02488 
02489         int x,y,z,i;
02490         int step=is_complex()?2:1;
02491         int isinten=get_attr_default("is_intensity",0);
02492 
02493         if (isinten&&!inten) { throw InvalidParameterException("Must set inten for calc_radial_dist with intensity image"); }
02494 
02495         for (i=0; i<n; i++) ret[i]=norm[i]=0.0;
02496         float * data = get_data();
02497 
02498         // We do 2D separately to avoid the hypot3 call
02499         if (nz==1) {
02500                 for (y=i=0; y<ny; y++) {
02501                         for (x=0; x<nx; x+=step,i+=step) {
02502                                 float r,v;
02503                                 if (step==2) {          //complex
02504                                         if (x==0 && y>ny/2) continue;
02505                                         r=(float)(Util::hypot_fast(x/2,y<ny/2?y:ny-y));         // origin at 0,0; periodic
02506                                         if (!inten) {
02507 #ifdef  _WIN32
02508                                                 if (is_ri()) v=static_cast<float>(_hypot(data[i],data[i+1]));   // real/imag, compute amplitude
02509 #else
02510                                                 if (is_ri()) v=static_cast<float>(hypot(data[i],data[i+1]));    // real/imag, compute amplitude
02511 #endif
02512                                                 else v=data[i];                                                 // amp/phase, just get amp
02513                                         } else {
02514                                                 if (isinten) v=data[i];
02515                                                 else if (is_ri()) v=data[i]*data[i]+data[i+1]*data[i+1];
02516                                                 else v=data[i]*data[i];
02517                                         }
02518                                 }
02519                                 else {
02520                                         r=(float)(Util::hypot_fast(x-nx/2,y-ny/2));
02521                                         if (inten) v=data[i]*data[i];
02522                                         else v=data[i];
02523                                 }
02524                                 r=(r-x0)/dx;
02525                                 int f=int(r);   // safe truncation, so floor isn't needed
02526                                 r-=float(f);    // r is now the fractional spacing between bins
02527 //                              printf("%d\t%d\t%d\t%1.3f\t%d\t%1.3f\t%1.4g\n",x,y,f,r,step,Util::hypot_fast(x/2,y<ny/2?y:ny-y),v);
02528                                 if (f>=0 && f<n) {
02529                                         ret[f]+=v*(1.0f-r);
02530                                         norm[f]+=(1.0f-r);
02531                                         if (f<n-1) {
02532                                                 ret[f+1]+=v*r;
02533                                                 norm[f+1]+=r;
02534                                         }
02535                                 }
02536                         }
02537                 }
02538         }
02539         else {
02540                 size_t i;       //3D file may have >2G size
02541                 for (z=i=0; z<nz; ++z) {
02542                         for (y=0; y<ny; ++y) {
02543                                 for (x=0; x<nx; x+=step,i+=step) {
02544                                         float r,v;
02545                                         if (step==2) {  //complex
02546                                                 if (x==0 && z<nz/2) continue;
02547                                                 if (x==0 && z==nz/2 && y<ny/2) continue;
02548                                                 r=Util::hypot3(x/2,y<ny/2?y:ny-y,z<nz/2?z:nz-z);        // origin at 0,0; periodic
02549                                                 if (!inten) {
02550 #ifdef  _WIN32
02551                                                         if (is_ri()) v=static_cast<float>(_hypot(data[i],data[i+1]));   // real/imag, compute amplitude
02552 #else
02553                                                         if (is_ri()) v=static_cast<float>(hypot(data[i],data[i+1]));    // real/imag, compute amplitude
02554 #endif  //_WIN32
02555                                                         else v=data[i];                                                 // amp/phase, just get amp
02556                                                 } else {
02557                                                         if (isinten) v=data[i];
02558                                                         else if (is_ri()) v=data[i]*data[i]+data[i+1]*data[i+1];
02559                                                         else v=data[i]*data[i];
02560                                                 }
02561                                         }
02562                                         else {
02563                                                 r=Util::hypot3(x-nx/2,y-ny/2,z-nz/2);
02564                                                 if (inten) v=data[i]*data[i];
02565                                                 else v=data[i];
02566                                         }
02567                                         r=(r-x0)/dx;
02568                                         int f=int(r);   // safe truncation, so floor isn't needed
02569                                         r-=float(f);    // r is now the fractional spacing between bins
02570                                         if (f>=0 && f<n) {
02571                                                 ret[f]+=v*(1.0f-r);
02572                                                 norm[f]+=(1.0f-r);
02573                                                 if (f<n-1) {
02574                                                         ret[f+1]+=v*r;
02575                                                         norm[f+1]+=r;
02576                                                 }
02577                                         }
02578                                 }
02579                         }
02580                 }
02581         }
02582 
02583         for (i=0; i<n; i++) ret[i]/=norm[i]?norm[i]:1.0f;       // Normalize
02584 
02585         EXITFUNC;
02586 
02587         return ret;
02588 }

float EMData::calc_sigma_diff (  ) 

Calculates sigma above and below the mean and returns the difference between them.

Returns:
The difference between sigma above and below the mean.

Definition at line 324 of file emdata_metadata.cpp.

References ENTERFUNC, EXITFUNC, get_attr(), get_data(), nx, ny, nz, sqrt(), square, and EMAN::Util::square().

00325 {
00326         ENTERFUNC;
00327 
00328         float *d = get_data();
00329         float mean = get_attr("mean");
00330         float sigma = get_attr("sigma");
00331 
00332         double sum_up = 0;
00333         double sum_down = 0;
00334         int nup = 0;
00335         int ndown = 0;
00336 
00337         size_t size = nx * ny * nz;
00338 
00339         for (size_t i = 0; i < size; i++) {
00340                 if (d[i] > mean) {
00341                         sum_up += Util::square(d[i] - mean);
00342                         nup++;
00343                 }
00344                 else {
00345                         sum_down += Util::square(mean - d[i]);
00346                         ndown++;
00347                 }
00348         }
00349 
00350         float sigup = std::sqrt((float)sum_up / nup);
00351         float sigdown = std::sqrt((float)sum_down / ndown);
00352         float sig_diff = fabs(sigup - sigdown) / sigma;
00353 
00354 
00355         EXITFUNC;
00356         return sig_diff;
00357 
00358 }

void EMData::cconj (  ) 

Replace the image its complex conjugate.

Exceptions:
ImageFormatException Image must be complex (and RI)

Definition at line 2663 of file emdata.cpp.

References cmplx(), ENTERFUNC, EXITFUNC, ImageFormatException, is_complex(), is_fftodd(), is_ri(), nx, ny, and nz.

02663                    {
02664         ENTERFUNC;
02665         if (!is_complex() || !is_ri())
02666                 throw ImageFormatException("EMData::conj requires a complex, ri image");
02667         int nxreal = nx -2 + int(is_fftodd());
02668         int nxhalf = nxreal/2;
02669         for (int iz = 0; iz < nz; iz++)
02670                 for (int iy = 0; iy < ny; iy++)
02671                         for (int ix = 0; ix <= nxhalf; ix++)
02672                                 cmplx(ix,iy,iz) = conj(cmplx(ix,iy,iz));
02673         EXITFUNC;
02674 }

void EMData::center_origin (  ) 

Definition at line 5294 of file emdata_sparx.cpp.

References ENTERFUNC, EXITFUNC, ImageFormatException, is_complex(), LOGERR, nx, ny, nz, and update().

05295 {
05296         ENTERFUNC;
05297         if (is_complex()) {
05298                 LOGERR("Real image expected. Input image is complex.");
05299                 throw ImageFormatException("Real image expected. Input image is complex.");
05300         }
05301         for (int iz = 0; iz < nz; iz++) {
05302                 for (int iy = 0; iy < ny; iy++) {
05303                         for (int ix = 0; ix < nx; ix++) {
05304                                 // next line multiplies by +/- 1
05305                                 (*this)(ix,iy,iz) *= -2*((ix+iy+iz)%2) + 1;
05306                         }
05307                 }
05308         }
05309         update();
05310         EXITFUNC;
05311 }

void EMData::center_origin_fft (  ) 

Multiply a Fourier image by (-1)**(ix+iy+iz) to center it.

Definition at line 5331 of file emdata_sparx.cpp.

References cmplx(), ENTERFUNC, EXITFUNC, get_array_offsets(), ImageFormatException, is_complex(), is_fftodd(), is_ri(), LOGERR, LOGWARN, nx, ny, nz, set_array_offsets(), and update().

Referenced by EMAN::padfft_slice(), and EMAN::FourierGriddingProjector::project3d().

05332 {
05333         ENTERFUNC;
05334         if (!is_complex()) {
05335                 LOGERR("complex image expected. Input image is real image.");
05336                 throw ImageFormatException("complex image expected. Input image is real image.");
05337         }
05338 
05339         if (!is_ri()) {
05340                 LOGWARN("Only RI should be used. ");
05341         }
05342         vector<int> saved_offsets = get_array_offsets();
05343         // iz in [1,nz], iy in [1,ny], ix in [0,nx/2], but nx comes in as extended and is the same for odd
05344         //                                                 and even, so we can ignore the difference...
05345         //                         in short, as nx is extended, it should be  ix in [0,(nx-2)/2],  corrected PAP 05/20
05346         set_array_offsets(0,1,1);
05347         int nxc = nx/2;
05348 
05349         if (is_fftodd()) {
05350                 for (int iz = 1; iz <= nz; iz++) {
05351                         for (int iy = 1; iy <= ny; iy++) {
05352                                 for (int ix = 0; ix < nxc; ix++) {
05353                                         cmplx(ix,iy,iz) *= float(-2*((ix+iy+iz)%2) + 1);
05354                                         float temp = float(iz-1+iy-1+ix)/float(ny)*M_PI;
05355                                         complex<float> temp2 = complex<float>(cos(temp), -sin(temp));
05356                                         cmplx(ix,iy,iz) *= temp2;
05357                                 }
05358                         }
05359                 }
05360         } else {
05361                 for (int iz = 1; iz <= nz; iz++) {
05362                         for (int iy = 1; iy <= ny; iy++) {
05363                                 for (int ix = 0; ix < nxc; ix++) {
05364                                         // next line multiplies by +/- 1
05365                                         cmplx(ix,iy,iz) *= float(-2*((ix+iy+iz)%2) + 1);
05366                                 }
05367                         }
05368                 }
05369         }
05370         set_array_offsets(saved_offsets);
05371         update();
05372         EXITFUNC;
05373 }

void EMData::center_origin_yz (  ) 

Definition at line 5313 of file emdata_sparx.cpp.

References ENTERFUNC, EXITFUNC, ImageFormatException, is_complex(), LOGERR, nx, ny, nz, and update().

05314 {
05315         ENTERFUNC;
05316         if (is_complex()) {
05317                 LOGERR("Real image expected. Input image is complex.");
05318                 throw ImageFormatException("Real image expected. Input image is complex.");
05319         }
05320         for (int iz = 0; iz < nz; iz++) {
05321                 for (int iy = (iz+1)%2; iy < ny; iy+=2) {
05322                         for (int ix = 0; ix < nx; ix++) {
05323                                 (*this)(ix,iy,iz) *= -1;
05324                         }
05325                 }
05326         }
05327         update();
05328         EXITFUNC;
05329 }

void EMData::clip_inplace ( const Region area,
const float &  fill_value = 0 
)

Clip the image inplace - clipping region must be smaller than the current region internally memory is reallocated

Exceptions:
ImageDimensionException if any of the dimensions of the argument region are negative.

Parameters:
area The clip area, can be 2D/3D.
fill_value the value that new region

Definition at line 303 of file emdata.cpp.

References Assert, EMAN::EMUtil::em_memcpy(), EMAN::EMUtil::em_memset(), ENTERFUNC, get_data(), ImageDimensionException, nx, ny, nz, EMAN::Region::origin, EMAN::EMData::ClipInplaceVariables::prv_x_left, EMAN::EMData::ClipInplaceVariables::prv_z_bottom, rdata, set_size(), EMAN::Region::size, and EMAN::EMData::ClipInplaceVariables::x_iter.

Referenced by calc_ccf(), calc_fast_sigma_image(), calc_flcf(), EMAN::FFTResampleProcessor::fft_resample(), EMAN::ScaleTransformProcessor::process(), EMAN::ZGradientProcessor::process_inplace(), EMAN::YGradientProcessor::process_inplace(), EMAN::XGradientProcessor::process_inplace(), EMAN::ScaleTransformProcessor::process_inplace(), EMAN::IntTranslateProcessor::process_inplace(), and EMAN::FlattenBackgroundProcessor::process_inplace().

00304 {
00305         // Added by d.woolford
00306         ENTERFUNC;
00307 
00308         // Store the current dimension values
00309         int prev_nx = nx, prev_ny = ny, prev_nz = nz;
00310         int prev_size = nx*ny*nz;
00311 
00312         // Get the zsize, ysize and xsize of the final area, these are the new dimension sizes of the pixel data
00313         int new_nz = ( area.size[2]==0 ? 1 : (int)area.size[2]);
00314         int new_ny = ( area.size[1]==0 ? 1 : (int)area.size[1]);
00315         int new_nx = (int)area.size[0];
00316 
00317         if ( new_nz < 0 || new_ny < 0 || new_nx < 0 )
00318         {
00319                 // Negative image dimensions were never tested nor considered when creating this implementation
00320                 throw ImageDimensionException("New image dimensions are negative - this is not supported in the clip_inplace operation");
00321         }
00322 
00323         int new_size = new_nz*new_ny*new_nx;
00324 
00325         // Get the translation values, they are used to construct the ClipInplaceVariables object
00326         int x0 = (int) area.origin[0];
00327         int y0 = (int) area.origin[1];
00328         int z0 = (int) area.origin[2];
00329 
00330         // Get a object that calculates all the interesting variables associated with the clip inplace operation
00331         ClipInplaceVariables civ(prev_nx, prev_ny, prev_nz, new_nx, new_ny, new_nz, x0, y0, z0);
00332 
00333         get_data(); // Do this here to make sure rdata is up to date, applicable if GPU stuff is occuring
00334         // Double check to see if any memory shifting even has to occur
00335         if ( x0 > prev_nx || y0 > prev_ny || z0 > prev_nz || civ.x_iter == 0 || civ.y_iter == 0 || civ.z_iter == 0)
00336         {
00337                 // In this case the volume has been shifted beyond the location of the pixel rdata and
00338                 // the client should expect to see a volume with nothing in it.
00339 
00340                 // Set size calls realloc,
00341                 set_size(new_nx, new_ny, new_nz);
00342 
00343                 // Set pixel memory to zero - the client should expect to see nothing
00344                 EMUtil::em_memset(rdata, 0, new_nx*new_ny*new_nz);
00345 
00346                 return;
00347         }
00348 
00349         // Resize the volume before memory shifting occurs if the new volume is larger than the previous volume
00350         // All of the pixel rdata is guaranteed to be at the start of the new volume because realloc (called in set size)
00351         // guarantees this.
00352         if ( new_size > prev_size )
00353                 set_size(new_nx, new_ny, new_nz);
00354 
00355         // Store the clipped row size.
00356         size_t clipped_row_size = (civ.x_iter) * sizeof(float);
00357 
00358         // Get the new sector sizes to save multiplication later.
00359         int new_sec_size = new_nx * new_ny;
00360         int prev_sec_size = prev_nx * prev_ny;
00361 
00362         // Determine the memory locations of the source and destination pixels - at the point nearest
00363         // to the beginning of the volume (rdata)
00364         int src_it_begin = civ.prv_z_bottom*prev_sec_size + civ.prv_y_front*prev_nx + civ.prv_x_left;
00365         int dst_it_begin = civ.new_z_bottom*new_sec_size + civ.new_y_front*new_nx + civ.new_x_left;
00366 
00367         // This loop is in the forward direction (starting at points nearest to the beginning of the volume)
00368         // it copies memory only when the destination pointer is less the source pointer - therefore
00369         // ensuring that no memory "copied to" is yet to be "copied from"
00370         for (int i = 0; i < civ.z_iter; ++i) {
00371                 for (int j = 0; j < civ.y_iter; ++j) {
00372 
00373                         // Determine the memory increments as dependent on i and j
00374                         // This could be optimized so that not so many multiplications are occurring...
00375                         int dst_inc = dst_it_begin + j*new_nx + i*new_sec_size;
00376                         int src_inc = src_it_begin + j*prev_nx + i*prev_sec_size;
00377                         float* local_dst = rdata + dst_inc;
00378                         float* local_src = rdata + src_inc;
00379 
00380                         if ( dst_inc >= src_inc )
00381                         {
00382                                 // this is fine, it will happen now and then and it will be necessary to continue.
00383                                 // the tempatation is to break, but you can't do that (because the point where memory intersects
00384                                 // could be in this slice - and yes, this aspect could be optimized).
00385                                 continue;
00386                         }
00387 
00388                         // Asserts are compiled only in debug mode
00389                         // This situation not encountered in testing thus far
00390                         Assert( dst_inc < new_size && src_inc < prev_size && dst_inc >= 0 && src_inc >= 0 );
00391 
00392                         // Finally copy the memory
00393                         EMUtil::em_memcpy(local_dst, local_src, clipped_row_size);
00394                 }
00395         }
00396 
00397         // Determine the memory locations of the source and destination pixels - at the point nearest
00398         // to the end of the volume (rdata+new_size)
00399         int src_it_end = prev_size - civ.prv_z_top*prev_sec_size - civ.prv_y_back*prev_nx - prev_nx + civ.prv_x_left;
00400         int dst_it_end = new_size - civ.new_z_top*new_sec_size - civ.new_y_back*new_nx - new_nx + civ.new_x_left;
00401 
00402         // This loop is in the reverse direction (starting at points nearest to the end of the volume).
00403         // It copies memory only when the destination pointer is greater than  the source pointer therefore
00404         // ensuring that no memory "copied to" is yet to be "copied from"
00405         for (int i = 0; i < civ.z_iter; ++i) {
00406                 for (int j = 0; j < civ.y_iter; ++j) {
00407 
00408                         // Determine the memory increments as dependent on i and j
00409                         int dst_inc = dst_it_end - j*new_nx - i*new_sec_size;
00410                         int src_inc = src_it_end - j*prev_nx - i*prev_sec_size;
00411                         float* local_dst = rdata + dst_inc;
00412                         float* local_src = rdata + src_inc;
00413 
00414                         if (dst_inc <= (src_inc + civ.x_iter ))
00415                         {
00416                                 // Overlap
00417                                 if ( dst_inc > src_inc )
00418                                 {
00419                                         // Because the memcpy operation is the forward direction, and this "reverse
00420                                         // direction" loop is proceeding in a backwards direction, it is possible
00421                                         // that memory copied to is yet to be copied from (because memcpy goes forward).
00422                                         // In this scenario pixel memory "copied to" is yet to be "copied from"
00423                                         // i.e. there is overlap
00424 
00425                                         // memmove handles overlapping cases.
00426                                         // memmove could use a temporary buffer, or could go just go backwards
00427                                         // the specification doesn't say how the function behaves...
00428                                         // If memmove creates a temporary buffer is clip_inplace no longer inplace?
00429                                         memmove(local_dst, local_src, clipped_row_size);
00430                                 }
00431                                 continue;
00432                         }
00433 
00434                         // This situation not encountered in testing thus far
00435                         Assert( dst_inc < new_size && src_inc < prev_size && dst_inc >= 0 && src_inc >= 0 );
00436 
00437                         // Perform the memory copy
00438                         EMUtil::em_memcpy(local_dst, local_src, clipped_row_size);
00439                 }
00440         }
00441 
00442         // Resize the volume after memory shifting occurs if the new volume is smaller than the previous volume
00443         // set_size calls realloc, guaranteeing that the pixel rdata is in the right location.
00444         if ( new_size < prev_size )
00445                 set_size(new_nx, new_ny, new_nz);
00446 
00447         // Now set all the edges to zero
00448 
00449         // Set the extra bottom z slices to the fill_value
00450         if (  z0 < 0 )
00451         {
00452                 //EMUtil::em_memset(rdata, 0, (-z0)*new_sec_size*sizeof(float));
00453                 int inc = (-z0)*new_sec_size;
00454                 std::fill(rdata,rdata+inc,fill_value);
00455         }
00456 
00457         // Set the extra top z slices to the fill_value
00458         if (  civ.new_z_top > 0 )
00459         {
00460                 float* begin_pointer = rdata + (new_nz-civ.new_z_top)*new_sec_size;
00461                 //EMUtil::em_memset(begin_pointer, 0, (civ.new_z_top)*new_sec_size*sizeof(float));
00462                 float* end_pointer = begin_pointer+(civ.new_z_top)*new_sec_size;
00463                 std::fill(begin_pointer,end_pointer,fill_value);
00464         }
00465 
00466         // Next deal with x and y edges by iterating through each slice
00467         for ( int i = civ.new_z_bottom; i < civ.new_z_bottom + civ.z_iter; ++i )
00468         {
00469                 // Set the extra front y components to the fill_value
00470                 if ( y0 < 0 )
00471                 {
00472                         float* begin_pointer = rdata + i*new_sec_size;
00473                         //EMUtil::em_memset(begin_pointer, 0, (-y0)*new_nx*sizeof(float));
00474                         float* end_pointer = begin_pointer+(-y0)*new_nx;
00475                         std::fill(begin_pointer,end_pointer,fill_value);
00476                 }
00477 
00478                 // Set the extra back y components to the fill_value
00479                 if ( civ.new_y_back > 0 )
00480                 {
00481                         float* begin_pointer = rdata + i*new_sec_size + (new_ny-civ.new_y_back)*new_nx;
00482                         //EMUtil::em_memset(begin_pointer, 0, (civ.new_y_back)*new_nx*sizeof(float));
00483                         float* end_pointer = begin_pointer+(civ.new_y_back)*new_nx;
00484                         std::fill(begin_pointer,end_pointer,fill_value);
00485                 }
00486 
00487                 // Iterate through the y to set each correct x component to the fill_value
00488                 for (int j = civ.new_y_front; j <civ.new_y_front + civ.y_iter; ++j)
00489                 {
00490                         // Set the extra left x components to the fill_value
00491                         if ( x0 < 0 )
00492                         {
00493                                 float* begin_pointer = rdata + i*new_sec_size + j*new_nx;
00494                                 //EMUtil::em_memset(begin_pointer, 0, (-x0)*sizeof(float));
00495                                 float* end_pointer = begin_pointer+(-x0);
00496                                 std::fill(begin_pointer,end_pointer,fill_value);
00497                         }
00498 
00499                         // Set the extra right x components to the fill_value
00500                         if ( civ.new_x_right > 0 )
00501                         {
00502                                 float* begin_pointer = rdata + i*new_sec_size + j*new_nx + (new_nx - civ.new_x_right);
00503                                 //EMUtil::em_memset(begin_pointer, 0, (civ.new_x_right)*sizeof(float));
00504                                 float* end_pointer = begin_pointer+(civ.new_x_right);
00505                                 std::fill(begin_pointer,end_pointer,fill_value);
00506                         }
00507 
00508                 }
00509         }
00510 
00511 // These couts may be useful
00512 //      cout << "start starts " << civ.prv_x_left << " " << civ.prv_y_front << " " << civ.prv_z_bottom << endl;
00513 //      cout << "start ends " << civ.prv_x_right << " " << civ.prv_y_back << " " << civ.prv_z_top << endl;
00514 //      cout << "dst starts " << civ.new_x_left << " " << civ.new_y_front << " " << civ.new_z_bottom << endl;
00515 //      cout << "dst ends " << civ.new_x_right << " " << civ.new_y_back << " " << civ.new_z_top << endl;
00516 //      cout << "total iter z - " << civ.z_iter << " y - " << civ.y_iter << " x - " << civ.x_iter << endl;
00517 //      cout << "=====" << endl;
00518 //      cout << "dst_end is " << dst_it_end << " src end is " << src_it_end << endl;
00519 //      cout << "dst_begin is " << dst_it_begin << " src begin is " << src_it_begin << endl;
00520 
00521         // Update appropriate attributes (Copied and pasted from get_clip)
00522         if( attr_dict.has_key("origin_x") && attr_dict.has_key("origin_y") &&
00523         attr_dict.has_key("origin_z") )
00524         {
00525                 float xorigin = attr_dict["origin_x"];
00526                 float yorigin = attr_dict["origin_y"];
00527                 float zorigin = attr_dict["origin_z"];
00528 
00529                 float apix_x = attr_dict["apix_x"];
00530                 float apix_y = attr_dict["apix_y"];
00531                 float apix_z = attr_dict["apix_z"];
00532 
00533                 set_xyz_origin(xorigin + apix_x * area.origin[0],
00534                         yorigin + apix_y * area.origin[1],
00535                         zorigin + apix_z * area.origin[2]);
00536         }
00537 
00538         // Set the update flag because the size of the image has changed and stats should probably be recalculated if requested.
00539         update();
00540 
00541         EXITFUNC;
00542 }

float EMData::cm_euc ( EMData sinoj,
int  n1,
int  n2 
)

euclidean distance between two line

Parameters:
sinoj 
n1 
n2 

Definition at line 503 of file emdata_sparx.cpp.

References dist(), get_data(), and get_xsize().

00504 {
00505     int lnlen = get_xsize();
00506     float* line_1 = get_data() + n1 * lnlen;
00507     float* line_2 = sinoj->get_data() + n2 * lnlen;
00508     return dist(lnlen, line_1, line_2);
00509 }

float EMData::cmp ( const string &  cmpname,
EMData with,
const Dict params = Dict() 
)

Compare this image with another image.

Parameters:
cmpname Comparison algorithm name.
with The image you want to compare to.
params Comparison parameters in a keyed dictionary.
Exceptions:
NotExistingObjectError If the comparison algorithm doesn't exist.
Returns:
comparison score. The bigger, the better.

Definition at line 97 of file emdata_modular.cpp.

References EMAN::Cmp::cmp(), ENTERFUNC, and EXITFUNC.

Referenced by EMAN::RTFExhaustiveAligner::align(), EMAN::RotateFlipAligner::align(), EMAN::RotateTranslateFlipAligner::align(), EMAN::RotateTranslateAligner::align(), EMAN::RotationalAligner::align(), EMAN::Util::ccc_images(), EMAN::Util::ccc_images_G(), EMAN::Util::twoD_fine_ali(), EMAN::Util::twoD_fine_ali_G(), EMAN::Util::twoD_to_3D_ali(), EMAN::RT3DSphereAligner::xform_align_nbest(), and EMAN::RT3DGridAligner::xform_align_nbest().

00098 {
00099         ENTERFUNC;
00100         float result = 0;
00101         Cmp *c = Factory < Cmp >::get(cmpname, params);
00102         if (c) {
00103                 result = c->cmp(this, with);
00104                 if( c )
00105                 {
00106                         delete c;
00107                         c = 0;
00108                 }
00109         }
00110 
00111         EXITFUNC;
00112         return result;
00113 }

std::complex<float>& EMAN::EMData::cmplx ( const int  ix  )  [inline]

Definition at line 2308 of file emdata.h.

std::complex<float>& EMAN::EMData::cmplx ( const int  ix,
const int  iy 
) [inline]

Definition at line 2297 of file emdata.h.

std::complex<float>& EMAN::EMData::cmplx ( const int  ix,
const int  iy,
const int  iz 
) [inline]

Return reference to complex elements.

Definition at line 2286 of file emdata.h.

Referenced by EMAN::newfile_store::add_image(), cconj(), center_origin_fft(), EMAN::Processor::EMFourierFilterFunc(), extract_plane(), extractline(), extractpoint(), EMAN::Util::extractpoint2(), filter_by_image(), EMAN::nnSSNR_ctfReconstructor::finish(), EMAN::nnSSNR_Reconstructor::finish(), fouriergridrot2d(), fouriergridrot_shift2d(), EMAN::fourierproduct(), nn_SSNR(), nn_SSNR_ctf(), onelinenn(), onelinenn_ctf(), onelinenn_ctf_applied(), onelinenn_mult(), EMAN::periodogram(), symplane0(), symplane0_ctf(), symplane1(), and symplane2().

vector< float > EMData::cog (  ) 

Calculates the Center of Gravity and the Radius of Gyration of the image.

Returns:
the mass and the radius as vectors.

Definition at line 672 of file emdata_sparx.cpp.

References get_ndim(), nx, ny, nz, rdata, EMAN::Util::round(), sqrt(), and square.

00672                           {
00673 
00674         vector<float> cntog;
00675         int ndim = get_ndim();
00676         int i=1,j=1,k=1;
00677         float val,sum1=0.f,MX=0.f,RG=0.f,MY=0.f,MZ=0.f,r=0.f;
00678 
00679         if (ndim == 1) {
00680                 for ( i = 1;i <= nx; i++) {
00681                         val   = rdata(i,j,k);
00682                         sum1 += val;
00683                         MX   += ((i-1)*val);
00684                 }
00685                 MX=(MX/sum1);
00686                 for ( i = 1;i <= nx; i++) {
00687                         val   = rdata(i,j,k);
00688                         sum1 += val;
00689                         RG   += val*(square(MX - (i-1)));
00690                 }
00691                 RG=std::sqrt(RG/sum1);
00692                 MX=MX-(nx/2);
00693                 cntog.push_back(MX);
00694                 cntog.push_back(RG);
00695 #ifdef _WIN32
00696                 cntog.push_back((float)Util::round(MX));
00697 #else
00698                 cntog.push_back(round(MX));
00699 #endif  //_WIN32
00700         } else if (ndim == 2) {
00701                 for (j=1;j<=ny;j++) {
00702                         for (i=1;i<=nx;i++) {
00703                                 val = rdata(i,j,k);
00704                                 sum1 += val;
00705                                 MX   += ((i-1)*val);
00706                                 MY   += ((j-1)*val);
00707                         }
00708                 }
00709                 MX=(MX/sum1);
00710                 MY=(MY/sum1);
00711                 sum1=0.f;
00712                 RG=0.f;
00713                 for (j=1;j<=ny;j++) {
00714                         r = (square(MY-(j-1)));
00715                         for (i=1;i<=nx;i++) {
00716                                 val = rdata(i,j,k);
00717                                 sum1 += val;
00718                                 RG   += val*(square(MX - (i-1)) + r);
00719                         }
00720                 }
00721                 RG = std::sqrt(RG/sum1);
00722                 MX = MX - nx/2;
00723                 MY = MY - ny/2;
00724                 cntog.push_back(MX);
00725                 cntog.push_back(MY);
00726                 cntog.push_back(RG);
00727 #ifdef _WIN32
00728                 cntog.push_back((float)Util::round(MX));cntog.push_back((float)Util::round(MY));
00729 #else
00730                 cntog.push_back(round(MX));cntog.push_back(round(MY));
00731 #endif  //_WIN32
00732         } else {
00733                 for (k = 1;k <= nz;k++) {
00734                         for (j=1;j<=ny;j++) {
00735                                 for (i=1;i<=nx;i++) {
00736                                         val = rdata(i,j,k);
00737                                         sum1 += val;
00738                                         MX += ((i-1)*val);
00739                                         MY += ((j-1)*val);
00740                                         MZ += ((k-1)*val);
00741                                 }
00742                         }
00743                 }
00744                 MX = MX/sum1;
00745                 MY = MY/sum1;
00746                 MZ = MZ/sum1;
00747                 sum1=0.f;
00748                 RG=0.f;
00749                 for (k = 1;k <= nz;k++) {
00750                         for (j=1;j<=ny;j++) {
00751                                 float r = (square(MY-(j-1)) + square(MZ - (k-1)));
00752                                 for (i=1;i<=nx;i++) {
00753                                         val = rdata(i,j,k);
00754                                         sum1 += val;
00755                                         RG   += val*(square(MX - (i-1)) + r);
00756                                 }
00757                         }
00758                 }
00759                 RG = std::sqrt(RG/sum1);
00760                 MX = MX - nx/2;
00761                 MY = MY - ny/2;
00762                 MZ = MZ - nz/2;
00763                 cntog.push_back(MX);
00764                 cntog.push_back(MY);
00765                 cntog.push_back(MZ);
00766                 cntog.push_back(RG);
00767 #ifdef _WIN32
00768                 cntog.push_back((float)Util::round(MX));cntog.push_back((float)Util::round(MY));cntog.push_back((float)Util::round(MZ));
00769 #else
00770                 cntog.push_back(round(MX));cntog.push_back(round(MY));cntog.push_back(round(MZ));
00771 #endif  //_WIN32
00772         }
00773         return cntog;
00774 }

EMData * EMData::conjg (  ) 

Definition at line 4886 of file emdata_sparx.cpp.

References copy_head(), get_data(), ImageFormatException, in, nx, ny, and nz.

04887 {
04888         if(this->is_complex()) {
04889                 EMData* buf_new = this->copy_head();
04890                 float *in  = this->get_data();
04891                 float *out = buf_new->get_data();
04892                 for(int i=0; i<nx*ny*nz; i+=2) {out[i] = in[i]; out[i+1] = -in[i+1];}
04893                 return buf_new;
04894         } else throw ImageFormatException("image has to be complex");
04895 }

EMData * EMData::convolute ( EMData with  ) 

Convolutes 2 data sets.

The 2 images must be of the same size.

Parameters:
with One data set. 'this' image is the other data set.
Exceptions:
NullPointerException If FFT resturns NULL image.
Returns:
The result image.

Definition at line 3151 of file emdata.cpp.

References ap2ri(), copy(), do_fft(), do_ift(), ENTERFUNC, EXITFUNC, get_data(), get_xsize(), get_ysize(), get_zsize(), ImageFormatException, EMAN::EMUtil::is_same_size(), LOGERR, NullPointerException, and update().

Referenced by calc_fast_sigma_image(), and EMAN::FlattenBackgroundProcessor::process_inplace().

03152 {
03153         ENTERFUNC;
03154 
03155         EMData *f1 = do_fft();
03156         if (!f1) {
03157                 LOGERR("FFT returns NULL image");
03158                 throw NullPointerException("FFT returns NULL image");
03159         }
03160 
03161         f1->ap2ri();
03162 
03163         EMData *cf = 0;
03164         if (with) {
03165                 cf = with->do_fft();
03166                 if (!cf) {
03167                         LOGERR("FFT returns NULL image");
03168                         throw NullPointerException("FFT returns NULL image");
03169                 }
03170                 cf->ap2ri();
03171         }
03172         else {
03173                 cf = f1->copy();
03174         }
03175         //printf("cf_x=%d, f1y=%d, thisx=%d, withx=%d\n",cf->get_xsize(),f1->get_ysize(),this->get_xsize(),with->get_xsize());
03176         if (with && !EMUtil::is_same_size(f1, cf)) {
03177                 LOGERR("images not same size");
03178                 throw ImageFormatException("images not same size");
03179         }
03180 
03181         float *rdata1 = f1->get_data();
03182         float *rdata2 = cf->get_data();
03183         size_t cf_size = cf->get_xsize() * cf->get_ysize() * cf->get_zsize();
03184 
03185         float re,im;
03186 
03187         for (size_t i = 0; i < cf_size; i += 2) {
03188                 re = rdata1[i] * rdata2[i] - rdata1[i + 1] * rdata2[i + 1];
03189                 im = rdata1[i + 1] * rdata2[i] + rdata1[i] * rdata2[i + 1];
03190                 rdata2[i]=re;
03191                 rdata2[i+1]=im;
03192         }
03193         cf->update();
03194         EMData *f2 = cf->do_ift();//ming change cf to cf_temp
03195         //printf("cf_x=%d, f2x=%d, thisx=%d, withx=%d\n",cf->get_xsize(),f2->get_xsize(),this->get_xsize(),with->get_xsize());
03196         if( cf )
03197         {
03198                 delete cf;
03199                 cf = 0;
03200         }
03201 
03202         if( f1 )
03203         {
03204                 delete f1;
03205                 f1=0;
03206         }
03207 
03208         EXITFUNC;
03209         return f2;
03210 }

EMData * EMData::copy (  )  const

Make a copy of this image including both data and header.

Returns:
A copy of this image including both data and header.

Definition at line 82 of file emdata_core.cpp.

References EMData(), ENTERFUNC, and EXITFUNC.

Referenced by absi(), EMAN::MinMaxAverager::add_image(), EMAN::RTFExhaustiveAligner::align(), EMAN::RotateTranslateAligner::align(), calc_fast_sigma_image(), calc_flcf(), calc_mutual_correlation(), EMAN::FRCCmp::cmp(), EMAN::PhaseCmp::cmp(), common_lines_real(), convolute(), EMAN::FourierReconstructor::determine_slice_agreement(), do_radon(), EMAN::Processor::EMFourierFilterFunc(), FH2F(), filter_by_image(), EMAN::nn4_ctfReconstructor::finish(), EMAN::nn4Reconstructor::finish(), Four_ds(), Four_shuf_ds_cen_us(), EMAN::fourierproduct(), FourInterpol(), EMAN::FourierReconstructor::insert_slice(), log(), log10(), main(), EMAN::operator *(), EMAN::operator+(), EMAN::operator-(), EMAN::operator/(), EMAN::periodogram(), power(), EMAN::Reconstructor::preprocess_slice(), EMAN::FourierReconstructor::preprocess_slice(), EMAN::ScaleTransformProcessor::process(), EMAN::BooleanShrinkProcessor::process(), EMAN::FFTResampleProcessor::process(), EMAN::KmeansSegmentProcessor::process(), EMAN::Processor::process(), EMAN::CTFSNRWeightProcessor::process_inplace(), EMAN::SymSearchProcessor::process_inplace(), EMAN::LocalNormProcessor::process_inplace(), EMAN::MeanShrinkProcessor::process_inplace(), EMAN::MedianShrinkProcessor::process_inplace(), EMAN::SNREvalProcessor::process_inplace(), EMAN::FourierGriddingProjector::project3d(), real(), real2FH(), replace_amplitudes(), set_attr_python(), EMAN::PointArray::set_from_density_map(), and sqrt().

00083 {
00084         ENTERFUNC;
00085 
00086         EMData *ret = new EMData(*this);
00087 
00088         EXITFUNC;
00089         return ret;
00090 }

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 93 of file emdata_core.cpp.

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

Referenced by EMAN::CtfAverager::add_image(), EMAN::CtfCWautoAverager::add_image(), EMAN::Util::addn_img(), average_circ_sub(), conjg(), delete_disconnected_regions(), EMAN::Util::divn_filter(), EMAN::Util::divn_img(), do_fft(), do_ift(), downsample(), fouriergridrot2d(), fouriergridrot_shift2d(), FourTruncate(), get_fft_amplitude(), get_fft_amplitude2D(), get_fft_phase(), get_pow(), helicise(), little_big_dot(), EMAN::Util::madn_scalar(), EMAN::Util::muln_img(), mult_radial(), EMAN::Util::mult_scalar(), norm_pad(), EMAN::Util::pad(), EMAN::MeanShrinkProcessor::process(), EMAN::MedianShrinkProcessor::process(), rot_scale_conv(), rot_scale_conv7(), rot_scale_conv_new(), rot_scale_conv_new_background(), rot_scale_trans(), rot_scale_trans2D(), rot_scale_trans2D_background(), rot_scale_trans_background(), EMAN::Util::subn_img(), and EMAN::Util::window().

00094 {
00095         ENTERFUNC;
00096         EMData *ret = new EMData();
00097         ret->attr_dict = attr_dict;
00098 
00099         ret->set_size(nx, ny, nz);
00100         ret->flags = flags;
00101 
00102         ret->all_translation = all_translation;
00103 
00104         ret->path = path;
00105         ret->pathnum = pathnum;
00106 
00107 // should these be here? d.woolford I did not comment them out, merely place them here (commented out) to draw attention
00108 //      ret->xoff = xoff;
00109 //      ret->yoff = yoff;
00110 //      ret->zoff = zoff;
00111 //      ret->changecount = changecount;
00112 
00113         ret->update();
00114 
00115         EXITFUNC;
00116         return ret;
00117 }

void EMData::cut_slice ( const EMData *const   map,
const Transform tr,
bool  interpolate = true 
)

cut a 2D slice out of a real 3D map.

Put slice into 'this' image.

Parameters:
map The real 3D map.
tr orientation of the slice as encapsulated in a Transform object.
interpolate Do interpolation or not.
Exceptions:
NullPointerException If map is NULL.
ImageDimensionException If this image is not 2D.
ImageDimensionException If map image is not 3D.
ImageFormatException If this image is complex
ImageFormatException If map is complex
Author:
David Woolford (adapted from an original version by Steve Ludtke)
Date:
Feb 2008

Definition at line 3607 of file emdata.cpp.

References EMAN::Util::bilinear_interpolate(), ENTERFUNC, EXITFUNC, EMAN::Util::fast_floor(), get_data(), get_ndim(), get_xsize(), get_ysize(), get_zsize(), ImageDimensionException, ImageFormatException, is_complex(), EMAN::Util::linear_interpolate(), NullPointerException, nx, ny, EMAN::Util::round(), t, transform(), EMAN::Util::trilinear_interpolate(), update(), v, x, and y.

03608 {
03609         ENTERFUNC;
03610 
03611         if (!map) throw NullPointerException("NULL image");
03612         // These restrictions should be ultimately restricted so that all that matters is get_ndim() = (map->get_ndim() -1)
03613         if ( get_ndim() != 2 ) throw ImageDimensionException("Can not call cut slice on an image that is not 2D");
03614         if ( map->get_ndim() != 3 ) throw ImageDimensionException("Can not cut slice from an image that is not 3D");
03615         // Now check for complex images - this is really just being thorough
03616         if ( is_complex() ) throw ImageFormatException("Can not call cut slice on an image that is complex");
03617         if ( map->is_complex() ) throw ImageFormatException("Can not cut slice from a complex image");
03618 
03619 
03620         float *sdata = map->get_data();
03621         float *ddata = get_data();
03622 
03623         int map_nx = map->get_xsize();
03624         int map_ny = map->get_ysize();
03625         int map_nz = map->get_zsize();
03626         int map_nxy = map_nx * map_ny;
03627 
03628         int ymax = ny/2;
03629         if ( ny % 2 == 1 ) ymax += 1;
03630         int xmax = nx/2;
03631         if ( nx % 2 == 1 ) xmax += 1;
03632         for (int y = -ny/2; y < ymax; y++) {
03633                 for (int x = -nx/2; x < xmax; x++) {
03634                         Vec3f coord(x,y,0);
03635                         Vec3f soln = transform*coord;
03636 
03637 //                      float xx = (x+pretrans[0]) * (*ort)[0][0] +  (y+pretrans[1]) * (*ort)[0][1] + pretrans[2] * (*ort)[0][2] + posttrans[0];
03638 //                      float yy = (x+pretrans[0]) * (*ort)[1][0] +  (y+pretrans[1]) * (*ort)[1][1] + pretrans[2] * (*ort)[1][2] + posttrans[1];
03639 //                      float zz = (x+pretrans[0]) * (*ort)[2][0] +  (y+pretrans[1]) * (*ort)[2][1] + pretrans[2] * (*ort)[2][2] + posttrans[2];
03640 
03641 
03642 //                      xx += map_nx/2;
03643 //                      yy += map_ny/2;
03644 //                      zz += map_nz/2;
03645 
03646                         float xx = soln[0]+map_nx/2;
03647                         float yy = soln[1]+map_ny/2;
03648                         float zz = soln[2]+map_nz/2;
03649 
03650                         int l = (x+nx/2) + (y+ny/2) * nx;
03651 
03652                         float t = xx - floor(xx);
03653                         float u = yy - floor(yy);
03654                         float v = zz - floor(zz);
03655 
03656                         if (xx < 0 || yy < 0 || zz < 0 ) {
03657                                 ddata[l] = 0;
03658                                 continue;
03659                         }
03660                         if (interpolate) {
03661                                 if ( xx > map_nx - 1 || yy > map_ny - 1 || zz > map_nz - 1) {
03662                                         ddata[l] = 0;
03663                                         continue;
03664                                 }
03665                                 int k = (int) (Util::fast_floor(xx) + Util::fast_floor(yy) * map_nx + Util::fast_floor(zz) * map_nxy);
03666 
03667 
03668                                 if (xx < (map_nx - 1) && yy < (map_ny - 1) && zz < (map_nz - 1)) {
03669                                         ddata[l] = Util::trilinear_interpolate(sdata[k],
03670                                                                 sdata[k + 1], sdata[k + map_nx],sdata[k + map_nx + 1],
03671                                                                 sdata[k + map_nxy], sdata[k + map_nxy + 1], sdata[k + map_nx + map_nxy],
03672                                                                 sdata[k + map_nx + map_nxy + 1],t, u, v);
03673                                 }
03674                                 else if ( xx == (map_nx - 1) && yy == (map_ny - 1) && zz == (map_nz - 1) ) {
03675                                         ddata[l] += sdata[k];
03676                                 }
03677                                 else if ( xx == (map_nx - 1) && yy == (map_ny - 1) ) {
03678                                         ddata[l] +=     Util::linear_interpolate(sdata[k], sdata[k + map_nxy],v);
03679                                 }
03680                                 else if ( xx == (map_nx - 1) && zz == (map_nz - 1) ) {
03681                                         ddata[l] += Util::linear_interpolate(sdata[k], sdata[k + map_nx],u);
03682                                 }
03683                                 else if ( yy == (map_ny - 1) && zz == (map_nz - 1) ) {
03684                                         ddata[l] += Util::linear_interpolate(sdata[k], sdata[k + 1],t);
03685                                 }
03686                                 else if ( xx == (map_nx - 1) ) {
03687                                         ddata[l] += Util::bilinear_interpolate(sdata[k], sdata[k + map_nx], sdata[k + map_nxy], sdata[k + map_nxy + map_nx],u,v);
03688                                 }
03689                                 else if ( yy == (map_ny - 1) ) {
03690                                         ddata[l] += Util::bilinear_interpolate(sdata[k], sdata[k + 1], sdata[k + map_nxy], sdata[k + map_nxy + 1],t,v);
03691                                 }
03692                                 else if ( zz == (map_nz - 1) ) {
03693                                         ddata[l] += Util::bilinear_interpolate(sdata[k], sdata[k + 1], sdata[k + map_nx], sdata[k + map_nx + 1],t,u);
03694                                 }
03695 
03696 //                              if (k >= map->get_size()) {
03697 //                                      cout << xx << " " << yy << " " <<  zz << " " << endl;
03698 //                                      cout << k << " " << get_size() << endl;
03699 //                                      cout << get_xsize() << " " << get_ysize() << " " << get_zsize() << endl;
03700 //                                      throw;
03701 //                                      }
03702 //
03703 //                              ddata[l] = Util::trilinear_interpolate(sdata[k],
03704 //                                              sdata[k + 1], sdata[k + map_nx],sdata[k + map_nx + 1],
03705 //                                              sdata[k + map_nxy], sdata[k + map_nxy + 1], sdata[k + map_nx + map_nxy],
03706 //                                              sdata[k + map_nx + map_nxy + 1],t, u, v);
03707                         }
03708                         else {
03709                                 if ( xx > map_nx - 1 || yy > map_ny - 1 || zz > map_nz - 1) {
03710                                         ddata[l] = 0;
03711                                         continue;
03712                                 }
03713                                 int k = Util::round(xx) + Util::round(yy) * map_nx + Util::round(zz) * map_nxy;
03714                                 ddata[l] = sdata[k];
03715                         }
03716 
03717                 }
03718         }
03719 
03720         update();
03721 
03722         EXITFUNC;
03723 }

void EMAN::EMData::debug_print_parms (  )  [inline]

Printing EMData params for debugging purpose.

Definition at line 3733 of file emdata.h.

void EMData::del_attr ( const string &  attr_name  ) 

Delete the attribute from dictionary.

Parameters:
attr_name the attribute name to be removed

Definition at line 1070 of file emdata_metadata.cpp.

References attr_dict, and EMAN::Dict::erase().

01071 {
01072         attr_dict.erase(attr_name);
01073 }

void EMData::del_attr_dict ( const vector< string > &  del_keys  ) 

Delete the attributes from the dictionary.

Parameters:
del_keys the attrutes' names to be removed

Definition at line 1075 of file emdata_metadata.cpp.

01076 {
01077         vector<string>::const_iterator it;
01078         for(it=del_keys.begin(); it!=del_keys.end(); ++it) {
01079                 this->del_attr(*it);
01080         }
01081 }

EMData * EMData::delete_disconnected_regions ( int  ix = 0,
int  iy = 0,
int  iz = 0 
)

Delete disconnected regions in a binary image.

Works only for a volume.

Parameters:
[in] ix,: x coordinate (with respect to the center) from which the search of the compact region begins.
[in] iy,: y coordinate (with respect to the center) from which the search of the compact region begins.
[in] iz,: z coordinate (with respect to the center) from which the search of the compact region begins.
Returns:
New binary image

Definition at line 4897 of file emdata_sparx.cpp.

References copy_head(), get_ndim(), ImageDimensionException, ImageFormatException, is_complex(), nx, ny, nz, to_zero(), and update().

04897                                                                   {
04898         if (3 != get_ndim())
04899                 throw ImageDimensionException("delete_disconnected_regions needs a 3-D image.");
04900         if (is_complex())
04901                 throw ImageFormatException("delete_disconnected_regions requires a real image");
04902         if ((*this)(ix+nx/2,iy+ny/2,iz+nz/2) == 0)
04903                 throw ImageDimensionException("delete_disconnected_regions starting point is zero.");
04904 
04905         EMData* result = this->copy_head();
04906         result->to_zero();
04907         (*result)(ix+nx/2,iy+ny/2,iz+nz/2) = (*this)(ix+nx/2,iy+ny/2,iz+nz/2);
04908         bool kpt = true;
04909         //cout << "  delete   "<<(*result)(ix+nx/2,iy+ny/2,iz+nz/2)<<endl;
04910         while(kpt) {
04911                 kpt = false;
04912                 for (int cz = 1; cz < nz-1; cz++) {
04913                         for (int cy = 1; cy < ny-1; cy++) {
04914                                 for (int cx = 1; cx < nx-1; cx++) {
04915                                         if((*result)(cx,cy,cz) == 1) {
04916                                                 for (int lz = -1; lz <= 1; lz++) {
04917                                                         for (int ly = -1; ly <= 1; ly++) {
04918                                                                 for (int lx = -1; lx <= 1; lx++) {
04919                                                                         if(((*this)(cx+lx,cy+ly,cz+lz) == 1) && ((*result)(cx+lx,cy+ly,cz+lz) == 0))  {
04920                                                                                 (*result)(cx+lx,cy+ly,cz+lz) = 1;
04921                                                                                 kpt = true;
04922                                                                         }
04923                                                                 }
04924                                                         }
04925                                                 }
04926                                         }
04927                                 }
04928                         }
04929                 }
04930         }
04931         result->update();
04932         return result;
04933 }

void EMData::depad (  ) 

De-pad, and and remove Fourier extension convenience function.

Purpose: De-pad, and and remove Fourier extension from a real image.
Method: Remove padding and extension along x for fft,
and return the new image.
Returns:
depadded input image.

Definition at line 5044 of file emdata_sparx.cpp.

References attr_dict, EXITFUNC, get_array_offsets(), get_data(), ImageFormatException, is_complex(), is_fftodd(), nx, ny, nz, set_array_offsets(), set_attr(), set_complex(), set_complex_x(), set_fftodd(), set_fftpad(), set_size(), and update().

Referenced by EMAN::Processor::EMFourierFilterFunc(), filter_by_image(), EMAN::nn4_ctfReconstructor::finish(), EMAN::nn4Reconstructor::finish(), EMAN::FourierReconstructor::finish(), EMAN::FourierReconstructorSimple2D::finish(), Four_ds(), Four_shuf_ds_cen_us(), EMAN::fourierproduct(), FourInterpol(), FourTruncate(), EMAN::TestImageFourierNoiseProfile::process_inplace(), EMAN::CTFSNRWeightProcessor::process_inplace(), EMAN::TestImageFourierNoiseGaussian::process_inplace(), and replace_amplitudes().

05044                    {
05045         if (is_complex())
05046                 throw ImageFormatException("Depadding of complex images not supported");
05047         vector<int> saved_offsets = get_array_offsets();
05048         set_array_offsets(0,0,0);
05049         int npad = attr_dict["npad"];
05050         if (0 == npad) npad = 1;
05051         int offset = is_fftodd() ? 1 : 2;
05052         int nxold = (nx - offset)/npad;
05053 #ifdef _WIN32
05054         int nyold = _cpp_max(ny/npad, 1);
05055         int nzold = _cpp_max(nz/npad, 1);
05056 #else
05057         int nyold = std::max<int>(ny/npad, 1);
05058         int nzold = std::max<int>(nz/npad, 1);
05059 #endif  //_WIN32
05060         int xstart = 0, ystart = 0, zstart = 0;
05061         if( npad > 1) {
05062                 xstart = (nx - offset - nxold)/2 + nxold%2;
05063                 if(ny > 1) {
05064                         ystart = (ny - nyold)/2 + nyold%2;
05065                         if(nz > 1) {
05066                                 zstart = (nz - nzold)/2 + nzold%2;
05067                         }
05068                 }
05069         }
05070         int bytes = nxold*sizeof(float);
05071         float* dest = get_data();
05072         for (int iz=0; iz < nzold; iz++) {
05073                 for (int iy = 0; iy < nyold; iy++) {
05074                         memmove(dest, &(*this)(xstart,iy+ystart,iz+zstart), bytes);
05075                         dest += nxold;
05076                 }
05077         }
05078         set_size(nxold, nyold, nzold);
05079         set_attr("npad", 1);
05080         set_fftpad(false);
05081         set_fftodd(false);
05082         set_complex(false);
05083         if(ny==1 && nz==1) set_complex_x(false);
05084         set_array_offsets(saved_offsets);
05085         update();
05086         EXITFUNC;
05087 }

void EMData::depad_corner (  ) 

De-pad, and and remove Fourier extension convenience function.

Purpose: De-pad, and and remove Fourier extension from a real image.
Method: Remove padding and extension along x for fft,
and return the new image.
Returns:
depadded input image.

Definition at line 5096 of file emdata_sparx.cpp.

References attr_dict, EXITFUNC, get_array_offsets(), get_data(), ImageFormatException, is_complex(), is_fftodd(), nx, ny, nz, set_array_offsets(), set_attr(), set_complex(), set_complex_x(), set_fftodd(), set_fftpad(), set_size(), and update().

Referenced by EMAN::FFTResampleProcessor::fft_resample(), and EMAN::fourierproduct().

05096                           {
05097         if(is_complex())
05098                 throw ImageFormatException("Depadding of complex images not allowed");
05099         vector<int> saved_offsets = get_array_offsets();
05100         set_array_offsets(0,0,0);
05101         int npad = attr_dict["npad"];
05102         if(0 == npad) npad = 1;
05103         int offset = is_fftodd() ? 1 : 2;
05104         int nxold = (nx - offset)/npad;
05105 #ifdef _WIN32
05106         int nyold = _cpp_max(ny/npad, 1);
05107         int nzold = _cpp_max(nz/npad, 1);
05108 #else
05109         int nyold = std::max<int>(ny/npad, 1);
05110         int nzold = std::max<int>(nz/npad, 1);
05111 #endif  //_WIN32
05112         int bytes = nxold*sizeof(float);
05113         float* dest = get_data();
05114         for (int iz=0; iz < nzold; iz++) {
05115                 for (int iy = 0; iy < nyold; iy++) {
05116                         memmove(dest, &(*this)(0,iy,iz), bytes);
05117                         dest += nxold;
05118                 }
05119         }
05120         set_size(nxold, nyold, nzold);
05121         set_attr("npad", 1);
05122         set_fftpad(false);
05123         set_fftodd(false);
05124         set_complex(false);
05125         if(ny==1 && nz==1) set_complex_x(false);
05126         set_array_offsets(saved_offsets);
05127         update();
05128         EXITFUNC;
05129 }

void EMData::div ( const EMData image  ) 

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

Parameters:
image The image 'this' image divided by.
Exceptions:
ImageFormatException If the 2 images are not same size.

Definition at line 599 of file emdata_core.cpp.

References data, ENTERFUNC, EXITFUNC, get_data(), get_xsize(), get_ysize(), get_zsize(), ImageFormatException, InvalidValueException, is_real(), nx, nxyz, ny, nz, and update().

00600 {
00601         ENTERFUNC;
00602 
00603         if (nx != em.get_xsize() || ny != em.get_ysize() || nz != em.get_zsize()) {
00604                 throw ImageFormatException( "images not same sizes");
00605         }
00606         else if( (is_real()^em.is_real()) == true )
00607         {
00608                 throw ImageFormatException( "not support division between real image and complex image");
00609         }
00610         else {
00611                 const float *src_data = em.get_data();
00612                 size_t size = nxyz;
00613                 float* data = get_data();
00614 
00615                 if( is_real() )
00616                 {
00617                         for (size_t i = 0; i < size; i++) {
00618                                 if(src_data[i] != 0) {
00619                                         data[i] /= src_data[i];
00620                                 }
00621                                 else {
00622                                         throw InvalidValueException(src_data[i], "divide by zero");
00623                                 }
00624                         }
00625                 }
00626                 else
00627                 {
00628                         typedef std::complex<float> comp;
00629                         for( size_t i = 0; i < size; i+=2 )
00630                         {
00631                                 comp c_src( src_data[i], src_data[i+1] );
00632                                 comp c_rdat( data[i], data[i+1] );
00633                                 comp c_result = c_rdat / c_src;
00634                                 data[i] = c_result.real();
00635                                 data[i+1] = c_result.imag();
00636                         }
00637                 }
00638                 update();
00639         }
00640 
00641         EXITFUNC;
00642 }

void EMData::div ( float  f  ) 

make each pixel value divided by a float number.

Parameters:
f The float number 'this' image divided by.

Definition at line 588 of file emdata_core.cpp.

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

Referenced by calc_flcf(), EMAN::operator/(), operator/=(), and EMAN::LocalNormProcessor::process_inplace().

00589 {
00590         ENTERFUNC;
00591         if ( f == 0 ) {
00592                 throw InvalidValueException(f,"Can not divide by zero");
00593         }
00594         mult(1.0f/f);
00595         EXITFUNC;
00596 }

void EMData::divkbsinh ( const Util::KaiserBessel kb  ) 

divkbsinh -- Divide image by a Kaiser-Bessel sinh window.

Parameters:
[in] kb Kaiser-Bessel window object
Note: Ideally this method really should be a "processor" instead, but at the moment a KaiserBessel object cannot be passed as part of a Dict, making the usual EMData::project() interface rather awkward here.

Definition at line 3417 of file emdata_sparx.cpp.

References get_array_offsets(), ImageFormatException, is_complex(), nx, ny, nz, set_array_offsets(), and EMAN::Util::KaiserBessel::sinhwin().

Referenced by EMAN::FourierGriddingProjector::project3d().

03417                                                  {
03418         if (is_complex())
03419                 throw ImageFormatException("divkbsinh requires a real image.");
03420         vector<int> saved_offsets = get_array_offsets();
03421         set_array_offsets(0,0,0);
03422         // Note that the following loops will work for 1-, 2-, and 3-D
03423         // images, since the "extra" weights will be 1.0.  (For example,
03424         // for a 2-d image iz=0, nz=1, so iz-nz/2 = 0 - 1/2 = 0, since
03425         // the division is an integer division.)
03426         for (int iz=0; iz < nz; iz++) {
03427                 float wz = kb.sinhwin(static_cast<float>(iz-nz/2));
03428                 for (int iy=0; iy < ny; iy++) {
03429                         float wy = kb.sinhwin(static_cast<float>(iy-ny/2));
03430                         for (int ix=0; ix < nx; ix++) {
03431                                 float wx = kb.sinhwin(static_cast<float>(ix-nx/2));
03432                                 float w = wx*wy*wz;
03433                                 (*this)(ix,iy,iz) /= w;
03434                         }
03435                 }
03436         }
03437         set_array_offsets(saved_offsets);
03438 }

EMData * EMData::do_fft_inplace (  ) 

Do FFT inplace.

And return the FFT image.

Returns:
The FFT of the current image in real/imaginary format.

Definition at line 192 of file emdata_transform.cpp.

References ENTERFUNC, EXITFUNC, get_data(), ImageFormatException, is_complex(), is_fftodd(), is_fftpadded(), LOGERR, nx, ny, nz, rdata, set_complex(), set_complex_x(), set_fftodd(), set_fftpad(), set_ri(), set_size(), and update().

Referenced by calc_fourier_shell_correlation(), EMAN::FRCCmp::cmp(), EMAN::PhaseCmp::cmp(), EMAN::Processor::EMFourierFilterFunc(), EMAN::FFTResampleProcessor::fft_resample(), filter_by_image(), EMAN::fourierproduct(), EMAN::FourierReconstructorSimple2D::insert_slice(), EMAN::padfft_slice(), EMAN::periodogram(), EMAN::FourierReconstructor::preprocess_slice(), EMAN::FFTProcessor::process_inplace(), EMAN::CTFSNRWeightProcessor::process_inplace(), EMAN::FourierGriddingProjector::project3d(), and replace_amplitudes().

00193 {
00194         ENTERFUNC;
00195 
00196         if ( is_complex() ) {
00197                 LOGERR("real image expected. Input image is complex image.");
00198                 throw ImageFormatException("real image expected. Input image is complex image.");
00199         }
00200 
00201         size_t offset;
00202         int nxreal;
00203         get_data(); // Required call if GPU caching is being used. Otherwise harmless
00204         if (!is_fftpadded()) {
00205                 // need to extend the matrix along x
00206                 // meaning nx is the un-fftpadded size
00207                 nxreal = nx;
00208                 offset = 2 - nx%2;
00209                 if (1 == offset) set_fftodd(true);
00210                 else             set_fftodd(false);
00211                 int nxnew = nx + offset;
00212                 set_size(nxnew, ny, nz);
00213 
00214                 for (int iz = nz-1; iz >= 0; iz--) {
00215                         for (int iy = ny-1; iy >= 0; iy--) {
00216                                 for (int ix = nxreal-1; ix >= 0; ix--) {
00217                                         size_t oldxpos = ix + (iy + iz*ny)*nxreal;
00218                                         size_t newxpos = ix + (iy + iz*ny)*nxnew;
00219                                         (*this)(newxpos) = (*this)(oldxpos);
00220                                 }
00221                         }
00222                 }
00223                 set_fftpad(true);
00224         } else {
00225                 offset = is_fftodd() ? 1 : 2;
00226                 nxreal = nx - offset;
00227         }
00228         EMfft::real_to_complex_nd(rdata, rdata, nxreal, ny, nz);
00229 
00230         set_complex(true);
00231         if(ny==1 && nz==1)  set_complex_x(true);
00232         set_ri(true);
00233 
00234         update();
00235 
00236         EXITFUNC;
00237         return this;
00238 }

EMData * EMData::do_ift_inplace (  ) 

Definition at line 310 of file emdata_transform.cpp.

References ap2ri(), data, ENTERFUNC, EXITFUNC, get_data(), ImageFormatException, is_complex(), is_fftodd(), is_ri(), LOGERR, LOGWARN, mult(), nx, ny, nz, set_complex(), set_complex_x(), set_fftpad(), set_ri(), set_size(), and update().

Referenced by EMAN::PhaseCmp::cmp(), EMAN::Processor::EMFourierFilterFunc(), EMAN::FFTResampleProcessor::fft_resample(), filter_by_image(), EMAN::nn4_ctfReconstructor::finish(), EMAN::nn4Reconstructor::finish(), EMAN::FourierReconstructor::finish(), EMAN::FourierReconstructorSimple2D::finish(), Four_ds(), Four_shuf_ds_cen_us(), EMAN::fourierproduct(), FourInterpol(), FourTruncate(), EMAN::FFTProcessor::process_inplace(), EMAN::TestImageFourierNoiseProfile::process_inplace(), EMAN::CTFSNRWeightProcessor::process_inplace(), EMAN::TestImageFourierNoiseGaussian::process_inplace(), and replace_amplitudes().

00311 {
00312         ENTERFUNC;
00313 
00314         if (!is_complex()) {
00315                 LOGERR("complex image expected. Input image is real image.");
00316                 throw ImageFormatException("complex image expected. Input image is real image.");
00317         }
00318 
00319         if (!is_ri()) {
00320                 LOGWARN("run IFT on AP data, only RI should be used. ");
00321         }
00322         ap2ri();
00323 
00324         int offset = is_fftodd() ? 1 : 2;
00325         float* data = get_data();
00326         EMfft::complex_to_real_nd(data, data, nx - offset, ny, nz);
00327 
00328 #if defined     FFTW2 || defined FFTW3 || defined CUDA_FFT      //native fft and ACML already done normalization
00329         // SCALE the inverse FFT
00330         int nxo = nx - offset;
00331         float scale = 1.0f / (nxo * ny * nz);
00332         mult(scale);
00333 #endif //FFTW2 || FFTW3
00334 
00335 #ifndef CUDA_FFT
00336         set_fftpad(true);
00337 #else
00338         set_size(nx - offset, ny, nz);
00339 #endif
00340         set_complex(false);
00341         if(ny==1 && nz==1) set_complex_x(false);
00342         set_ri(false);
00343         update();
00344 
00345 
00346         EXITFUNC;
00347         return this;
00348 }

EMData * EMData::do_radon (  ) 

Radon Transform: an algorithm that transforms an original image into a series of equiangular projections.

When applied to a 2D object, the output of the Radon transform is a series of 1D lines.

Do radon transformation on this image. This image must be 2D square.

Exceptions:
ImageFormatException If the image is not square.
ImageDimensionException If the image is not 2D.
Returns:
Radon transform image in square.

Definition at line 1338 of file emdata.cpp.

References copy(), EMData(), ENTERFUNC, EXITFUNC, get_data(), get_ndim(), ImageDimensionException, ImageFormatException, nx, ny, set_size(), EMAN::Util::square(), t, to_zero(), transform(), update(), x, and y.

Referenced by main().

01339 {
01340         ENTERFUNC;
01341 
01342         if (get_ndim() != 2) {
01343                 throw ImageDimensionException("2D only");
01344         }
01345 
01346         if (nx != ny) {
01347                 throw ImageFormatException("square image only");
01348         }
01349 
01350         EMData *result = new EMData();
01351         result->set_size(nx, ny, 1);
01352         result->to_zero();
01353         float *result_data = result->get_data();
01354 
01355         EMData *this_copy = this;
01356         this_copy = copy();
01357 
01358         for (int i = 0; i < nx; i++) {
01359                 Transform t(Dict("type","2d","alpha",(float) M_PI * 2.0f * i / nx));
01360                 this_copy->transform(t);
01361 
01362                 float *copy_data = this_copy->get_data();
01363 
01364                 for (int y = 0; y < nx; y++) {
01365                         for (int x = 0; x < nx; x++) {
01366                                 if (Util::square(x - nx / 2) + Util::square(y - nx / 2) <= nx * nx / 4) {
01367                                         result_data[i + y * nx] += copy_data[x + y * nx];
01368                                 }
01369                         }
01370                 }
01371 
01372                 this_copy->update();
01373         }
01374 
01375         result->update();
01376 
01377         if( this_copy )
01378         {
01379                 delete this_copy;
01380                 this_copy = 0;
01381         }
01382 
01383         EXITFUNC;
01384         return result;
01385 }

float EMData::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:
with The image to do dot product with.
Exceptions:
NullPointerException if with is a NULL image.
Returns:
The dot product result.

Definition at line 646 of file emdata_core.cpp.

References EMAN::DotCmp::cmp(), ENTERFUNC, EXITFUNC, and NullPointerException.

Referenced by EMAN::TomoDotCmp::cmp(), little_big_dot(), and make_footprint().

00647 {
00648         ENTERFUNC;
00649         if (!with) {
00650                 throw NullPointerException("Null EMData Image");
00651         }
00652         DotCmp dot_cmp;
00653         float r = -dot_cmp.cmp(this, with);
00654         EXITFUNC;
00655         return r;
00656 }

double EMData::dot_rotate_translate ( EMData with,
float  dx,
float  dy,
float  da,
const bool  mirror = false 
)

dot product of 2 images.

Then 'this' image is rotated/translated. It is much faster than Rotate/Translate then dot product. 2D images only.

Parameters:
with The image used to do the dot product.
dx Translation distance in x direction.
dy Translation distance in y direction.
da Rotation euler angle in degrees
mirror 
Exceptions:
ImageFormatException If the 2 images are not the same size.
ImageDimensionException If the image is 3D.
Returns:

Definition at line 1164 of file emdata.cpp.

References ENTERFUNC, EXITFUNC, EMAN::Util::fast_floor(), get_data(), get_ndim(), ImageDimensionException, ImageFormatException, EMAN::EMUtil::is_same_size(), LOGERR, nx, ny, t, and y.

Referenced by refalifnfast().

01165 {
01166         ENTERFUNC;
01167 
01168         if (!EMUtil::is_same_size(this, with)) {
01169                 LOGERR("images not same size");
01170                 throw ImageFormatException("images not same size");
01171         }
01172 
01173         if (get_ndim() == 3) {
01174                 LOGERR("1D/2D Images only");
01175                 throw ImageDimensionException("1D/2D only");
01176         }
01177 
01178         float *this_data = 0;
01179 
01180         this_data = get_data();
01181 
01182         float da_rad = da*(float)M_PI/180.0f;
01183 
01184         float *with_data = with->get_data();
01185         float mx0 = cos(da_rad);
01186         float mx1 = sin(da_rad);
01187         float y = -ny / 2.0f;
01188         float my0 = mx0 * (-nx / 2.0f - 1.0f) + nx / 2.0f - dx;
01189         float my1 = -mx1 * (-nx / 2.0f - 1.0f) + ny / 2.0f - dy;
01190         double result = 0;
01191 
01192         for (int j = 0; j < ny; j++) {
01193                 float x2 = my0 + mx1 * y;
01194                 float y2 = my1 + mx0 * y;
01195 
01196                 int ii = Util::fast_floor(x2);
01197                 int jj = Util::fast_floor(y2);
01198                 float t = x2 - ii;
01199                 float u = y2 - jj;
01200 
01201                 for (int i = 0; i < nx; i++) {
01202                         t += mx0;
01203                         u -= mx1;
01204 
01205                         if (t >= 1.0f) {
01206                                 ii++;
01207                                 t -= 1.0f;
01208                         }
01209 
01210                         if (u >= 1.0f) {
01211                                 jj++;
01212                                 u -= 1.0f;
01213                         }
01214 
01215                         if (t < 0) {
01216                                 ii--;
01217                                 t += 1.0f;
01218                         }
01219 
01220                         if (u < 0) {
01221                                 jj--;
01222                                 u += 1.0f;
01223                         }
01224 
01225                         if (ii >= 0 && ii <= nx - 2 && jj >= 0 && jj <= ny - 2) {
01226                                 int k0 = ii + jj * nx;
01227                                 int k1 = k0 + 1;
01228                                 int k2 = k0 + nx + 1;
01229                                 int k3 = k0 + nx;
01230 
01231                                 float tt = 1 - t;
01232                                 float uu = 1 - u;
01233                                 int idx = i + j * nx;
01234                                 if (mirror) idx = nx-1-i+j*nx; // mirroring of Transforms is always about the y axis
01235                                 result += (this_data[k0] * tt * uu + this_data[k1] * t * uu +
01236                                                    this_data[k2] * t * u + this_data[k3] * tt * u) * with_data[idx];
01237                         }
01238                 }
01239                 y += 1.0f;
01240         }
01241 
01242         EXITFUNC;
01243         return result;
01244 }

EMData * EMData::downsample ( Util::sincBlackman kb,
float  scale = 1.0 
)

Definition at line 2600 of file emdata_sparx.cpp.

References copy_head(), get_array_offsets(), max, nx, ny, nz, set_array_offsets(), set_size(), to_zero(), x, and y.

02600                                                             {
02601 
02602         /*int M = kb.get_sB_size();
02603         int kbmin = -M/2;
02604         int kbmax = -kbmin;*/
02605 
02606         int nxn, nyn, nzn;
02607         nxn = (int)(nx*scale); nyn = (int)(ny*scale); nzn = (int)(nz*scale);
02608 
02609         vector<int> saved_offsets = get_array_offsets();
02610         set_array_offsets(0,0,0);
02611         EMData* ret = this->copy_head();
02612 #ifdef _WIN32
02613         ret->set_size(nxn, _MAX(nyn,1), _MAX(nzn,1));
02614 #else
02615         ret->set_size(nxn, std::max(nyn,1), std::max(nzn,1));
02616 #endif  //_WIN32
02617         ret->to_zero();  //we will leave margins zeroed.
02618 
02619         // scan new, find pixels in old
02620         for (int iy =0; iy < nyn; iy++) {
02621                 float y = float(iy)/scale;
02622                 for (int ix = 0; ix < nxn; ix++) {
02623                         float x = float(ix)/scale;
02624                         (*ret)(ix,iy) = this->get_pixel_filtered(x, y, 1.0f, kb);
02625                 }
02626         }
02627         set_array_offsets(saved_offsets);
02628         return ret;
02629 }

EMData * EMData::extract_plane ( const Transform tf,
Util::KaiserBessel kb 
)

extractplane -- Gridding convolution in 3D along a plane

Note: Expected to be used in combination with fourier gridding projections.

Parameters:
[in] tf transform matrix defining the intended plane.
[in] kb Kaiser-Bessel window
Returns:
Complex gridding plane
See also:
P.A. Penczek, R. Renka, and H. Schomberg, J. Opt. Soc. Am. A _21_, 499-509 (2004)

Definition at line 3465 of file emdata_sparx.cpp.

References abs, cmplx(), EMData(), get_array_offsets(), EMAN::Util::KaiserBessel::get_window_size(), EMAN::Util::KaiserBessel::i0win_tab(), ImageDimensionException, ImageFormatException, EMAN::Transform::invert(), is_complex(), nx, ny, nz, EMAN::Util::round(), set_array_offsets(), set_complex(), set_fftodd(), set_fftpad(), set_ri(), set_shuffled(), set_size(), EMAN::Util::sgn(), tf(), and to_zero().

Referenced by EMAN::FourierGriddingProjector::project3d(), and EMAN::Util::twoD_to_3D_ali().

03465                                                                        {
03466         if (!is_complex())
03467                 throw ImageFormatException("extractplane requires a complex image");
03468         if (nx%2 != 0)
03469                 throw ImageDimensionException("extractplane requires nx to be even");
03470         int nxreal = nx - 2;
03471         if (nxreal != ny || nxreal != nz)
03472                 throw ImageDimensionException("extractplane requires ny == nx == nz");
03473         // build complex result image
03474         EMData* res = new EMData();
03475         res->set_size(nx,ny,1);
03476         res->to_zero();
03477         res->set_complex(true);
03478         res->set_fftodd(false);
03479         res->set_fftpad(true);
03480         res->set_ri(true);
03481         // Array offsets: (0..nhalf,-nhalf..nhalf-1,-nhalf..nhalf-1)
03482         int n = nxreal;
03483         int nhalf = n/2;
03484         vector<int> saved_offsets = get_array_offsets();
03485         set_array_offsets(0,-nhalf,-nhalf);
03486         res->set_array_offsets(0,-nhalf,0);
03487         // set up some temporary weighting arrays
03488         int kbsize =  kb.get_window_size();
03489         int kbmin  = -kbsize/2;
03490         int kbmax  = -kbmin;
03491         float* wy0 = new float[kbmax - kbmin + 1];
03492         float* wy  = wy0 - kbmin; // wy[kbmin:kbmax]
03493         float* wx0 = new float[kbmax - kbmin + 1];
03494         float* wx  = wx0 - kbmin;
03495         float* wz0 = new float[kbmax - kbmin + 1];
03496         float* wz  = wz0 - kbmin;
03497         float rim = nhalf*float(nhalf);
03498         int count = 0;
03499         float wsum = 0.f;
03500         Transform tftrans = tf; // need transpose of tf here for consistency
03501         tftrans.invert();      // with spider
03502         for (int jy = -nhalf; jy < nhalf; jy++) {
03503                 for (int jx = 0; jx <= nhalf; jx++) {
03504                         Vec3f nucur((float)jx, (float)jy, 0.f);
03505                         Vec3f nunew = tftrans*nucur;
03506                         float xnew = nunew[0], ynew = nunew[1], znew = nunew[2];
03507                         if (xnew*xnew+ynew*ynew+znew*znew <= rim) {
03508                                 count++;
03509                                 std::complex<float> btq(0.f,0.f);
03510                                 bool flip = false;
03511                                 if (xnew < 0.f) {
03512                                         flip = true;
03513                                         xnew = -xnew;
03514                                         ynew = -ynew;
03515                                         znew = -znew;
03516                                 }
03517                                 int ixn = int(Util::round(xnew));
03518                                 int iyn = int(Util::round(ynew));
03519                                 int izn = int(Util::round(znew));
03520                                 // populate weight arrays
03521                                 for (int i=kbmin; i <= kbmax; i++) {
03522                                         int izp = izn + i;
03523                                         wz[i] = kb.i0win_tab(znew - izp);
03524                                         int iyp = iyn + i;
03525                                         wy[i] = kb.i0win_tab(ynew - iyp);
03526                                         int ixp = ixn + i;
03527                                         wx[i] = kb.i0win_tab(xnew - ixp);
03528 
03529                                 }
03530                                 // restrict weight arrays to non-zero elements
03531                                 int lnbz = 0;
03532                                 for (int iz = kbmin; iz <= -1; iz++) {
03533                                         if (wz[iz] != 0.f) {
03534                                                 lnbz = iz;
03535                                                 break;
03536                                         }
03537                                 }
03538                                 int lnez = 0;
03539                                 for (int iz = kbmax; iz >= 1; iz--) {
03540                                         if (wz[iz] != 0.f) {
03541                                                 lnez = iz;
03542                                                 break;
03543                                         }
03544                                 }
03545                                 int lnby = 0;
03546                                 for (int iy = kbmin; iy <= -1; iy++) {
03547                                         if (wy[iy] != 0.f) {
03548                                                 lnby = iy;
03549                                                 break;
03550                                         }
03551                                 }
03552                                 int lney = 0;
03553                                 for (int iy = kbmax; iy >= 1; iy--) {
03554                                         if (wy[iy] != 0.f) {
03555                                                 lney = iy;
03556                                                 break;
03557                                         }
03558                                 }
03559                                 int lnbx = 0;
03560                                 for (int ix = kbmin; ix <= -1; ix++) {
03561                                         if (wx[ix] != 0.f) {
03562                                                 lnbx = ix;
03563                                                 break;
03564                                         }
03565                                 }
03566                                 int lnex = 0;
03567                                 for (int ix = kbmax; ix >= 1; ix--) {
03568                                         if (wx[ix] != 0.f) {
03569                                                 lnex = ix;
03570                                                 break;
03571                                         }
03572                                 }
03573                                 if    (ixn >= -kbmin      && ixn <= nhalf-1-kbmax
03574                                    && iyn >= -nhalf-kbmin && iyn <= nhalf-1-kbmax
03575                                    && izn >= -nhalf-kbmin && izn <= nhalf-1-kbmax) {
03576                                         // interior points
03577                                         for (int lz = lnbz; lz <= lnez; lz++) {
03578                                                 int izp = izn + lz;
03579                                                 for (int ly=lnby; ly<=lney; ly++) {
03580                                                         int iyp = iyn + ly;
03581                                                         float ty = wz[lz]*wy[ly];
03582                                                         for (int lx=lnbx; lx<=lnex; lx++) {
03583                                                                 int ixp = ixn + lx;
03584                                                                 float wg = wx[lx]*ty;
03585                                                                 btq += cmplx(ixp,iyp,izp)*wg;
03586                                                                 wsum += wg;
03587                                                         }
03588                                                 }
03589                                         }
03590                                 } else {
03591                                         // points "sticking out"
03592                                         for (int lz = lnbz; lz <= lnez; lz++) {
03593                                                 int izp = izn + lz;
03594                                                 for (int ly=lnby; ly<=lney; ly++) {
03595                                                         int iyp = iyn + ly;
03596                                                         float ty = wz[lz]*wy[ly];
03597                                                         for (int lx=lnbx; lx<=lnex; lx++) {
03598                                                                 int ixp = ixn + lx;
03599                                                                 float wg = wx[lx]*ty;
03600                                                                 bool mirror = false;
03601                                                                 int ixt(ixp), iyt(iyp), izt(izp);
03602                                                                 if (ixt > nhalf || ixt < -nhalf) {
03603                                                                         ixt = Util::sgn(ixt)
03604                                                                                   *(n - abs(ixt));
03605                                                                         iyt = -iyt;
03606                                                                         izt = -izt;
03607                                                                         mirror = !mirror;
03608                                                                 }
03609                                                                 if (iyt >= nhalf || iyt < -nhalf) {
03610                                                                         if (ixt != 0) {
03611                                                                                 ixt = -ixt;
03612                                                                                 iyt = Util::sgn(iyt)
03613                                                                                           *(n - abs(iyt));
03614                                                                                 izt = -izt;
03615                                                                                 mirror = !mirror;
03616                                                                         } else {
03617                                                                                 iyt -= n*Util::sgn(iyt);
03618                                                                         }
03619                                                                 }
03620                                                                 if (izt >= nhalf || izt < -nhalf) {
03621                                                                         if (ixt != 0) {
03622                                                                                 ixt = -ixt;
03623                                                                                 iyt = -iyt;
03624                                                                                 izt = Util::sgn(izt)
03625                                                                                           *(n - abs(izt));
03626                                                                                 mirror = !mirror;
03627                                                                         } else {
03628                                                                                 izt -= Util::sgn(izt)*n;
03629                                                                         }
03630                                                                 }
03631                                                                 if (ixt < 0) {
03632                                                                         ixt = -ixt;
03633                                                                         iyt = -iyt;
03634                                                                         izt = -izt;
03635                                                                         mirror = !mirror;
03636                                                                 }
03637                                                                 if (iyt == nhalf) iyt = -nhalf;
03638                                                                 if (izt == nhalf) izt = -nhalf;
03639                                                                 if (mirror)   btq += conj(cmplx(ixt,iyt,izt))*wg;
03640                                                                 else          btq += cmplx(ixt,iyt,izt)*wg;
03641                                                                 wsum += wg;
03642                                                         }
03643                                                 }
03644                                         }
03645                                 }
03646                                 if (flip)  res->cmplx(jx,jy) = conj(btq);
03647                                 else       res->cmplx(jx,jy) = btq;
03648                         }
03649                 }
03650         }
03651         for (int jy = -nhalf; jy < nhalf; jy++)
03652                 for (int jx = 0; jx <= nhalf; jx++)
03653                         res->cmplx(jx,jy) *= count/wsum;
03654         delete[] wx0; delete[] wy0; delete[] wz0;
03655         set_array_offsets(saved_offsets);
03656         res->set_array_offsets(0,0,0);
03657         res->set_shuffled(true);
03658         return res;
03659 }

EMData * EMData::extractline ( Util::KaiserBessel kb,
float  nuxnew,
float  nuynew 
)

Definition at line 3083 of file emdata_sparx.cpp.

References abs, cmplx(), EMData(), get_array_offsets(), EMAN::Util::KaiserBessel::get_window_size(), EMAN::Util::KaiserBessel::i0win_tab(), ImageDimensionException, ImageFormatException, is_complex(), nx, ny, EMAN::Util::round(), set_array_offsets(), set_complex(), set_fftodd(), set_fftpad(), set_ri(), set_size(), EMAN::Util::sgn(), and to_zero().

03084 {
03085         if (!is_complex())
03086                 throw ImageFormatException("extractline requires a fourier image");
03087         if (nx%2 != 0)
03088                 throw ImageDimensionException("extractline requires nx to be even");
03089         int nxreal = nx - 2;
03090         if (nxreal != ny)
03091                 throw ImageDimensionException("extractline requires ny == nx");
03092         // build complex result image
03093         EMData* res = new EMData();
03094         res->set_size(nx,1,1);
03095         res->to_zero();
03096         res->set_complex(true);
03097         res->set_fftodd(false);
03098         res->set_fftpad(true);
03099         res->set_ri(true);
03100         // Array offsets: (0..nhalf,-nhalf..nhalf-1)
03101         int n = nxreal;
03102         int nhalf = n/2;
03103         vector<int> saved_offsets = get_array_offsets();
03104         set_array_offsets(0,-nhalf,-nhalf);
03105 
03106         // set up some temporary weighting arrays
03107         int kbsize = kb.get_window_size();
03108         int kbmin = -kbsize/2;
03109         int kbmax = -kbmin;
03110         float* wy0 = new float[kbmax - kbmin + 1];
03111         float* wy = wy0 - kbmin; // wy[kbmin:kbmax]
03112         float* wx0 = new float[kbmax - kbmin + 1];
03113         float* wx = wx0 - kbmin;
03114 
03115         int   count = 0;
03116         float wsum = 0.f;
03117         bool  flip = (nuxnew < 0.f);
03118 
03119         for (int jx = 0; jx <= nhalf; jx++) {
03120                 float xnew = jx*nuxnew, ynew = jx*nuynew;
03121                 count++;
03122                 std::complex<float> btq(0.f,0.f);
03123                 if (flip) {
03124                         xnew = -xnew;
03125                         ynew = -ynew;
03126                 }
03127                 int ixn = int(Util::round(xnew));
03128                 int iyn = int(Util::round(ynew));
03129                 // populate weight arrays
03130                 for (int i=kbmin; i <= kbmax; i++) {
03131                         int iyp = iyn + i;
03132                         wy[i] = kb.i0win_tab(ynew - iyp);
03133                         int ixp = ixn + i;
03134                         wx[i] = kb.i0win_tab(xnew - ixp);
03135                 }
03136                 // restrict weight arrays to non-zero elements
03137 
03138                 int lnby = 0;
03139                 for (int iy = kbmin; iy <= -1; iy++) {
03140                         if (wy[iy] != 0.f) {
03141                                 lnby = iy;
03142                                 break;
03143                         }
03144                 }
03145                 int lney = 0;
03146                 for (int iy = kbmax; iy >= 1; iy--) {
03147                         if (wy[iy] != 0.f) {
03148                                 lney = iy;
03149                                 break;
03150                         }
03151                 }
03152                 int lnbx = 0;
03153                 for (int ix = kbmin; ix <= -1; ix++) {
03154                         if (wx[ix] != 0.f) {
03155                                 lnbx = ix;
03156                                 break;
03157                         }
03158                 }
03159                 int lnex = 0;
03160                 for (int ix = kbmax; ix >= 1; ix--) {
03161                         if (wx[ix] != 0.f) {
03162                                 lnex = ix;
03163                                 break;
03164                         }
03165                 }
03166                 if (ixn >= -kbmin && ixn <= nhalf-1-kbmax
03167                                 && iyn >= -nhalf-kbmin && iyn <= nhalf-1-kbmax) {
03168                         // interior points
03169                         for (int ly=lnby; ly<=lney; ly++) {
03170                                 int iyp = iyn + ly;
03171                                 for (int lx=lnbx; lx<=lnex; lx++) {
03172                                         int ixp = ixn + lx;
03173                                         float wg = wx[lx]*wy[ly];
03174                                         btq += cmplx(ixp,iyp)*wg;
03175                                         wsum += wg;
03176                                 }
03177                         }
03178                 } else {
03179                         // points "sticking out"
03180                         for (int ly=lnby; ly<=lney; ly++) {
03181                                 int iyp = iyn + ly;
03182                                 for (int lx=lnbx; lx<=lnex; lx++) {
03183                                         int ixp = ixn + lx;
03184                                         float wg = wx[lx]*wy[ly];
03185                                         bool mirror = false;
03186                                         int ixt(ixp), iyt(iyp);
03187                                         if (ixt > nhalf || ixt < -nhalf) {
03188                                                 ixt = Util::sgn(ixt)*(n - abs(ixt));
03189                                                 iyt = -iyt;
03190                                                 mirror = !mirror;
03191                                         }
03192                                         if (iyt >= nhalf || iyt < -nhalf) {
03193                                                 if (ixt != 0) {
03194                                                         ixt = -ixt;
03195                                                         iyt = Util::sgn(iyt)*(n - abs(iyt));
03196                                                         mirror = !mirror;
03197                                                 } else {
03198                                                         iyt -= n*Util::sgn(iyt);
03199                                                 }
03200                                         }
03201                                         if (ixt < 0) {
03202                                                 ixt = -ixt;
03203                                                 iyt = -iyt;
03204                                                 mirror = !mirror;
03205                                         }
03206                                         if (iyt == nhalf) iyt = -nhalf;
03207                                         if (mirror) btq += conj(cmplx(ixt,iyt))*wg;
03208                                         else        btq += cmplx(ixt,iyt)*wg;
03209                                         wsum += wg;
03210                                 }
03211                         }
03212                 }
03213                 if (flip) res->cmplx(jx) = conj(btq);
03214                 else      res->cmplx(jx) = btq;
03215         }
03216         for (int jx = 0; jx <= nhalf; jx++)  res->cmplx(jx) *= count/wsum;
03217 
03218         delete[] wx0; delete[] wy0;
03219         set_array_offsets(saved_offsets);
03220         res->set_array_offsets(0,0,0);
03221         return res;
03222 }

std::complex< float > EMData::extractpoint ( float  xin,
float  yin,
Util::KaiserBessel kb 
)

extractpoint -- Gridding convolution

Note: Expected to be used in combination with fouriergridrot2d.

Parameters:
[in] xin x-position
[in] yin y-position
[in] kb Kaiser-Bessel window
Returns:
Complex gridding result
See also:
P.A. Penczek, R. Renka, and H. Schomberg, J. Opt. Soc. Am. A _21_, (2004)

Definition at line 2971 of file emdata_sparx.cpp.

References cmplx(), get_ndim(), EMAN::Util::KaiserBessel::get_window_size(), EMAN::Util::KaiserBessel::i0win_tab(), ImageDimensionException, ImageFormatException, is_complex(), nx, ny, and EMAN::Util::round().

02971                                                                                        {
02972         if (2 != get_ndim())
02973                 throw ImageDimensionException("extractpoint needs a 2-D image.");
02974         if (!is_complex())
02975                 throw ImageFormatException("extractpoint requires a fourier image");
02976         int nxreal = nx - 2;
02977         if (nxreal != ny)
02978                 throw ImageDimensionException("extractpoint requires ny == nx");
02979         int nhalf = nxreal/2;
02980         int kbsize = kb.get_window_size();
02981         int kbmin = -kbsize/2;
02982         int kbmax = -kbmin;
02983         bool flip = (nuxnew < 0.f);
02984         if (flip) {
02985                 nuxnew *= -1;
02986                 nuynew *= -1;
02987         }
02988         // put (xnew,ynew) on a grid.  The indices will be wrong for
02989         // the Fourier elements in the image, but the grid sizing will
02990         // be correct.
02991         int ixn = int(Util::round(nuxnew));
02992         int iyn = int(Util::round(nuynew));
02993         // set up some temporary weighting arrays
02994         float* wy0 = new float[kbmax - kbmin + 1];
02995         float* wy = wy0 - kbmin; // wy[kbmin:kbmax]
02996         float* wx0 = new float[kbmax - kbmin + 1];
02997         float* wx = wx0 - kbmin;
02998         for (int i = kbmin; i <= kbmax; i++) {
02999                         int iyp = iyn + i;
03000                         wy[i] = kb.i0win_tab(nuynew - iyp);
03001                         int ixp = ixn + i;
03002                         wx[i] = kb.i0win_tab(nuxnew - ixp);
03003         }
03004         // restrict loops to non-zero elements
03005         int iymin = 0;
03006         for (int iy = kbmin; iy <= -1; iy++) {
03007                 if (wy[iy] != 0.f) {
03008                         iymin = iy;
03009                         break;
03010                 }
03011         }
03012         int iymax = 0;
03013         for (int iy = kbmax; iy >= 1; iy--) {
03014                 if (wy[iy] != 0.f) {
03015                         iymax = iy;
03016                         break;
03017                 }
03018         }
03019         int ixmin = 0;
03020         for (int ix = kbmin; ix <= -1; ix++) {
03021                 if (wx[ix] != 0.f) {
03022                         ixmin = ix;
03023                         break;
03024                 }
03025         }
03026         int ixmax = 0;
03027         for (int ix = kbmax; ix >= 1; ix--) {
03028                 if (wx[ix] != 0.f) {
03029                         ixmax = ix;
03030                         break;
03031                 }
03032         }
03033         float wsum = 0.0f;
03034         for (int iy = iymin; iy <= iymax; iy++)
03035                 for (int ix = ixmin; ix <= ixmax; ix++)
03036                         wsum += wx[ix]*wy[iy];
03037         std::complex<float> result(0.f,0.f);
03038         if ((ixn >= -kbmin) && (ixn <= nhalf-1-kbmax) && (iyn >= -nhalf-kbmin) && (iyn <= nhalf-1-kbmax)) {
03039                 // (xin,yin) not within window border from the edge
03040                 for (int iy = iymin; iy <= iymax; iy++) {
03041                         int iyp = iyn + iy;
03042                         for (int ix = ixmin; ix <= ixmax; ix++) {
03043                                 int ixp = ixn + ix;
03044                                 float w = wx[ix]*wy[iy];
03045                                 std::complex<float> val = cmplx(ixp,iyp);
03046                                 result += val*w;
03047                         }
03048                 }
03049         } else {
03050                 // points that "stick out"
03051                 for (int iy = iymin; iy <= iymax; iy++) {
03052                         int iyp = iyn + iy;
03053                         for (int ix = ixmin; ix <= ixmax; ix++) {
03054                                 int ixp = ixn + ix;
03055                                 bool mirror = false;
03056                                 int ixt= ixp, iyt= iyp;
03057                                 if (ixt < 0) {
03058                                         ixt = -ixt;
03059                                         iyt = -iyt;
03060                                         mirror = !mirror;
03061                                 }
03062                                 if (ixt > nhalf) {
03063                                         ixt = nxreal - ixt;
03064                                         iyt = -iyt;
03065                                         mirror = !mirror;
03066                                 }
03067                                 if (iyt > nhalf-1)  iyt -= nxreal;
03068                                 if (iyt < -nhalf)   iyt += nxreal;
03069                                 float w = wx[ix]*wy[iy];
03070                                 std::complex<float> val = this->cmplx(ixt,iyt);
03071                                 if (mirror)  result += conj(val)*w;
03072                                 else         result += val*w;
03073                         }
03074                 }
03075         }
03076         if (flip)  result = conj(result)/wsum;
03077         else       result /= wsum;
03078         delete [] wx0;
03079         delete [] wy0;
03080         return result;
03081 }

void EMData::fft_shuffle (  ) 

fft_shuffle -- Shuffle a Fourier image to put the origin at (0,ny/2)

Our usual FFT convention puts the origin at (0,0), but then grid points corresponding to iy > ny/2 correspond to (unnormalized) frequencies iy-ny. This routine rearranges the columns of the Fourier image so that iy varies from -ny/2 to ny/2 (or ny/2 - 1 for ny even). This method acts as a toggle, so to unshuffle a Fourier image just call this method a second time.

Definition at line 3232 of file emdata_sparx.cpp.

References get_array_offsets(), ImageFormatException, is_complex(), is_shuffled(), nx, ny, nz, set_array_offsets(), set_shuffled(), swapx(), and update().

Referenced by fouriergridrot2d(), fouriergridrot_shift2d(), EMAN::FourierGriddingProjector::project3d(), and write_image().

03232                          {
03233         if (!is_complex())
03234                 throw ImageFormatException("fft_shuffle requires a fourier image");
03235         vector<int> offsets = get_array_offsets();
03236         set_array_offsets(); // clear offsets before shuffling
03237         EMData& self = *this;
03238         int nyhalf = ny/2;
03239         int nzhalf = nz/2;
03240         int nbytes = nx*sizeof(float);
03241         float* temp = new float[nx];
03242         for (int iz=0; iz < nz; iz++)
03243                 for (int iy=0; iy < nyhalf; iy++)
03244                         swapx(&self(0,iy,iz),&self(0,iy+nyhalf,iz),temp,nbytes);
03245         if (nz > 1) {
03246                 for (int iy=0; iy < ny; iy++)
03247                         for (int iz=0; iz < nzhalf; iz++)
03248                                 swapx(&self(0,iy,iz),&self(0,iy,iz+nzhalf),temp,nbytes);
03249         }
03250         set_shuffled(!is_shuffled()); // toggle
03251         set_array_offsets(offsets); // reset offsets
03252         update();
03253         delete[] temp;
03254 }

EMData * EMData::FH2F ( int  Size,
float  OverSamplekB,
int  IntensityFlag = 0 
)

returns the fourier version of the image from the FH version.

The current image is not changed. The result is in real/imaginary format. The FH switch is set off.

Parameters:
Size is the size of the image to be returned
OverSamplekB is a parameter controlling the fineness of the Fourier sampling
IntensityFlag =0 is the usual; =1 means that the input was an intensity
Returns:
the shuffled version of the FFT

Definition at line 223 of file emdata_sparx.cpp.

References copy(), get_xsize(), get_ysize(), get_zsize(), ImageFormatException, LOGERR, nx, ny, nz, Radialize(), set_complex(), set_complex_x(), set_fftodd(), set_FH(), set_ri(), set_shuffled(), set_size(), spline_mat(), sqrt(), to_zero(), and update().

Referenced by FH2Real().

00224 {
00225         int nx=get_xsize();
00226         int ny=get_ysize();
00227         int nz=get_zsize();
00228         float ScalFactor=4.1f;
00229         int Center = (int) floor((Size+1.0)/2.0 +.1);
00230         int CenterM= Center-1;
00231         int CountMax = (Center+1)*Center/2;
00232 
00233         int     *PermMatTr           = new int[CountMax];
00234         float  *RValsSorted         = new float[CountMax];
00235         float  *weightofkValsSorted = new float[CountMax];
00236         int      *SizeReturned        = new int[1];
00237         Util::Radialize(PermMatTr, RValsSorted,weightofkValsSorted,Size, SizeReturned);
00238         int RIntMax= SizeReturned[0];  // replaces CountMax; the latter should now never be used.
00239 //      kVec2Use = (0:1/OverSamplek:RValsSorted(RIntMax)+1/OverSamplek); %   in pixels  (otherwise need *2*pi/Size)
00240 
00241         int   mMax = (int) floor( ScalFactor*RValsSorted[RIntMax-1]+10.0);
00242 
00243         int    kIntMax  = 2+ (int) floor( RValsSorted[RIntMax-1]*OverSamplekB);
00244         float *kVec2Use = new float[kIntMax];
00245         for (int kk=0; kk<kIntMax; kk++){
00246                 kVec2Use[kk]= ((float) kk)/OverSamplekB;}
00247 
00248 
00249 
00250 #ifdef DEBUG
00251         printf("nx=%d, ny=%d, nz=%d Center=%d mMax=%d CountMax=%d kIntMax=%d Centerm1=%d  Size=%d\n\n",
00252             nx,ny,nz, Center, mMax, CountMax, kIntMax,  CenterM, Size);
00253 #endif
00254 
00255         EMData * rhoOfkmB = this;
00256 
00257 //     check mMax's are equal
00258 //     check kIntMax's are equal
00259 
00260         if ( (nx==2*(mMax+1)) && (ny==kIntMax) &&(nz==1) ) {
00261 
00262         EMData *rhoOfkandm = copy();
00263         rhoOfkandm ->set_size(2*(mMax+1),RIntMax);
00264         rhoOfkandm ->to_zero();
00265 //      MArray2D rhoOfkandm = tempCopy->get_2dview();  % Just changed Nov 20 2005
00266 //      printf("rhoOfkandm \n");
00267         for (int mr=0; mr <2*(mMax+1); mr++){
00268                 float *Row= new float[kIntMax];
00269                 float *RowOut= new float[RIntMax];
00270                 for (int ii=0; ii<kIntMax; ii++){ Row[ii]=(*rhoOfkmB)(mr,ii);}
00271                 Util::spline_mat(kVec2Use, Row, kIntMax,  RValsSorted, RowOut, RIntMax );
00272                 for (int ii=0; ii<RIntMax; ii++){
00273                         (*rhoOfkandm)(mr,ii) = RowOut[ii];
00274 //                      printf("%3.3f  ",RowOut[ii]);
00275                 }
00276 //              printf(" \n");
00277 //              rhoOfkandm(m+1,:) = spline(kVec2Use,rhoOfkmBReIm(m+1,1:kIntMax),kIntMax,RValsSorted);
00278         }
00279         rhoOfkandm ->update();
00280 
00281 //          So far so good PRB ....
00282 
00283         EMData* outCopy = rhoOfkandm ->copy();
00284         outCopy->set_size(2*Size,Size,1);
00285         outCopy->to_zero();
00286 //      MArray2D ImBWfftRm = outCopy->get_2dview();
00287 
00288         int Count =0, kInt, kIntm1;
00289         std::complex <float> ImfTemp;
00290         float kValue, thetak;
00291 
00292         for (int jkx=0; jkx <Center; jkx++) { // These index the outputted picture
00293                 for (int jky=0; jky<=jkx; jky++){
00294                         kInt = PermMatTr[Count];
00295                         kIntm1= kInt-1;
00296                         Count++;
00297                         float fjkx = float(jkx);
00298                         float fjky = float(jky);
00299 
00300                         kValue = std::sqrt(fjkx*fjkx +  fjky*fjky )  ;
00301 //                      mMaxR= floor(ScalFactor*kValue +10);
00302 
00303  //                   How many copies
00304 
00305                         thetak = atan2(fjky,fjkx);
00306                         ImfTemp = (*rhoOfkandm)(0, kIntm1) ;
00307                         for (int mm= 1; mm <mMax;mm++) {  // The index for m
00308                                 std::complex <float> fact(0,-mm*thetak);
00309                                 std::complex <float> expfact= exp(fact);
00310                                 std::complex <float> tempRho((*rhoOfkandm)(2*mm,kIntm1),(*rhoOfkandm)(2*mm+1,kIntm1));
00311                                 float mmFac = float(1-2*(mm%2));
00312                                 if (IntensityFlag==1){ mmFac=1;}
00313                                 ImfTemp +=   expfact * tempRho + mmFac  *conj(expfact*tempRho);//pow(float(-1),mm)
00314                         }
00315                         (*outCopy)(2*(CenterM+jkx),CenterM+jky)   = ImfTemp.real();
00316                         (*outCopy)(2*(CenterM+jkx)+1,CenterM+jky) = ImfTemp.imag();
00317 //                      printf("jkx=%d, jky=%d; %f + %f i \n",jkx,jky,ImfTemp.real(), ImfTemp.imag());
00318 
00319                         if (jky>0) {
00320                                 thetak = atan2(-fjky,fjkx);
00321                                 ImfTemp = (*rhoOfkandm)(0,kIntm1);
00322                                 for (int mm= 1; mm<mMax; mm++) { // The index for m
00323                                         std::complex <float> fact(0,-mm*thetak);
00324                                         std::complex <float> expfact= exp(fact);
00325                                         std::complex <float> tempRho((*rhoOfkandm)(2*mm,kIntm1), (*rhoOfkandm)(2*mm+1,kIntm1));
00326                                         float mmFac = float(1-2*(mm%2));
00327                                         if (IntensityFlag==1){ mmFac=1;}
00328                                         ImfTemp +=   expfact * tempRho +  mmFac  *conj(expfact*tempRho);
00329                                 }
00330                                 (*outCopy)(2*(CenterM+jkx),CenterM-jky)  = ImfTemp.real();
00331 
00332                                 (*outCopy)(2*(CenterM+jkx)+1,CenterM-jky) = ImfTemp.imag();
00333                         }
00334 
00335                         if (jkx>0) {
00336                                 thetak = atan2(fjky,-fjkx);
00337                                 ImfTemp = (*rhoOfkandm)(0,kIntm1);
00338                                 for (int mm= 1; mm<mMax; mm++) { // The index for m
00339                                         std::complex <float> fact(0,-mm*thetak);
00340                                         std::complex <float> expfact= exp(fact);
00341                                         std::complex <float> tempRho((*rhoOfkandm)(2*mm,kIntm1), (*rhoOfkandm)(2*mm+1,kIntm1));
00342                                         float mmFac = float(1-2*(mm%2));
00343                                         if (IntensityFlag==1){ mmFac=1;}
00344                                         ImfTemp +=   expfact * tempRho +  mmFac *conj(expfact*tempRho);
00345                                 }
00346                                 (*outCopy)(2*(CenterM-jkx)  ,CenterM+jky) = ImfTemp.real();
00347                                 (*outCopy)(2*(CenterM-jkx)+1,CenterM+jky) = ImfTemp.imag();
00348                         }
00349 
00350                         if (jkx>0 && jky>0) {
00351                                 thetak = atan2(-fjky,-fjkx);
00352                                 ImfTemp = (*rhoOfkandm)(0 , kIntm1);
00353                                 for (int mm= 1; mm<mMax; mm++) {  // The index for m
00354                                         std::complex <float> fact(0,-mm*thetak);
00355                                         std::complex <float> expfact= exp(fact);
00356                                         std::complex <float> tempRho( (*rhoOfkandm)(2*mm,kIntm1),(*rhoOfkandm)(2*mm+1,kIntm1) );
00357                                         float mmFac = float(1-2*(mm%2));
00358                                         if (IntensityFlag==1){ mmFac=1;}
00359                                         ImfTemp +=   expfact * tempRho +  mmFac *conj(expfact*tempRho);
00360                                 }
00361                                 (*outCopy)(2*(CenterM-jkx)  ,CenterM-jky) = ImfTemp.real();
00362                                 (*outCopy)(2*(CenterM-jkx)+1,CenterM-jky) = ImfTemp.imag();
00363                         }
00364 
00365                         if (jky< jkx) {
00366                                 thetak = atan2(fjkx,fjky);
00367                                 ImfTemp = (*rhoOfkandm)(0,kIntm1);
00368                                 for (int mm= 1; mm<mMax; mm++){ // The index for m
00369                                         std::complex <float> fact(0,-mm*thetak);
00370                                         std::complex <float> expfact= exp(fact);
00371                                         std::complex <float> tempRho((*rhoOfkandm)(2*mm,kIntm1),(*rhoOfkandm)(2*mm+1,kIntm1));
00372                                         float mmFac = float(1-2*(mm%2));
00373                                         if (IntensityFlag==1){ mmFac=1;}
00374                                         ImfTemp +=   expfact * tempRho +  mmFac *conj(expfact*tempRho);
00375                                 }
00376                                 (*outCopy)(2*(CenterM+jky)  ,CenterM+jkx) = ImfTemp.real();
00377                                 (*outCopy)(2*(CenterM+jky)+1,CenterM+jkx) = ImfTemp.imag();
00378 
00379                                 if (jky>0){
00380                                         thetak = atan2(fjkx,-fjky);
00381                                         ImfTemp = (*rhoOfkandm)(0, kIntm1);
00382                                         for (int mm= 1; mm <mMax; mm++) { // The index for m
00383                                                 std::complex <float> fact(0,-mm*thetak);
00384                                                 std::complex <float> expfact= exp(fact);
00385                                                 std::complex <float> tempRho((*rhoOfkandm)(2*mm,kIntm1),(*rhoOfkandm)(2*mm+1,kIntm1));
00386                                         float mmFac = float(1-2*(mm%2));
00387                                         if (IntensityFlag==1){ mmFac=1;}
00388                                                 ImfTemp +=  expfact * tempRho +  mmFac *conj(expfact*tempRho);
00389                                         }
00390                                         (*outCopy)(2*(CenterM-jky)  ,CenterM+jkx) = ImfTemp.real();
00391                                         (*outCopy)(2*(CenterM-jky)+1,CenterM+jkx) = ImfTemp.imag();
00392                                 }
00393 
00394                                  if (jkx>0) {
00395                                          thetak = atan2(-fjkx,fjky);
00396                                          ImfTemp = (*rhoOfkandm)(0,kIntm1);
00397                                         for (int mm= 1; mm <mMax; mm++) { // The index for m
00398                                                 std::complex <float> fact(0,-mm*thetak);
00399                                                 std::complex <float> expfact= exp(fact);
00400                                                 std::complex <float> tempRho((*rhoOfkandm)(2*mm,kIntm1),(*rhoOfkandm)(2*mm+1,kIntm1));
00401                                                 float mmFac = float(1-2*(mm%2));
00402                                                 if (IntensityFlag==1){ mmFac=1;}
00403                                                 ImfTemp +=  expfact * tempRho +  mmFac *conj(expfact*tempRho);
00404                                         }
00405                                         (*outCopy)(2*(CenterM+jky)  ,CenterM-jkx) = ImfTemp.real();
00406                                         (*outCopy)(2*(CenterM+jky)+1,CenterM-jkx) = ImfTemp.imag();
00407                                 }
00408 
00409                                 if (jkx>0 && jky>0) {
00410                                         thetak = atan2(-fjkx,-fjky);
00411                                         ImfTemp = (*rhoOfkandm)(0,kIntm1) ;
00412                                         for (int mm= 1; mm <mMax; mm++) { // The index for m
00413                                                 std::complex <float> fact(0,-mm*thetak);
00414                                                 std::complex <float> expfact= exp(fact);
00415                                                 std::complex <float> tempRho((*rhoOfkandm)(2*mm,kIntm1) ,(*rhoOfkandm)(2*mm+1,kIntm1) );
00416                                                 float mmFac = float(1-2*(mm%2));
00417                                                 if (IntensityFlag==1){ mmFac=1;}
00418                                                 ImfTemp +=  expfact * tempRho +  mmFac *conj(expfact*tempRho);
00419                                         }
00420                                         (*outCopy)(2*(CenterM-jky)  ,CenterM-jkx) = ImfTemp.real();
00421                                         (*outCopy)(2*(CenterM-jky)+1,CenterM-jkx) = ImfTemp.imag();
00422                                 }
00423                         } // ends jky <jkx
00424 
00425 
00426                 } // ends jky
00427         } // ends jkx
00428         outCopy->update();
00429         outCopy->set_complex(true);
00430         if(outCopy->get_ysize()==1 && outCopy->get_zsize()==1) outCopy->set_complex_x(true);
00431         outCopy->set_ri(true);
00432         outCopy->set_FH(false);
00433         outCopy->set_fftodd(true);
00434         outCopy->set_shuffled(true);
00435         return outCopy;
00436         } else {
00437                 LOGERR("can't be an FH image not this size");
00438                 throw ImageFormatException("something strange about this image: not a FH");
00439 
00440         }
00441 }  // ends FH2F

EMData * EMData::FH2Real ( int  Size,
float  OverSamplekB,
int  IntensityFlag = 0 
)

returns the real version of the image from the FH version.

The current image is not changed. The result is in real format.

Parameters:
Size is the size of the image to be returned
OverSamplekB is a parameter controlling the fineness of the Fourier sampling
IntensityFlag =0 is the usual; =1 means that the input was an intensity
Returns:
the real version of the data

Definition at line 444 of file emdata_sparx.cpp.

References do_ift(), FH2F(), and process_inplace().

00445 {
00446         EMData* FFT= FH2F(Size,OverSamplekB,0);
00447         FFT->process_inplace("xform.fourierorigin.tocorner");
00448         EMData* eguess= FFT ->do_ift();
00449         return eguess;
00450 }  // ends FH2F

EMData * EMData::filter_by_image ( EMData image,
bool  RetReal = true 
)

Definition at line 5847 of file emdata_sparx.cpp.

References cmplx(), copy(), depad(), do_fft_inplace(), do_ift_inplace(), fint, get_data(), get_xsize(), get_ysize(), get_zsize(), is_complex(), is_fftodd(), norm_pad(), nx, ny, nz, set_array_offsets(), set_attr(), set_fftodd(), set_fftpad(), set_ri(), and update().

05847                                                            {
05848 
05849 
05850         bool   complex_input = this->is_complex();
05851         nx  = this->get_xsize();
05852         ny  = this->get_ysize();
05853         nz  = this->get_zsize();
05854         int nox;
05855         if (complex_input) nox = (nx - 2 + this->is_fftodd()); else nox = nx;
05856 
05857         int lsd2 = (nox + 2 - nox%2) / 2; // Extended x-dimension of the complex image
05858 
05859         EMData* fp = NULL; // output image
05860         if(complex_input) {
05861                 // fimage must remain pristine
05862                 fp = this->copy();
05863         } else {
05864                 fp = this->norm_pad( false, 1);
05865                 fp->do_fft_inplace();
05866         }
05867         fp->set_array_offsets(1,1,1);
05868         int nx2 = nox/2;
05869         int ny2 = ny/2;
05870         int nz2 = nz/2;
05871         float *fint = image->get_data();
05872         for ( int iz = 1; iz <= nz; iz++) {
05873                 int jz=nz2-iz+1; if(jz<0) jz += nz;
05874                 for ( int iy = 1; iy <= ny; iy++) {
05875                         int jy=ny2-iy+1; if(jy<0) jy += ny;
05876                         for ( int ix = 1; ix <= lsd2; ix++) {
05877                                 int jx = nx2-ix+1;
05878                                 fp->cmplx(ix,iy,iz) *= fint(jx,jy,jz);
05879                         }
05880                 }
05881         }
05882 
05883         fp->set_ri(1);
05884         fp->set_fftpad(true);
05885         fp->set_attr("npad", 1);
05886         if (nx%2 == 1) fp->set_fftodd(true);
05887         else fp->set_fftodd(false);
05888         if(RetReal) {
05889                 fp->do_ift_inplace();
05890                 fp->depad();
05891         }
05892         fp->set_array_offsets(0,0,0);
05893         fp->update();
05894 
05895         return fp;
05896 }

float EMData::find_3d_threshold ( float  mass,
float  pixel_size 
)

Definition at line 4643 of file emdata_sparx.cpp.

References abs, avagadro, C, density_protein, get_attr(), get_ndim(), ImageDimensionException, max, min, nx, ny, nz, R, and rdata.

04644 {
04645         /* Exception Handle */
04646         if(get_ndim()!=3)
04647                 throw ImageDimensionException("The image should be 3D");
04648         /* ===============================================================*/
04649 
04650         /* Calculation of the volume of the voxels */
04651         float density_1_mole, vol_1_mole, vol_angstrom;
04652         int  vol_voxels;
04653         density_1_mole = static_cast<float>( (mass*1000.0f)/avagadro );
04654         vol_1_mole =  static_cast<float>( density_1_mole/density_protein );
04655         vol_angstrom =  static_cast<float>( vol_1_mole*(double)pow((double)pow(10.0,8),3) );
04656         vol_voxels = static_cast<int> (vol_angstrom/(double)pow(pixel_size,3));
04657         /* ===============================================================*/
04658 
04659 
04660         float thr1 = get_attr("maximum");
04661         float thr3 = get_attr("minimum");
04662         float thr2 = (thr1-thr3)/2 + thr3;
04663         int size = nx*ny*nz;
04664         float x0 = thr1,x3 = thr3,x1,x2,THR=0;
04665 
04666         #ifdef _WIN32
04667                 int ILE = _MIN(nx*ny*nx,_MAX(1,vol_voxels));
04668         #else
04669                 int ILE = std::min(nx*ny*nx,std::max(1,vol_voxels));
04670         #endif  //_WIN32
04671 
04672         if (abs(thr3-thr2)>abs(thr2-thr1)) {
04673                 x1=thr2;
04674                 x2=thr2+C*(thr3-thr2);
04675         } else {
04676                 x2=thr2;
04677                 x1=thr2-C*(thr2-thr1);
04678         }
04679 
04680         int cnt1=0,cnt2=0;
04681         for (int i=0;i<size;i++) {
04682                 if(rdata[i]>=x1)  cnt1++;
04683                 if(rdata[i]>=x2)  cnt2++;
04684         }
04685         float LF1 = static_cast<float>( cnt1 - ILE );
04686         float F1 = LF1*LF1;
04687         float LF2 = static_cast<float>( cnt2 - ILE );
04688         float F2 = LF2*LF2;
04689 
04690         while ((LF1 != 0 || LF2 != 0) && (fabs(LF1-LF2) >= 1.f) && (abs(x1-x2) > (double)pow(10.0,-5) && abs(x1-x3) > (double)pow(10.0,-5) && abs(x2-x3) > (double)pow(10.0,-5)))
04691         {
04692                 if(F2 < F1) {
04693                         x0=x1;
04694                         x1=x2;
04695                         x2 = R*x1 + C*x3;
04696                         F1=F2;
04697                         int cnt=0;
04698                         for(int i=0;i<size;i++)
04699                                 if(rdata[i]>=x2)
04700                                         cnt++;
04701                         LF2 = static_cast<float>( cnt - ILE );
04702                         F2 = LF2*LF2;
04703                 } else {
04704                         x3=x2;
04705                         x2=x1;
04706                         x1=R*x2 + C*x0;
04707                         F2=F1;
04708                         int cnt=0;
04709                         for(int i=0;i<size;i++)
04710                                 if(rdata[i]>=x1)
04711                                         cnt++;
04712                         LF1 = static_cast<float>( cnt - ILE );
04713                         F1 = LF1*LF1;
04714                 }
04715         }
04716 
04717         if(F1 < F2) {
04718                 ILE = static_cast<int> (LF1 + ILE);
04719                 THR = x1;
04720         } else {
04721                 ILE = static_cast<int> (LF2 + ILE);
04722                 THR = x2;
04723         }
04724         return THR;
04725 
04726 }

EMData * EMData::Four_ds ( int  nxni,
int  nyni = 0,
int  nzni = 0,
bool  RetReal = true 
)

Definition at line 5715 of file emdata_sparx.cpp.

References copy(), depad(), do_ift_inplace(), fint, fout, get_data(), nx, ny, nz, set_complex(), set_fftodd(), set_ri(), set_size(), to_zero(), and update().

05715                                                                  {
05716 
05717         int nyn, nzn, lsd, lsdn, inx, iny, inz;
05718         int i, j;
05719 
05720         if(ny > 1) {
05721                 nyn = nyni;
05722                 if(nz > 1) {
05723                         nzn = nzni;
05724                 }  else {
05725                         nzn = 1;
05726                 }
05727         } else {
05728                 nyn = 1; nzn = 1;
05729         }
05730         lsd = nx-2 + 2 - nx%2;
05731         lsdn = nxn + 2 - nxn%2;
05732 //  do out of place ft
05733         EMData *temp_ft = this->copy();
05734         EMData *ret = this->copy();
05735         ret->set_size(lsdn, nyn, nzn);
05736         ret->to_zero();
05737         float *fout = ret->get_data();
05738         float *fint = temp_ft->get_data();
05739 //  TO KEEP EXACT VALUES ON THE ORIGINAL GRID ONE SHOULD USE
05740 //  SQ2     = 2.0. HOWEVER, TOTAL ENERGY WILL NOT BE CONSERVED
05741 //      float  sq2 = 1.0f/std::sqrt(2.0f);
05742         float  anorm = (float) nxn* (float) nyn* (float) nzn/(float) nx/ (float) ny/ (float) nz;
05743         for (i = 0; i < lsd*ny*nz; i++)  fint[i] *= anorm;
05744         inx = nxn-(nx-2); iny = nyn - ny; inz = nzn - nz;
05745         for (j=1; j<=nyn; j++)
05746                 for (i=1; i<=lsdn; i++)
05747                         fout(i,j,1)=fint((i-1)/2*4+2-i%2,j*2-1,1);
05748         ret->set_complex(true);
05749         ret->set_ri(1);
05750         //ret->set_fftpad(true);
05751         //ret->set_attr("npad", 1);
05752         if (nxn%2 == 1) {ret->set_fftodd(true);} else {ret->set_fftodd(false);}
05753         if(RetReal) {
05754                 ret->do_ift_inplace();
05755                 ret->depad();
05756         }
05757         ret->update();
05758 
05759         delete temp_ft;
05760         temp_ft = 0;
05761         return ret;
05762 }

EMData * EMData::Four_shuf_ds_cen_us ( int  nxni,
int  nyni = 0,
int  nzni = 0,
bool  RetReal = true 
)

Definition at line 5764 of file emdata_sparx.cpp.

References copy(), depad(), do_ift_inplace(), fint, fout, get_data(), nx, ny, nz, set_complex(), set_fftodd(), set_ri(), set_size(), sqrt(), to_zero(), and update().

05764                                                                         {
05765 
05766         int nyn, nzn, lsd, lsdn, inx, iny, inz;
05767         int i, j;
05768 
05769         nyn = nyni;
05770         nzn = 1;
05771         lsd = nx;
05772         lsdn = nxn + 2 - nxn%2;
05773 
05774         EMData *temp_ft = this->copy();
05775         EMData *ret = this->copy();
05776         ret->set_size(lsdn, nyn, nzn);
05777         ret->to_zero();
05778         float *fout = ret->get_data();
05779         float *fint = temp_ft->get_data();
05780 //  TO KEEP EXACT VALUES ON THE ORIGINAL GRID ONE SHOULD USE
05781 //  SQ2     = 2.0. HOWEVER, TOTAL ENERGY WILL NOT BE CONSERVED
05782         float  sq2 = 1.0f/std::sqrt(2.0f);
05783 
05784         for (i = 0; i < lsd*ny*nz; i++)  fint[i] *= 4;
05785 
05786         inx = nxn-(nx-2); iny = nyn - ny; inz = nzn - nz;
05787         for (j=1; j<=ny/4; j++)
05788                 for (i=1; i<=(nx-2)/2+2; i++) {
05789                         int g = (i-1)/2+1;
05790                         if ((g+j)%2 == 0) {
05791                                 fout(i,j,1)=fint(g*4-2-i%2,j*2-1+ny/2,1);
05792                         } else {
05793                                 fout(i,j,1)=-fint(g*4-2-i%2,j*2-1+ny/2,1);
05794                         }
05795                 }
05796 
05797         for (j=ny/4+1; j<=ny/4+1; j++)
05798                 for (i=1; i<=(nx-2)/2+2; i++) {
05799                         int g = (i-1)/2+1;
05800                         if ((g+j)%2 == 0) {
05801                                 fout(i,j,1)=fint(g*4-2-i%2,j*2-1-ny/2,1);
05802                         } else {
05803                                 fout(i,j,1)=-fint(g*4-2-i%2,j*2-1-ny/2,1);
05804                         }
05805                 }
05806 
05807         for (j=ny/4+2; j<=ny/2; j++)
05808                 for (i=1; i<=(nx-2)/2+2; i++) {
05809                         int g = (i-1)/2+1;
05810                         if ((g+j)%2 == 0) {
05811                                 fout(i,j+ny/2,1)=fint(g*4-2-i%2,j*2-1-ny/2,1);
05812                         } else {
05813                                 fout(i,j+ny/2,1)=-fint(g*4-2-i%2,j*2-1-ny/2,1);
05814                         }
05815                 }
05816 
05817         if (nx%2 == 0) {
05818                 for (j=1; j<=nyn; j++) {
05819                         fout((nx-2)/2+1,j,1) *= sq2;
05820                         fout((nx-2)/2+2,j,1) *= sq2;
05821                 }
05822                 for (i=1; i<=lsd/2+1; i++) {
05823                         fout(i,ny/4+1+ny/2,1) = sq2*fout(i,ny/4+1,1);
05824                         fout(i,ny/4+1,1) *= sq2;
05825                 }
05826         }
05827 
05828         ret->set_complex(true);
05829         ret->set_ri(1);
05830 
05831         if (nxn%2 == 1) {ret->set_fftodd(true);} else {ret->set_fftodd(false);}
05832         if(RetReal) {
05833                 ret->do_ift_inplace();
05834                 ret->depad();
05835         }
05836         ret->update();
05837 
05838         delete temp_ft;
05839         temp_ft = 0;
05840         return ret;
05841 }

EMData * EMData::fouriergridrot2d ( float  ang,
float  scale,
Util::KaiserBessel kb 
)

Definition at line 3327 of file emdata_sparx.cpp.

References cmplx(), copy_head(), DGR_TO_RAD, extractpoint2(), fft_shuffle(), get_ndim(), ImageDimensionException, ImageFormatException, is_complex(), is_fftodd(), is_shuffled(), nx, ny, set_array_offsets(), and update().

03327                                                                              {
03328         if (2 != get_ndim())
03329                 throw ImageDimensionException("fouriergridrot2d needs a 2-D image.");
03330         if (!is_complex())
03331                 throw ImageFormatException("fouriergridrot2d requires a fourier image");
03332         int nxreal = nx - 2 + int(is_fftodd());
03333         if (nxreal != ny)
03334                 throw ImageDimensionException("fouriergridrot2d requires ny == nx(real)");
03335         if (0 != nxreal%2)
03336                 throw ImageDimensionException("fouriergridrot2d needs an even image.");
03337         if (scale == 0.0f) scale = 1.0f;
03338         int nxhalf = nxreal/2;
03339         int nyhalf = ny/2;
03340         float cir = (nxhalf-1)*(nxhalf-1);
03341 
03342         if (!is_shuffled()) fft_shuffle();
03343 
03344         EMData* result = copy_head();
03345         set_array_offsets(0,-nyhalf);
03346         result->set_array_offsets(0,-nyhalf);
03347 
03348         
03349         
03350         ang = ang*(float)DGR_TO_RAD;
03351         float cang = cos(ang);
03352         float sang = sin(ang);
03353         for (int iy = -nyhalf; iy < nyhalf; iy++) {
03354                 float ycang = iy*cang;
03355                 float ysang = iy*sang;
03356                 for (int ix = 0; ix <= nxhalf; ix++) {
03357                         float nuxold = (ix*cang - ysang)*scale;
03358                         float nuyold = (ix*sang + ycang)*scale;
03359                         if (nuxold*nuxold+nuyold*nuyold<cir) result->cmplx(ix,iy) = Util::extractpoint2(nx, ny, nuxold, nuyold, this, kb);
03360                         //result->cmplx(ix,iy) = extractpoint(nuxold, nuyold, kb);
03361                 }
03362         }
03363         result->set_array_offsets();
03364         result->fft_shuffle(); // reset to an unshuffled result
03365         result->update();
03366         set_array_offsets();
03367         fft_shuffle(); // reset to an unshuffled complex image
03368         return result;
03369 }

EMData * EMData::fouriergridrot_shift2d ( float  ang,
float  sx,
float  sy,
Util::KaiserBessel kb 
)

Definition at line 3371 of file emdata_sparx.cpp.

References cmplx(), copy_head(), DGR_TO_RAD, extractpoint2(), fft_shuffle(), get_ndim(), ImageDimensionException, ImageFormatException, is_complex(), is_fftodd(), is_shuffled(), nx, ny, set_array_offsets(), and update().

03371                                                                                           {
03372         if (2 != get_ndim())
03373                 throw ImageDimensionException("fouriergridrot_shift2d needs a 2-D image.");
03374         if (!is_complex())
03375                 throw ImageFormatException("fouriergridrot_shift2d requires a fourier image");
03376         int nxreal = nx - 2 + int(is_fftodd());
03377         if (nxreal != ny)
03378                 throw ImageDimensionException("fouriergridrot_shift2d requires ny == nx(real)");
03379         if (0 != nxreal%2)
03380                 throw ImageDimensionException("fouriergridrot_shift2d needs an even image.");
03381         int nxhalf = nxreal/2;
03382         int nyhalf = ny/2;
03383 
03384         if (!is_shuffled()) fft_shuffle();
03385 
03386         EMData* result = copy_head();
03387         set_array_offsets(0, -nyhalf);
03388         result->set_array_offsets(0, -nyhalf);
03389 
03390         ang = ang*(float)DGR_TO_RAD;
03391         float cang = cos(ang);
03392         float sang = sin(ang);
03393         float temp = -2.0f*M_PI/nxreal;
03394         for (int iy = -nyhalf; iy < nyhalf; iy++) {
03395                 float ycang = iy*cang;
03396                 float ysang = iy*sang;
03397                 for (int ix = 0; ix <= nxhalf; ix++) {
03398                         float nuxold = ix*cang - ysang;
03399                         float nuyold = ix*sang + ycang;
03400                         result->cmplx(ix,iy) = Util::extractpoint2(nx, ny, nuxold, nuyold, this, kb);
03401                         //result->cmplx(ix,iy) = extractpoint(nuxold, nuyold, kb);
03402                         float phase_ang = temp*(sx*ix+sy*iy);
03403                         result->cmplx(ix,iy) *= complex<float>(cos(phase_ang), sin(phase_ang));
03404                 }
03405         }
03406         result->set_array_offsets();
03407         result->fft_shuffle(); // reset to an unshuffled result
03408         result->update();
03409         set_array_offsets();
03410         fft_shuffle(); // reset to an unshuffled complex image
03411         return result;
03412 }

EMData * EMData::FourInterpol ( int  nxni,
int  nyni = 0,
int  nzni = 0,
bool  RetReal = true 
)

Definition at line 5378 of file emdata_sparx.cpp.

References copy(), depad(), do_fft(), do_ift_inplace(), fint, fout, get_data(), ImageDimensionException, ImageFormatException, is_complex(), nx, ny, nz, set_attr(), set_complex(), set_fftodd(), set_fftpad(), set_ri(), set_size(), sqrt(), to_zero(), and update().

05378                                                                       {
05379 
05380         int nyn, nzn, lsd, lsdn, inx, iny, inz;
05381         int i, j, k;
05382         if (is_complex())
05383                 throw ImageFormatException("Input image has to be real");
05384 
05385         if(ny > 1) {
05386                 nyn = nyni;
05387                 if(nz > 1) {
05388                         nzn = nzni;
05389                 }  else {
05390                         nzn = 1;
05391                 }
05392         } else {
05393                 nyn = 1; nzn = 1;
05394         }
05395         if(nxn<nx || nyn<ny || nzn<nz)  throw ImageDimensionException("Cannot reduce the image size");
05396         lsd = nx + 2 - nx%2;
05397         lsdn = nxn + 2 - nxn%2;
05398 //  do out of place ft
05399         EMData *temp_ft = do_fft();
05400         EMData *ret = this->copy();
05401         ret->set_size(lsdn, nyn, nzn);
05402         ret->to_zero();
05403         float *fout = ret->get_data();
05404         float *fint = temp_ft->get_data();
05405 //  TO KEEP EXACT VALUES ON THE ORIGINAL GRID ONE SHOULD USE
05406 //  SQ2     = 2.0. HOWEVER, TOTAL ENERGY WILL NOT BE CONSERVED
05407         float  sq2 = 1.0f/std::sqrt(2.0f);
05408         float  anorm = (float) nxn* (float) nyn* (float) nzn/(float) nx/ (float) ny/ (float) nz;
05409         for (i = 0; i < lsd*ny*nz; i++)  fint[i] *= anorm;
05410         inx = nxn-nx; iny = nyn - ny; inz = nzn - nz;
05411         for (k=1; k<=nz/2+1; k++) for (j=1; j<=ny/2+1; j++) for (i=1; i<=lsd; i++) fout(i,j,k)=fint(i,j,k);
05412         if(nyn>1) {
05413         //cout << "  " <<nxn<<"  " <<nyn<<" A " <<nzn<<endl;
05414                 for (k=1; k<=nz/2+1; k++) for (j=ny/2+2+iny; j<=nyn; j++) for (i=1; i<=lsd; i++) fout(i,j,k)=fint(i,j-iny,k);
05415                 if(nzn>1) {
05416                         for (k=nz/2+2+inz; k<=nzn; k++) {
05417                                 for (j=1; j<=ny/2+1; j++) {
05418                                         for (i=1; i<=lsd; i++) {
05419                                                 fout(i,j,k)=fint(i,j,k-inz);
05420                                         }
05421                                 }
05422                                 for (j=ny/2+2+iny; j<=nyn; j++) {
05423                                         for (i=1; i<=lsd; i++) {
05424                                                 fout(i,j,k)=fint(i,j-iny,k-inz);
05425                                         }
05426                                 }
05427                         }
05428                 }
05429         }
05430 //       WEIGHTING FACTOR USED FOR EVEN NSAM. REQUIRED SINCE ADDING ZERO FOR
05431 //       INTERPOLATION WILL INTRODUCE A COMPLEX CONJUGATE FOR NSAM/2'TH
05432 //       ELEMENT.
05433         if(nx%2 == 0 && inx !=0) {
05434                 for (k=1; k<=nzn; k++) {
05435                         for (j=1; j<=nyn; j++) {
05436                                 fout(nx+1,j,k) *= sq2;
05437                                 fout(nx+2,j,k) *= sq2;
05438                         }
05439                 }
05440                 if(nyn>1) {
05441                         for (k=1; k<=nzn; k++) {
05442                           for (i=1; i<=lsd; i++) {
05443                             fout(i,ny/2+1+iny,k) = sq2*fout(i,ny/2+1,k);
05444                             fout(i,ny/2+1,k) *= sq2;
05445                           }
05446                         }
05447                         if(nzn>1) {
05448                                 for (j=1; j<=nyn; j++) {
05449                                         for (i=1; i<=lsd; i++) {
05450                                                 fout(i,j,nz/2+1+inz) = sq2*fout(i,j,nz/2+1);
05451                                                 fout(i,j,nz/2+1) *= sq2;
05452                                         }
05453                                 }
05454                         }
05455                 }
05456         }
05457         ret->set_complex(true);
05458 /*
05459 //  For padding from odd to even dimension additional shift by 1 pixel is necessary.
05460         float  xshift = 0.f, yshift = 0.f, zshift = 0.f;
05461         int nyn2, nzn2;
05462         if(nxn > nx && nx%2 == 1)  xshift = 1.0f;
05463         if(ny > 1) {
05464                 if(nyn > ny && ny%2 == 1)  yshift = 1.0f;
05465                 nyn2 = nyn/2;
05466                 if(nz > 1) {
05467                         if(nzn > nz && nz%2 == 1)  zshift = 1.0f;
05468                         nzn2 = nzn/2;
05469                 }  else {
05470                         nzn2 = 0;
05471                 }
05472         } else {
05473                 nyn2 = 0; nzn2 = 0;
05474         }
05475         if(xshift == 1.0 || yshift == 1.0 || zshift == 1.0)  {
05476                 ret->set_array_offsets(1,1,1);
05477                 int  lsdn2 = lsd/2;
05478                 for (int iz = 1; iz <= nzn; iz++) {
05479                         int jz=iz-1; if(jz>nzn2) jz=jz-nzn;
05480                         for (int iy = 1; iy <= nyn; iy++) {
05481                                 int jy=iy-1; if(jy>nyn2) jy=jy-nyn;
05482                                 for (int ix = 1; ix <= lsdn2; ix++) {
05483                                         int jx=ix-1;
05484                                         ret->cmplx(ix,iy,iz) *=
05485                                         exp(-float(twopi)*iimag*(xshift*jx/nxn + yshift*jy/nyn+ zshift*jz/nzn));
05486                                 }
05487                         }
05488                 }
05489                 ret->set_array_offsets(0,0,0);
05490         }*/
05491         ret->set_ri(1);
05492         ret->set_fftpad(true);
05493         ret->set_attr("npad", 1);
05494         if (nxn%2 == 1) {ret->set_fftodd(true);} else {ret->set_fftodd(false);}
05495         if(RetReal) {
05496                 ret->do_ift_inplace();
05497                 ret->depad();
05498         }
05499         ret->update();
05500 
05501         /*Dict d1 = temp_ft->get_attr_dict();
05502         Dict d2 = ret->get_attr_dict();
05503         printf("-----------------Attribute Dict for temp_ft--------------\n");
05504         EMUtil::dump_dict(d1);
05505         printf("-----------------Attribute Dict for ret--------------\n");
05506         EMUtil::dump_dict(d2);*/
05507         delete temp_ft;
05508         temp_ft = 0;
05509         return ret;
05510 }

EMData * EMData::FourTruncate ( int  nxni,
int  nyni = 0,
int  nzni = 0,
bool  RetReal = true 
)

Truncate Fourier transform of an image, it will reduce its size.

(It is a form of decimation).

Parameters:
[in] nxni new x size (has to be larger/equal than the original x size)
[in] nyni new y size (has to be larger/equal than the original y size)
[in] nzni new z size (has to be larger/equal than the original z size)
RetReal 
Returns:
New truncated up image.

Definition at line 5512 of file emdata_sparx.cpp.

References copy_head(), depad(), do_fft(), do_ift_inplace(), fint, fout, get_data(), ImageDimensionException, is_complex(), nx, ny, nz, set_attr(), set_complex(), set_fftodd(), set_fftpad(), set_ri(), set_size(), and update().

05512                                                                       {
05513 
05514         int nyn, nzn, lsd, lsdn, inx, iny, inz;
05515         int i, j, k;
05516         float  *fint;
05517         EMData *temp_ft = NULL;
05518         //if (is_complex())
05519         //      throw ImageFormatException("Input image has to be real");
05520 
05521         if(ny > 1) {
05522                 nyn = nyni;
05523                 if(nz > 1) {
05524                         nzn = nzni;
05525                 }  else {
05526                         nzn = 1;
05527                 }
05528         } else {
05529                 nyn = 1; nzn = 1;
05530         }
05531         if (is_complex()) {
05532                 nx = nx - 2 + nx%2;
05533                 fint = get_data();
05534         } else {
05535                 //  do out of place ft
05536                 temp_ft = do_fft();
05537                 fint = temp_ft->get_data();
05538         }
05539         if(nxn>nx || nyn>ny || nzn>nz)  throw ImageDimensionException("Cannot increase the image size");
05540         lsd = nx + 2 - nx%2;
05541         lsdn = nxn + 2 - nxn%2;
05542         EMData *ret = this->copy_head();
05543         ret->set_size(lsdn, nyn, nzn);
05544         float *fout = ret->get_data();
05545 //  TO KEEP EXACT VALUES ON THE ORIGINAL GRID ONE SHOULD USE
05546 //  SQ2     = 2.0. HOWEVER, TOTAL ENERGY WILL NOT BE CONSERVED
05547         //float  sq2 = std::sqrt(2.0f);
05548         float  anorm = (float) nxn* (float) nyn* (float) nzn/(float) nx/ (float) ny/ (float) nz;
05549         for (i = 0; i < lsd*ny*nz; i++)  fint[i] *= anorm;
05550         inx = nx - nxn;  iny = ny - nyn;  inz = nz - nzn;
05551         for (k=1; k<=nzn/2+1; k++) for (j=1; j<=nyn/2+1; j++) for (i=1; i<=lsdn; i++) fout(i,j,k)=fint(i,j,k);
05552         if(nyn>1) {
05553                 for (k=1; k<=nzn/2+1; k++) for (j=nyn/2+2; j<=nyn; j++) for (i=1; i<=lsdn; i++) fout(i,j,k)=fint(i,j+iny,k);
05554                 if(nzn>1) {
05555                         for (k=nzn/2+2; k<=nzn; k++) {
05556                                 for (j=1; j<=nyn/2+1; j++) {
05557                                         for (i=1; i<=lsdn; i++) {
05558                                                 fout(i,j,k)=fint(i,j,k+inz);
05559                                         }
05560                                 }
05561                                 for (j=nyn/2+2; j<=nyn; j++) {
05562                                         for (i=1; i<=lsdn; i++) {
05563                                                 fout(i,j,k)=fint(i,j+iny,k+inz);
05564                                         }
05565                                 }
05566                         }
05567                 }
05568         }
05569 //       WEIGHTING FACTOR USED FOR EVEN NSAM. REQUIRED SINCE ADDING ZERO FOR
05570 //       INTERPOLATION WILL INTRODUCE A COMPLEX CONJUGATE FOR NSAM/2'TH
05571 //       ELEMENT.
05572         /*
05573         if(nxn%2 == 0 && inx !=0) {
05574                 for (k=1; k<=nzn; k++) {
05575                         for (j=1; j<=nyn; j++) {
05576                                 fout(nxn+1,j,k) *= sq2;
05577                                 fout(nxn+2,j,k) *= sq2;
05578                         }
05579                 }
05580                 if(nyn>1) {
05581                         for (k=1; k<=nzn; k++) {
05582                           for (i=1; i<=lsdn; i++) {
05583                             fout(i,nyn/2+1+iny,k) = sq2*fout(i,nyn/2+1,k);
05584                             fout(i,nyn/2+1,k) *= sq2;
05585                           }
05586                         }
05587                         if(nzn>1) {
05588                                 for (j=1; j<=nyn; j++) {
05589                                         for (i=1; i<=lsdn; i++) {
05590                                                 fout(i,j,nzn/2+1+inz) = sq2*fout(i,j,nzn/2+1);
05591                                                 fout(i,j,nzn/2+1) *= sq2;
05592                                         }
05593                                 }
05594                         }
05595                 }
05596         }*/
05597         ret->set_complex(true);
05598         ret->set_ri(1);
05599         ret->set_fftpad(true);
05600         ret->set_attr("npad", 1);
05601         if (nxn%2 == 1) {ret->set_fftodd(true);} else {ret->set_fftodd(false);}
05602         if(RetReal) {
05603                 ret->do_ift_inplace();
05604                 ret->depad();
05605         }
05606         ret->update();
05607 
05608         /*Dict d1 = temp_ft->get_attr_dict();
05609         Dict d2 = ret->get_attr_dict();
05610         printf("-----------------Attribute Dict for temp_ft--------------\n");
05611         EMUtil::dump_dict(d1);
05612         printf("-----------------Attribute Dict for ret--------------\n");
05613         EMUtil::dump_dict(d2);*/
05614         if (!is_complex()) {
05615                 delete temp_ft;
05616                 temp_ft = 0;
05617         }
05618         return ret;
05619 }

void EMData::free_memory (  ) 

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

Definition at line 54 of file emdata_core.cpp.

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

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

00055 {
00056         ENTERFUNC;
00057         if (rdata) {
00058                 EMUtil::em_free(rdata);
00059                 rdata = 0;
00060         }
00061 
00062         if (supp) {
00063                 EMUtil::em_free(supp);
00064                 supp = 0;
00065         }
00066 
00067         if (rot_fp != 0)
00068         {
00069                 delete rot_fp;
00070                 rot_fp = 0;
00071         }
00072         /*
00073         nx = 0;
00074         ny = 0;
00075         nz = 0;
00076         nxy = 0;
00077          */
00078 
00079         EXITFUNC;
00080 }

MCArray2D EMData::get_2dcview ( int  x0,
int  y0 
) const

Get complex image raw pixel data in a 2D multi-array format.

The data coordinates is translated by (x0,y0) such that array[y0][x0] points to the pixel at the origin location. the data coordiates translated by (x0,y0). The array shares the memory space with the image data.

It should be used on 2D image only.

Parameters:
x0 X-axis translation amount.
y0 Y-axis translation amount.
Returns:
2D multi-array format of the raw data.

Definition at line 890 of file emdata_metadata.cpp.

References get_data(), get_ndim(), ImageDimensionException, nx, and ny.

00891 {
00892         const int ndims = 2;
00893         if (get_ndim() != ndims) {
00894                 throw ImageDimensionException("2D only");
00895         }
00896         boost::array<std::size_t,ndims> dims = {{nx/2, ny}};
00897         std::complex<float>* cdata = reinterpret_cast<std::complex<float>*>(get_data());
00898         MCArray2D marray(cdata, dims, boost::fortran_storage_order());
00899         boost::array<std::size_t,ndims> bases={{x0, y0}};
00900         marray.reindex(bases);
00901         return marray;
00902 }

MCArray2D EMData::get_2dcview (  )  const

Get complex image raw pixel data in a 2D multi-array format.

The array shares the memory space with the image data.

It should be used on 2D image only.

Returns:
2D multi-array format of the raw data.

Definition at line 831 of file emdata_metadata.cpp.

References get_data(), get_ndim(), ImageDimensionException, nx, and ny.

00832 {
00833         const int ndims = 2;
00834         if (get_ndim() != ndims) {
00835                 throw ImageDimensionException("2D only");
00836         }
00837         boost::array<std::size_t,ndims> dims = {{nx/2, ny}};
00838         std::complex<float>* cdata = reinterpret_cast<std::complex<float>*>(get_data());
00839         MCArray2D marray(cdata, dims, boost::fortran_storage_order());
00840         return marray;
00841 }

MArray2D EMData::get_2dview ( int  x0,
int  y0 
) const

Get image raw pixel data in a 2D multi-array format.

The data coordinates is translated by (x0,y0) such that array[y0][x0] points to the pixel at the origin location. the data coordiates translated by (x0,y0). The array shares the memory space with the image data.

It should be used on 2D image only.

Parameters:
x0 X-axis translation amount.
y0 Y-axis translation amount.
Returns:
2D multi-array format of the raw data.

Definition at line 865 of file emdata_metadata.cpp.

References get_data(), get_ndim(), ImageDimensionException, nx, and ny.

00866 {
00867         const int ndims = 2;
00868         if (get_ndim() != ndims) {
00869                 throw ImageDimensionException("2D only");
00870         }
00871         boost::array<std::size_t,ndims> dims = {{nx, ny}};
00872         MArray2D marray(get_data(), dims, boost::fortran_storage_order());
00873         boost::array<std::size_t,ndims> bases={{x0, y0}};
00874         marray.reindex(bases);
00875         return marray;
00876 }

MArray2D EMData::get_2dview (  )  const

Get image raw pixel data in a 2D multi-array format.

The array shares the memory space with the image data. Notice: the subscription order is d[y][x] in Python, it's d[x][y] in C++

It should be used on 2D image only.

Returns:
2D multi-array format of the raw data.

Definition at line 810 of file emdata_metadata.cpp.

References get_data(), get_ndim(), ImageDimensionException, nx, and ny.

00811 {
00812         const int ndims = 2;
00813         if (get_ndim() != ndims) {
00814                 throw ImageDimensionException("2D only");
00815         }
00816         boost::array<std::size_t,ndims> dims = {{nx, ny}};
00817         MArray2D marray(get_data(), dims, boost::fortran_storage_order());
00818         return marray;
00819 }

MCArray3D EMData::get_3dcview ( int  x0,
int  y0,
int  z0 
) const

Get complex image raw pixel data in a 3D multi-array format.

The data coordinates is translated by (x0,y0,z0) such that array[z0][y0][x0] points to the pixel at the origin location. the data coordiates translated by (x0,y0,z0). The array shares the memory space with the image data.

It should be used on 3D image only.

Parameters:
x0 X-axis translation amount.
y0 Y-axis translation amount.
z0 Z-axis translation amount.
Returns:
3D multi-array format of the raw data.

Definition at line 905 of file emdata_metadata.cpp.

References get_data(), nx, ny, and nz.

00906 {
00907         const int ndims = 3;
00908         boost::array<std::size_t,ndims> dims = {{nx/2, ny, nz}};
00909         std::complex<float>* cdata = reinterpret_cast<std::complex<float>*>(get_data());
00910         MCArray3D marray(cdata, dims, boost::fortran_storage_order());
00911         boost::array<std::size_t,ndims> bases={{x0, y0, z0}};
00912         marray.reindex(bases);
00913         return marray;
00914 }

MCArray3D EMData::get_3dcview (  )  const

Get complex image raw pixel data in a 3D multi-array format.

The array shares the memory space with the image data.

It should be used on 3D image only.

Returns:
3D multi-array format of the raw data.

Definition at line 844 of file emdata_metadata.cpp.

References get_data(), nx, ny, and nz.

00845 {
00846         const int ndims = 3;
00847         boost::array<std::size_t,ndims> dims = {{nx/2, ny, nz}};
00848         std::complex<float>* cdata = reinterpret_cast<std::complex<float>*>(get_data());
00849         MCArray3D marray(cdata, dims, boost::fortran_storage_order());
00850         return marray;
00851 }

MCArray3D * EMData::get_3dcviewptr (  )  const

Get pointer to a complex image raw pixel data in a 3D multi-array format.

The array shares the memory space with the image data.

It should be used on 3D image only.

Returns:
Pointer to a 3D multi-array format of the raw data.

Definition at line 854 of file emdata_metadata.cpp.

References get_data(), nx, ny, and nz.

00855 {
00856         const int ndims = 3;
00857         boost::array<std::size_t,ndims> dims = {{nx/2, ny, nz}};
00858         std::complex<float>* cdata = reinterpret_cast<std::complex<float>*>(get_data());
00859         MCArray3D* marray = new MCArray3D(cdata, dims,
00860                                                                           boost::fortran_storage_order());
00861         return marray;
00862 }

MArray3D EMData::get_3dview ( int  x0,
int  y0,
int  z0 
) const

Get image raw pixel data in a 3D multi-array format.

The data coordinates is translated by (x0,y0,z0) such that array[z0][y0][x0] points to the pixel at the origin location. the data coordiates translated by (x0,y0,z0). The array shares the memory space with the image data.

It should be used on 3D image only.

Parameters:
x0 X-axis translation amount.
y0 Y-axis translation amount.
z0 Z-axis translation amount.
Returns:
3D multi-array format of the raw data.

Definition at line 879 of file emdata_metadata.cpp.

References get_data(), nx, ny, and nz.

00880 {
00881         const int ndims = 3;
00882         boost::array<std::size_t,ndims> dims = {{nx, ny, nz}};
00883         MArray3D marray(get_data(), dims, boost::fortran_storage_order());
00884         boost::array<std::size_t,ndims> bases={{x0, y0, z0}};
00885         marray.reindex(bases);
00886         return marray;
00887 }

MArray3D EMData::get_3dview (  )  const

Get image raw pixel data in a 3D multi-array format.

The array shares the memory space with the image data. Notice: the subscription order is d[z][y][x] in Python, it's d[x][y][z] in C++ --grant Tang

It should be used on 3D image only.

Returns:
3D multi-array format of the raw data.

Definition at line 822 of file emdata_metadata.cpp.

References get_data(), nx, ny, and nz.

00823 {
00824         const int ndims = 3;
00825         boost::array<std::size_t,ndims> dims = {{nx, ny, nz}};
00826         MArray3D marray(get_data(), dims, boost::fortran_storage_order());
00827         return marray;
00828 }

vector<int> EMAN::EMData::get_array_offsets (  )  [inline]

Definition at line 2276 of file emdata.h.

Referenced by center_origin_fft(), EMAN::QuadMinDotCmp::cmp(), depad(), depad_corner(), divkbsinh(), downsample(), extract_plane(), extractline(), fft_shuffle(), getconvpt2d_kbi0(), nn(), nn_ctf(), nn_ctf_applied(), nn_SSNR(), nn_SSNR_ctf(), norm_pad(), rot_scale_conv(), rot_scale_conv7(), rot_scale_conv_new(), rot_scale_conv_new_background(), rot_scale_trans(), rot_scale_trans2D(), rot_scale_trans2D_background(), rot_scale_trans_background(), rotavg(), EMAN::rsconvolution(), symplane0(), symplane0_ctf(), symplane1(), and symplane2().

EMObject EMData::get_attr ( const string &  attr_name  )  const

The generic way to get any image header information given a header attribute name.

If the attribute does not exist, it will raise an exception.

Parameters:
attr_name The header attribute name.
Returns:
The attribute value.
Exceptions:
NotExistingObjectException when attribute not exist

Definition at line 926 of file emdata_metadata.cpp.

References attr_dict, BadAllocException, changecount, data, ENTERFUNC, EXITFUNC, get_data(), greaterthan(), EMAN::Dict::has_key(), ImageFormatException, is_complex(), median(), NotExistingObjectException, nx, ny, nz, t, and update_stat().

Referenced by EMAN::file_store::add_image(), EMAN::newfile_store::add_image(), EMAN::CtfCWautoAverager::add_image(), ali3d_d(), EMAN::RefineAligner::align(), EMAN::RotateFlipAligner::align(), EMAN::RotateTranslateFlipAligner::align(), EMAN::RotateTranslateAligner::align(), EMAN::RotationalAligner::align(), calc_center_density(), calc_center_of_mass(), calc_hist(), EMAN::NormalizeStdProcessor::calc_mean(), EMAN::NormalizeMaxMinProcessor::calc_mean(), EMAN::NormalizeMaxMinProcessor::calc_sigma(), EMAN::NormalizeUnitSumProcessor::calc_sigma(), EMAN::NormalizeUnitProcessor::calc_sigma(), EMAN::NormalizeProcessor::calc_sigma(), calc_sigma_diff(), EMAN::FRCCmp::cmp(), EMAN::PhaseCmp::cmp(), EMAN::DotCmp::cmp(), EMAN::SqEuclideanCmp::cmp(), EMAN::SetSFProcessor::create_radial_func(), EMAN::MatchSFProcessor::create_radial_func(), EMAN::LowpassAutoBProcessor::create_radial_func(), find_3d_threshold(), EMAN::IterationAverager::finish(), get_attr_default(), EMAN::AddSigmaNoiseProcessor::get_sigma(), wustl_mm::SkeletonMaker::VolumeData::GetOriginX(), wustl_mm::SkeletonMaker::VolumeData::GetOriginY(), wustl_mm::SkeletonMaker::VolumeData::GetOriginZ(), wustl_mm::SkeletonMaker::VolumeData::GetSpacingX(), wustl_mm::SkeletonMaker::VolumeData::GetSpacingY(), wustl_mm::SkeletonMaker::VolumeData::GetSpacingZ(), EMAN::Util::histc(), EMAN::Util::histogram(), EMAN::Util::image_mutation(), EMAN::Util::infomask(), EMAN::FourierPixelInserter3D::init(), EMAN::nn4_ctfReconstructor::insert_padfft_slice(), EMAN::nn4Reconstructor::insert_slice(), EMAN::BackProjectionReconstructor::insert_slice(), little_big_dot(), main(), EMAN::PointArray::match_points(), EMAN::Util::multiref_polar_ali_2d_local(), EMAN::Util::multiref_polar_ali_2d_local_psi(), nn_ctf(), nn_ctf_applied(), nn_SSNR_ctf(), norm_pad(), EMAN::Util::pad(), EMAN::LowpassAutoBProcessor::preprocess(), EMAN::ApplyPolynomialProfileToHelix::process_inplace(), EMAN::ModelEMCylinderProcessor::process_inplace(), EMAN::TomoTiltEdgeMaskProcessor::process_inplace(), EMAN::TomoTiltAngleWeightProcessor::process_inplace(), EMAN::HistogramBin::process_inplace(), EMAN::NSigmaClampingProcessor::process_inplace(), EMAN::ClampingProcessor::process_inplace(), EMAN::AutoMask3D2Processor::process_inplace(), EMAN::AutoMask3DProcessor::process_inplace(), EMAN::CoordinateMaskFileProcessor::process_inplace(), EMAN::ACFCenterProcessor::process_inplace(), EMAN::ToMassCenterProcessor::process_inplace(), EMAN::AutoMask2DProcessor::process_inplace(), EMAN::BilateralProcessor::process_inplace(), EMAN::NormalizeByMassProcessor::process_inplace(), EMAN::VerticalStripeProcessor::process_inplace(), EMAN::CoordinateProcessor::process_inplace(), EMAN::RealPixelProcessor::process_inplace(), EMAN::StandardProjector::project3d(), and EMAN::PointArray::set_from_density_map().

00927 {
00928         ENTERFUNC;
00929 
00930         size_t size = nx * ny * nz;
00931         update_stat();
00932 
00933         if (key == "kurtosis") {
00934                 float mean = attr_dict["mean"];
00935                 float sigma = attr_dict["sigma"];
00936 
00937                 float *data = get_data();
00938                 double kurtosis_sum = 0;
00939 
00940                 for (size_t k = 0; k < size; k++) {
00941                         float t = (data[k] - mean) / sigma;
00942                         float tt = t * t;
00943                         kurtosis_sum += tt * tt;
00944                 }
00945 
00946                 float kurtosis = (float)(kurtosis_sum / size - 3.0);
00947                 return kurtosis;
00948         }
00949         else if (key == "skewness") {
00950                 float mean = attr_dict["mean"];
00951                 float sigma = attr_dict["sigma"];
00952 
00953                 float *data = get_data();
00954                 double skewness_sum = 0;
00955                 for (size_t k = 0; k < size; k++) {
00956                         float t = (data[k] - mean) / sigma;
00957                         skewness_sum +=  t * t * t;
00958                 }
00959                 float skewness = (float)(skewness_sum / size);
00960                 return skewness;
00961         }
00962         else if (key == "median")
00963         {
00964                 if ( is_complex() ) throw ImageFormatException("Error - can not calculate the median of a complex image");
00965                 size_t n = size;
00966                 float* tmp = new float[n];
00967                 float* d = get_data();
00968                 if (tmp == 0 ) throw BadAllocException("Error - could not create deep copy of image data");
00969                 for(size_t i=0; i < n; ++i) tmp[i] = d[i]; // should just be a memcpy
00970                 qsort(tmp, n, sizeof(float), &greaterthan);
00971                 float median;
00972                 if (n%2==1) median = tmp[n/2];
00973                 else median = (tmp[n/2-1]+tmp[n/2])/2.0f;
00974                 delete [] tmp;
00975                 return median;
00976         }
00977         else if (key == "nonzero_median")
00978         {
00979                 if ( is_complex() ) throw ImageFormatException("Error - can not calculate the median of a complex image");
00980                 vector<float> tmp;
00981                 size_t n = size;
00982                 float* d = get_data();
00983                 for( size_t i = 0; i < n; ++i ) {
00984                         if ( d[i] != 0 ) tmp.push_back(d[i]);
00985                 }
00986                 sort(tmp.begin(), tmp.end());
00987                 unsigned int vsize = tmp.size();
00988                 float median;
00989                 if (vsize%2==1) median = tmp[vsize/2];
00990                 else median = (tmp[vsize/2-1]+tmp[vsize/2])/2.0f;
00991                 return median;
00992         }
00993         else if (key == "changecount") return EMObject(changecount);
00994         else if (key == "nx") return nx;
00995         else if (key == "ny") return ny;
00996         else if (key == "nz") return nz;
00997 
00998         if(attr_dict.has_key(key)) {
00999                 return attr_dict[key];
01000         }
01001         else {
01002                 throw NotExistingObjectException(key, "The requested key does not exist");
01003         }
01004 
01005         EXITFUNC;
01006 }

EMObject EMData::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.

If the attribute does not exist, it will return a default EMObject() object, which will be converted to None in Python. Or return any object user submit.

Parameters:
attr_name The header attribute name.
em_obj the default attribute to return when this attr_name not exist in attr_dict
Returns:
The attribute value, default to None.

Definition at line 1008 of file emdata_metadata.cpp.

References attr_dict, ENTERFUNC, EXITFUNC, get_attr(), and EMAN::Dict::has_key().

Referenced by calc_radial_dist(), EMAN::FRCCmp::cmp(), EMAN::FourierReconstructor::determine_slice_agreement(), EMAN::nnSSNR_ctfReconstructor::insert_slice(), EMAN::nn4_ctfReconstructor::insert_slice(), EMAN::nnSSNR_Reconstructor::insert_slice(), EMAN::nn4Reconstructor::insert_slice(), EMAN::FourierReconstructor::insert_slice(), and EMAN::padfft_slice().

01009 {
01010         ENTERFUNC;
01011 
01012         if(attr_dict.has_key(key)) {
01013                 return get_attr(key);
01014         }
01015         else {
01016                 return em_obj;
01017         }
01018 
01019         EXITFUNC;
01020 }

Dict EMData::get_attr_dict (  )  const

Get the image attribute dictionary containing all the image attribute names and attribute values.

Returns:
The image attribute dictionary containing all attribute names and values.

Definition at line 1022 of file emdata_metadata.cpp.

References attr_dict, changecount, nx, ny, nz, and update_stat().

Referenced by EMAN::TestUtil::dump_emdata(), main(), EMAN::NewFourierProcessor::preprocess(), EMAN::LowpassAutoBProcessor::preprocess(), EMAN::HighpassAutoPeakProcessor::preprocess(), EMAN::HighpassFourierProcessor::preprocess(), EMAN::LowpassFourierProcessor::preprocess(), EMAN::TransformProcessor::process(), EMAN::MeanZeroEdgeProcessor::process_inplace(), and EMAN::TestUtil::verify_image_file_by_mode().

01023 {
01024         update_stat();
01025         
01026         Dict tmp=Dict(attr_dict);
01027         tmp["nx"]=nx;
01028         tmp["ny"]=ny;
01029         tmp["nz"]=nz;
01030         tmp["changecount"]=changecount;
01031 
01032         return tmp;
01033 }

int EMAN::EMData::get_changecount (  )  const [inline]

Definition at line 1198 of file emdata.h.

float EMData::get_circle_mean (  ) 

Calculates the circular edge mean by applying a circular mask on 'this' image.

Returns:
The circular edge mean.

Definition at line 643 of file emdata_metadata.cpp.

References data, EMData(), ENTERFUNC, EXITFUNC, get_data(), EMAN::EMUtil::is_same_size(), nx, ny, nz, process_inplace(), set_size(), and to_one().

Referenced by EMAN::NormalizeCircleMeanProcessor::calc_mean().

00644 {
00645         ENTERFUNC;
00646 
00647         static bool busy = false;
00648         static EMData *mask = 0;
00649 
00650         while (busy);
00651         busy = true;
00652 
00653         if (!mask || !EMUtil::is_same_size(this, mask)) {
00654                 if (!mask) {
00655                         mask = new EMData();
00656                 }
00657                 mask->set_size(nx, ny, nz);
00658                 mask->to_one();
00659 
00660                 float radius = (float)(ny / 2 - 2);
00661                 mask->process_inplace("mask.sharp", Dict("inner_radius", radius - 1,
00662                                                                            "outer_radius", radius + 1));
00663 
00664         }
00665         double n = 0,s=0;
00666         float *d = mask->get_data();
00667         float * data = get_data();
00668         size_t size = nx*ny*nz;
00669         for (size_t i = 0; i < size; i++) {
00670                 if (d[i]) { n+=1.0; s+=data[i]; }
00671         }
00672 
00673 
00674         float result = (float)(s/n);
00675         busy = false;
00676 
00677         EXITFUNC;
00678         return result;
00679 }

EMData * EMData::get_col ( int  col_index  )  const

Get one column of a 2D images.

Parameters:
col_index Index of the column.
Exceptions:
ImageDimensionException If this image is not 2D.
Returns:
A 1D image with the column data.

Definition at line 694 of file emdata_core.cpp.

References EMData(), ENTERFUNC, EXITFUNC, get_data(), get_ndim(), ImageDimensionException, nx, ny, set_size(), and update().

Referenced by EMAN::CCDNormProcessor::process_inplace().

00695 {
00696         ENTERFUNC;
00697 
00698         if (get_ndim() != 2) {
00699                 throw ImageDimensionException("2D image only");
00700         }
00701 
00702         EMData *ret = new EMData();
00703         ret->set_size(ny, 1, 1);
00704         float *dst = ret->get_data();
00705         float *src = get_data();
00706 
00707         for (int i = 0; i < ny; i++) {
00708                 dst[i] = src[i * nx + col_index];
00709         }
00710 
00711         ret->update();
00712         EXITFUNC;
00713         return ret;
00714 }

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:
x x coordinate
y y coordinate
z z coordinate
Returns:
The complex pixel at x,y

Definition at line 127 of file emdata_core.cpp.

References abs, nx, nxy, ny, nz, and rdata.

00127                                                                                     {
00128         if (abs(x)>=nx/2 || abs(y)>ny/2 || abs(z)>nz/2) return std::complex<float>(0,0);
00129 
00130         if (x<0) {
00131                 int idx=-x*2+(y<=0?-y:ny-y)*nx+(z<=0?-z:nz-z)*nxy;
00132                 return std::complex<float>(rdata[idx],rdata[idx+1]);
00133         }
00134 
00135         int idx=x*2+(y<0?ny+y:y)*nx+(z<0?nz+z:z)*nxy;
00136         return std::complex<float>(rdata[idx],rdata[idx+1]);
00137 }

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:
x x coordinate
y y coordinate
Returns:
The complex pixel at x,y

Definition at line 119 of file emdata_core.cpp.

References abs, nx, ny, and rdata.

Referenced by EMAN::FourierReconstructor::do_insert_slice_work(), and make_footprint().

00119                                                                        {
00120         if (abs(x)>=nx/2 || abs(y)>ny/2) return std::complex<float>(0,0);
00121         if (x>=0 && y>=0) return std::complex<float>(rdata[ x*2+y*nx],      rdata[x*2+y*nx+1]);
00122         if (x>0 && y<0) return std::complex<float>(  rdata[ x*2+(ny+y)*nx], rdata[x*2+(ny+y)*nx+1]);
00123         if (x<0 && y>0) return std::complex<float>(  rdata[-x*2+(ny-y)*nx],-rdata[-x*2+(ny-y)*nx+1]);
00124         return std::complex<float>(rdata[-x*2-y*nx],-rdata[-x*2+-y*nx+1]);
00125 }

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 147 of file emdata_core.cpp.

References abs, nx, nxyz, ny, and nz.

00147                                                                                                                                                                  {
00148 if (abs(x)>=fullnx/2 || abs(y)>fullny/2 || abs(z)>fullnz/2) return nxyz;
00149 
00150 if (x<0) {
00151         x*=-1;
00152         y*=-1;
00153         z*=-1;
00154 }
00155 if (y<0) y=fullny+y;
00156 if (z<0) z=fullnz+z;
00157 
00158 if (x<subx0||y<suby0||z<subz0||x>=subx0+nx||y>=suby0+ny||z>=subz0+nz) return nxyz;
00159 
00160 return (x-subx0)*2+(y-suby0)*(size_t)nx+(z-subz0)*(size_t)nx*(size_t)ny;
00161 }

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:
x x coordinate
y y coordinate
z z coordinate
Returns:
The complex pixel at x,y

Definition at line 139 of file emdata_core.cpp.

References abs, nx, nxy, nxyz, ny, and nz.

Referenced by EMAN::FourierReconstructor::pixel_at().

00139                                                                              {
00140         if (abs(x)>=nx/2 || abs(y)>ny/2 || abs(z)>nz/2) return nxyz;
00141         if (x<0) {
00142                 return -x*2+(y<=0?-y:ny-y)*(size_t)nx+(z<=0?-z:nz-z)*(size_t)nxy;
00143         }
00144         return x*2+(y<0?ny+y:y)*(size_t)nx+(z<0?nz+z:z)*(size_t)nxy;
00145 }

size_t EMAN::EMData::get_complex_index_fast ( const int &  x,
const int &  y,
const int &  z 
) const [inline]

Definition at line 1917 of file emdata.h.

Referenced by EMAN::FourierReconstructor::pixel_at().

const float* const EMAN::EMData::get_const_data (  )  const [inline]

Get the image pixel density data in a 1D float array - const version of get_data.

Returns:
The image pixel density data.

Definition at line 338 of file emdata.h.

References ENTERFUNC, and process_inplace().

Referenced by EMAN::MeanShrinkProcessor::accrue_mean(), EMAN::MeanShrinkProcessor::accrue_mean_one_p_five(), EMAN::MedianShrinkProcessor::accrue_median(), EMAN::PhaseCmp::cmp(), EMAN::OptVarianceCmp::cmp(), EMAN::DotCmp::cmp(), EMAN::SqEuclideanCmp::cmp(), EMAN::CccCmp::cmp(), operator==(), EMAN::TransformProcessor::transform(), and unwrap().

00344 {

Ctf * EMData::get_ctf (  )  const

Get ctf parameter of this image.

Returns:
The ctf parameter.

Definition at line 692 of file emdata_metadata.cpp.

References attr_dict, EMAN::Ctf::from_vector(), and EMAN::Dict::has_key().

Referenced by EMAN::EMUtil::is_same_ctf(), main(), and EMAN::SNRProcessor::process_inplace().

00693 {
00694         if(attr_dict.has_key("ctf")) {
00695                 EMAN1Ctf * ctf = new EMAN1Ctf();
00696                 ctf->from_vector(attr_dict["ctf"]);
00697 
00698                 return dynamic_cast<Ctf *>(ctf);
00699         }
00700         else {
00701                 return 0;
00702         }
00703 }

float* EMAN::EMData::get_data (  )  const [inline]

Get the image pixel density data in a 1D float array.

Returns:
The image pixel density data.

Definition at line 332 of file emdata.h.

Referenced by absi(), EMAN::MeanShrinkProcessor::accrue_mean(), EMAN::MeanShrinkProcessor::accrue_mean_one_p_five(), EMAN::MedianShrinkProcessor::accrue_median(), add(), EMAN::file_store::add_image(), EMAN::CtfAverager::add_image(), EMAN::CtfCWautoAverager::add_image(), EMAN::IterationAverager::add_image(), EMAN::ImageAverager::add_image(), EMAN::Util::add_img(), EMAN::Util::add_img2(), EMAN::Util::add_img_abs(), add_incoherent(), EMAN::newfile_store::add_tovol(), EMAN::Util::addn_img(), addsquare(), ali3d_d(), EMAN::RotatePrecenterAligner::align(), EMAN::TranslationalAligner::align(), EMAN::RotationalAligner::align_180_ambiguous(), amplitude(), EMAN::SVDAnalyzer::analyze(), EMAN::varimax::analyze(), EMAN::PCAlarge::analyze(), EMAN::PCAsmall::analyze(), ap2ri(), apmd(), apmq(), apply_radial_func(), average_circ_sub(), EMAN::PawelProjector::backproject3d(), EMAN::ChaoProjector::backproject3d(), calc_az_dist(), calc_ccfx(), calc_center_density(), calc_center_of_mass(), calc_dist(), calc_fourier_shell_correlation(), calc_highest_locations(), calc_hist(), EMAN::MaskEdgeMeanProcessor::calc_locals(), calc_max_location(), EMAN::NormalizeLREdgeMeanProcessor::calc_mean(), EMAN::NormalizeMaskProcessor::calc_mean(), calc_min_location(), calc_mutual_correlation(), calc_n_highest_locations(), calc_radial_dist(), EMAN::NormalizeMaskProcessor::calc_sigma(), calc_sigma_diff(), circumference(), clip_inplace(), cm_euc(), EMAN::Util::cml_prepare_line(), EMAN::FRCCmp::cmp(), EMAN::PhaseCmp::cmp(), common_lines(), common_lines_real(), EMAN::Util::compress_image_mask(), EMAN::EMAN2Ctf::compute_2d_complex(), EMAN::EMAN1Ctf::compute_2d_complex(), conjg(), convolute(), EMAN::Util::Crosrng_e(), EMAN::Util::Crosrng_ew(), EMAN::Util::Crosrng_ms(), EMAN::Util::Crosrng_ms_delta(), EMAN::Util::Crosrng_msg(), EMAN::Util::Crosrng_msg_m(), EMAN::Util::Crosrng_msg_s(), EMAN::Util::Crosrng_ns(), EMAN::Util::Crosrng_psi_0_180(), EMAN::Util::Crosrng_sm_psi(), cut_slice(), EMAN::Util::cyclicshift(), EMAN::Util::decimate(), depad(), depad_corner(), EMAN::PointArray::distmx(), div(), EMAN::Util::div_filter(), EMAN::Util::div_img(), EMAN::Util::divn_filter(), EMAN::Util::divn_img(), EMAN::FourierReconstructor::do_compare_slice_work(), do_fft(), do_fft_inplace(), do_ift(), do_ift_inplace(), do_radon(), dot_rotate_translate(), EMAN::TestUtil::dump_emdata(), EMAN::Processor::EMFourierFilterFunc(), EMAN::Util::ener(), EMAN::Util::eval(), filter_by_image(), EMAN::WienerFourierReconstructor::finish(), EMAN::CtfAverager::finish(), EMAN::CtfCWautoAverager::finish(), EMAN::IterationAverager::finish(), EMAN::ImageAverager::finish(), Four_ds(), Four_shuf_ds_cen_us(), EMAN::Phase180Processor::fourier_phaseshift180(), FourInterpol(), FourTruncate(), EMAN::Util::Frngs(), EMAN::Util::Frngs_inv(), get_2dcview(), get_2dview(), get_3dcview(), get_3dcviewptr(), get_3dview(), get_attr(), get_circle_mean(), get_col(), get_data_pickle(), get_edge_mean(), get_fft_amplitude(), get_fft_phase(), EMAN::file_store::get_image(), EMAN::newfile_store::get_image(), get_pixel_conv7(), get_pow(), get_row(), EMAN::Util::get_slice(), get_top_half(), get_value_at_wrap(), EMAN::Util::hist_comp_freq(), EMAN::Util::histc(), EMAN::Util::histogram(), EMAN::Util::im_diff(), imag(), EMAN::Util::image_mutation(), EMAN::Util::infomask(), EMAN::nn4_ctfReconstructor::insert_buffed_slice(), insert_clip(), EMAN::SVDAnalyzer::insert_image(), EMAN::varimax::insert_image(), EMAN::PCAlarge::insert_image(), EMAN::PCAsmall::insert_image(), insert_scaled_sum(), EMAN::BackProjectionReconstructor::insert_slice(), EMAN::WienerFourierReconstructor::insert_slice(), EMAN::FourierReconstructorSimple2D::insert_slice(), EMAN::GaussFFTProjector::interp_ft_3d(), EMAN::PCA::Lanczos_ooc(), little_big_dot(), EMAN::FourierReconstructor::load_inserter(), log(), log10(), EMAN::Util::mad_scalar(), EMAN::Util::madn_scalar(), main(), EMAN::TestUtil::make_image_file_by_mode(), EMAN::EMUtil::make_image_median(), EMAN::Util::min_dist_four(), EMAN::Util::min_dist_real(), EMAN::Util::move_points(), EMAN::Util::mul_img(), EMAN::Util::mul_scalar(), EMAN::Util::muln_img(), mult(), mult_complex_efficient(), EMAN::Util::mult_scalar(), EMAN::Util::multiref_peaks_ali2d(), EMAN::Util::multiref_peaks_compress_ali2d(), EMAN::Util::Normalize_ring(), EMAN::ReconstructorVolumeData::normalize_threed(), operator==(), EMAN::Util::pack_complex_to_real(), EMAN::Util::pad(), ParseAlignOptions(), EMAN::PointArray::pdb2mrc_by_summation(), phase(), EMAN::FourierReconstructor::pixel_at(), EMAN::Util::Polar2D(), EMAN::Util::Polar2Dm(), EMAN::Util::Polar2Dmi(), EMAN::DirectionalSumProcessor::process(), EMAN::Wiener2DAutoAreaProcessor::process(), EMAN::XYZProcessor::process_inplace(), EMAN::BinaryOperateProcessor< Type >::process_inplace(), EMAN::ApplyPolynomialProfileToHelix::process_inplace(), EMAN::ModelEMCylinderProcessor::process_inplace(), EMAN::ConvolutionProcessor::process_inplace(), EMAN::HistogramBin::process_inplace(), EMAN::ClampingProcessor::process_inplace(), EMAN::Rotate180Processor::process_inplace(), EMAN::CCDNormProcessor::process_inplace(), EMAN::RampProcessor::process_inplace(), EMAN::TestImageCylinder::process_inplace(), EMAN::TestImageNoiseGauss::process_inplace(), EMAN::TestImageNoiseUniformRand::process_inplace(), EMAN::TestImageCirclesphere::process_inplace(), EMAN::TestImageSquarecube::process_inplace(), EMAN::TestImageSinewaveCircular::process_inplace(), EMAN::TestImageSinewave::process_inplace(), EMAN::TestImageGaussian::process_inplace(), EMAN::TestImageFourierNoiseProfile::process_inplace(), EMAN::CTFSNRWeightProcessor::process_inplace(), EMAN::TestImageFourierNoiseGaussian::process_inplace(), EMAN::IterBinMaskProcessor::process_inplace(), EMAN::AutoMask3D2Processor::process_inplace(), EMAN::AutoMask3DProcessor::process_inplace(), EMAN::SmartMaskProcessor::process_inplace(), EMAN::CoordinateMaskFileProcessor::process_inplace(), EMAN::SymSearchProcessor::process_inplace(), EMAN::AddMaskShellProcessor::process_inplace(), EMAN::AddRandomNoiseProcessor::process_inplace(), EMAN::AutoMask2DProcessor::process_inplace(), EMAN::AutoMaskAsymUnit::process_inplace(), EMAN::PhaseToCenterProcessor::process_inplace(), EMAN::PhaseToCornerProcessor::process_inplace(), EMAN::FourierToCenterProcessor::process_inplace(), EMAN::FourierToCornerProcessor::process_inplace(), EMAN::AddNoiseProcessor::process_inplace(), EMAN::FlipProcessor::process_inplace(), EMAN::RotationalSubstractProcessor::process_inplace(), EMAN::RotationalAverageProcessor::process_inplace(), EMAN::BilateralProcessor::process_inplace(), EMAN::BinarizeFourierProcessor::process_inplace(), EMAN::NormalizeToLeastSquareProcessor::process_inplace(), EMAN::NormalizeRowProcessor::process_inplace(), EMAN::NormalizeByMassProcessor::process_inplace(), EMAN::NormalizeProcessor::process_inplace(), EMAN::ZeroEdgePlaneProcessor::process_inplace(), EMAN::ZeroEdgeRowProcessor::process_inplace(), EMAN::DecayEdgeProcessor::process_inplace(), EMAN::AverageXProcessor::process_inplace(), EMAN::MeanZeroEdgeProcessor::process_inplace(), EMAN::BeamstopProcessor::process_inplace(), EMAN::SigmaZeroEdgeProcessor::process_inplace(), EMAN::VerticalStripeProcessor::process_inplace(), EMAN::GradientPlaneRemoverProcessor::process_inplace(), EMAN::GradientRemoverProcessor::process_inplace(), EMAN::CutoffBlockProcessor::process_inplace(), EMAN::DiffBlockProcessor::process_inplace(), EMAN::BoxStatProcessor::process_inplace(), EMAN::AreaProcessor::process_inplace(), EMAN::ComplexPixelProcessor::process_inplace(), EMAN::ToMinvalProcessor::process_inplace(), EMAN::WatershedProcessor::process_inplace(), EMAN::CoordinateProcessor::process_inplace(), EMAN::RealPixelProcessor::process_inplace(), EMAN::Wiener2DFourierProcessor::process_inplace(), EMAN::Wiener2DAutoAreaProcessor::process_inplace(), EMAN::LinearPyramidProcessor::process_inplace(), EMAN::AmpweightFourierProcessor::process_inplace(), EMAN::FourierAnlProcessor::process_inplace(), EMAN::FourierProcessor::process_inplace(), EMAN::ImageProcessor::process_inplace(), EMAN::ChaoProjector::project3d(), EMAN::StandardProjector::project3d(), EMAN::GaussFFTProjector::project3d(), read_data(), read_image(), ReadVandBcast(), real(), recons3d_CGLS_mpi_Cart(), recons3d_HyBR_mpi_Cart(), recons3d_sirt_mpi(), recons3d_sirt_mpi_Cart(), EMAN::Util::reconstitute_image_mask(), render_amp24(), render_ap24(), replace_amplitudes(), ri2ap(), ri2inten(), rot_scale_conv_new(), rot_scale_conv_new_background(), rot_scale_trans(), rot_scale_trans2D(), rot_scale_trans2D_background(), rot_scale_trans_background(), rotate_translate(), rotate_x(), set_col(), set_data_pickle(), EMAN::PointArray::set_from_density_map(), EMAN::Util::set_line(), EMAN::SVDAnalyzer::set_params(), set_row(), set_size(), wustl_mm::SkeletonMaker::VolumeData::SetDataAt(), EMAN::WienerFourierReconstructor::setup(), setup4slice(), sget_value_at(), sqrt(), sub(), EMAN::Util::sub_fav(), EMAN::Util::sub_img(), EMAN::Util::subn_img(), subsquare(), EMAN::Phase180Processor::swap_central_slices_180(), EMAN::Phase180Processor::swap_corners_180(), to_value(), uncut_slice(), unified(), unwrap(), unwrap_largerR(), EMAN::Util::update_fav(), update_stat(), EMAN::Cmp::validate_input_args(), EMAN::TestUtil::verify_image_file_by_mode(), EMAN::EMUtil::vertical_acf(), EMAN::Util::window(), write_data(), write_image(), EMAN::Util::WTF(), and EMAN::Util::WTM().

00344 {

vector<float> EMAN::EMData::get_data_as_vector (  )  const [inline]

Get the pixel data as a vector.

Returns:
a vector containing the pixel data.

Definition at line 868 of file emdata.h.

00872                                 {
00873                                         prv_x_right = prv_nx - new_nx - xtrans;
00874                                         x_iter -= prv_x_right;

std::string EMData::get_data_pickle (  )  const

Definition at line 1160 of file emdata_metadata.cpp.

References get_data(), nx, ny, and nz.

01161 {
01162 //      vector<float> vf;
01163 //      vf.resize(nx*ny*nz);
01164 //      std::copy(rdata, rdata+nx*ny*nz, vf.begin());
01165 
01166         std::string vf((const char *)get_data(),nx*ny*nz*sizeof(float));
01167 
01168         return vf;
01169 }

float EMData::get_edge_mean (  )  const

Calculates the mean pixel values around the (1 pixel) edge of the image.

Returns:
The mean pixel values around the (1 pixel) edge.

Definition at line 589 of file emdata_metadata.cpp.

References data, ENTERFUNC, EXITFUNC, get_data(), nx, nxy, ny, and nz.

Referenced by calc_fast_sigma_image(), EMAN::NormalizeEdgeMeanProcessor::calc_mean(), EMAN::NormalizeMaskProcessor::calc_mean(), little_big_dot(), make_rotational_footprint(), make_rotational_footprint_cmc(), make_rotational_footprint_e1(), and EMAN::FlattenBackgroundProcessor::process_inplace().

00590 {
00591         ENTERFUNC;
00592 
00593         int di = 0;
00594         double edge_sum = 0;
00595         float edge_mean = 0;
00596         size_t nxy = nx * ny;
00597         float * data = get_data();
00598         if (nz == 1) {
00599                 for (int i = 0, j = (ny - 1) * nx; i < nx; ++i, ++j) {
00600                         edge_sum += data[i] + data[j];
00601                 }
00602                 for (size_t i = 0, j = nx - 1; i < nxy; i += nx, j += nx) {
00603                         edge_sum += data[i] + data[j];
00604                 }
00605                 edge_mean = (float)edge_sum / (nx * 2 + ny * 2);
00606         }
00607         else {
00608                 if (nx == ny && nx == nz * 2 - 1) {
00609                         for (size_t j = (nxy * (nz - 1)); j < nxy * nz; ++j, ++di) {
00610                                 edge_sum += data[j];
00611                         }
00612                 }
00613                 else {
00614                         for (size_t i = 0, j = (nxy * (nz - 1)); i < nxy; ++i, ++j, ++di) {
00615                                 edge_sum += data[i] + data[j];
00616                         }
00617                 }
00618 
00619                 int nxy2 = nx * (ny - 1);
00620                 for (int k = 1; k < nz - 1; ++k) {
00621                         size_t k2 = k * nxy;
00622                         size_t k3 = k2 + nxy2;
00623                         for (int i = 0; i < nx; ++i, ++di) {
00624                                 edge_sum += data[i + k2] + data[i + k3];
00625                         }
00626                 }
00627                 for (int k = 1; k < nz - 1; ++k) {
00628                         size_t k2 = k * nxy;
00629                         size_t k3 = nx - 1 + k2;
00630                         for (int i = 1; i < ny - 1; ++i, ++di) {
00631                                 edge_sum += data[i * nx + k2] + data[i * nx + k3];
00632                         }
00633                 }
00634 
00635                 edge_mean = (float)edge_sum / (di * 2);
00636         }
00637         EXITFUNC;
00638 
00639         return edge_mean;
00640 }

EMData * EMData::get_fft_amplitude (  ) 

return the amplitudes of the FFT including the left half

Exceptions:
ImageFormatException If the image is not a complex image.
Returns:
The current FFT image's amplitude image.

Definition at line 92 of file emdata_metadata.cpp.

References copy_head(), data, ENTERFUNC, EXITFUNC, get_data(), get_ndim(), get_ysize(), get_zsize(), ImageFormatException, is_complex(), LOGERR, nx, ny, nz, ri2ap(), set_complex(), set_complex_x(), set_ri(), set_size(), to_zero(), and update().

00093 {
00094         ENTERFUNC;
00095 
00096         if (!is_complex()) {
00097                 LOGERR("complex image expected. Input image is real image.");
00098                 throw ImageFormatException("complex image expected. Input image is a real image.");
00099         }
00100 
00101         ri2ap();
00102 
00103         int nx2 = nx - 2;
00104         EMData *dat = copy_head();
00105         dat->set_size(nx2, ny, nz);
00106         dat->to_zero();
00107 
00108         float *d = dat->get_data();
00109         float *data = get_data();
00110         int ndim = get_ndim();
00111 
00112         size_t idx1, idx2, idx3;
00113         if (ndim == 3) {
00114                 for (int k = 1; k < nz; ++k) {
00115                         for (int j = 1; j < ny; ++j) {
00116                                 for (int i = 0; i < nx2/2; ++i) {
00117                                         idx1 = k*nx2*ny+j*nx2+nx2/2+i;
00118                                         idx2 = k*nx*ny+j*nx+2*i;
00119                                         idx3 = (nz-k)*nx2*ny+(ny-j)*nx2+nx2/2-i;
00120                                         d[idx1] = data[idx2];
00121                                         d[idx3] = data[idx2];
00122                                 }
00123                         }
00124                 }
00125         }
00126         else if (ndim == 2) {
00127                 for (int j = 1; j < ny; ++j) {
00128                         for (int i = 0; i < nx2/2; ++i) {
00129                                 d[j*nx2+nx2/2+i] = data[j*nx+2*i];
00130                                 d[(ny-j)*nx2+nx2/2-i] = data[j*nx+2*i];
00131                         }
00132                 }
00133         }
00134 
00135         dat->update();
00136         dat->set_complex(false);
00137         if(dat->get_ysize()==1 && dat->get_zsize()==1) {
00138                 dat->set_complex_x(false);
00139         }
00140         dat->set_ri(false);
00141 
00142         EXITFUNC;
00143         return dat;
00144 }

EMData * EMData::get_fft_amplitude2D (  ) 

return the amplitudes of the 2D FFT including the left half PRB

Exceptions:
ImageFormatException If the image is not a complex image.

Returns:
The current FFT image's amplitude image.

Definition at line 51 of file emdata_metadata.cpp.

References copy_head(), ENTERFUNC, EXITFUNC, ImageFormatException, is_complex(), LOGERR, nx, ny, nz, set_complex(), set_ri(), set_size(), sqrt(), to_zero(), and update().

00052 {
00053         ENTERFUNC;
00054 
00055 //      int ndim = get_ndim();
00056         if (!is_complex()) {
00057                 LOGERR("complex image expected. Input image is real image.");
00058                 throw ImageFormatException("complex image expected. Input image is a real image.");
00059         }
00060         if (nz>1) {
00061                 LOGERR("2D image expected. Input image is 3D");
00062                 throw ImageFormatException("2D odd square complex image"
00063                         " expected Input image is 3D.");
00064         }
00065 
00066         int nx2 = nx/2;
00067 
00068         EMData *dat = copy_head();
00069 
00070         dat->set_size(nx2, ny, nz);
00071         dat->to_zero();
00072 
00073         float temp=0;
00074 
00075         for (int j = 0; j < ny; j++) {
00076                 for (int i = 0; i < nx2; i++) {
00077                         temp = (*this)(2*i,j)*(*this)(2*i,j);
00078                         temp += (*this)(2*i+1,j)*(*this)(2*i+1,j);
00079                         (*dat)(i,j) = std::sqrt(temp);
00080                 }
00081         }
00082 
00083         dat->update();
00084         dat->set_complex(false);
00085         dat->set_ri(false);
00086 
00087         EXITFUNC;
00088         return dat;
00089 }

EMData * EMData::get_fft_phase (  ) 

return the phases of the FFT including the left half

Exceptions:
ImageFormatException If the image is not a complex image.
Returns:
The current FFT image's phase image.

Definition at line 147 of file emdata_metadata.cpp.

References copy_head(), data, ENTERFUNC, EXITFUNC, get_data(), get_ndim(), get_ysize(), get_zsize(), ImageFormatException, is_complex(), LOGERR, nx, ny, nz, ri2ap(), set_complex(), set_complex_x(), set_ri(), set_size(), to_zero(), and update().

00148 {
00149         ENTERFUNC;
00150 
00151         if (!is_complex()) {
00152                 LOGERR("complex image expected. Input image is real image.");
00153                 throw ImageFormatException("complex image expected. Input image is a real image.");
00154         }
00155 
00156         ri2ap();
00157 
00158         int nx2 = nx - 2;
00159         EMData *dat = copy_head();
00160         dat->set_size(nx2, ny, nz);
00161         dat->to_zero();
00162 
00163         float *d = dat->get_data();
00164         float * data = get_data();
00165 
00166         int ndim = get_ndim();
00167         size_t idx1, idx2, idx3;
00168         if (ndim == 3) {
00169                 for (int k = 1; k < nz; ++k) {
00170                         for (int j = 1; j < ny; ++j) {
00171                                 for (int i = 0; i < nx2/2; ++i) {
00172                                         idx1 = k*nx2*ny+j*nx2+nx2/2+i;
00173                                         idx2 = k*nx*ny+j*nx+2*i+1;
00174                                         idx3 = (nz-k)*nx2*ny+(ny-j)*nx2+nx2/2-i;
00175                                         d[idx1] = data[idx2];
00176                                         d[idx3] = -data[idx2];
00177                                 }
00178                         }
00179                 }
00180         }
00181         else if (ndim == 2) {
00182                 for (int j = 1; j < ny; ++j) {
00183                         for (int i = 0; i < nx2/2; ++i) {
00184                                 d[j*nx2+nx2/2+i] = data[j*nx+2*i+1];
00185                                 d[(ny-j)*nx2+nx2/2-i] = -data[j*nx+2*i+1];
00186                         }
00187                 }
00188         }
00189 
00190         dat->update();
00191         dat->set_complex(false);
00192         if(dat->get_ysize()==1 && dat->get_zsize()==1) {
00193                 dat->set_complex_x(false);
00194         }
00195         dat->set_ri(false);
00196 
00197         EXITFUNC;
00198         return dat;
00199 }

int EMAN::EMData::get_flags (  )  const [inline]

Definition at line 1188 of file emdata.h.

int EMAN::EMData::get_ndim (  )  const [inline]

Get image dimension.

Returns:
image dimension.

Definition at line 879 of file emdata.h.

Referenced by ali3d_d(), EMAN::Refine3DAligner::align(), apply_radial_func(), EMAN::TransformProcessor::assert_valid_aspect(), calc_az_dist(), calc_ccfx(), calc_dist(), calc_fast_sigma_image(), cog(), cut_slice(), delete_disconnected_regions(), do_ift(), do_radon(), EMAN::PCA::dopca_ooc(), dot_rotate_translate(), EMAN::Processor::EMFourierFilterFunc(), extractpoint(), EMAN::FFTResampleProcessor::fft_resample(), find_3d_threshold(), fouriergridrot2d(), fouriergridrot_shift2d(), get_2dcview(), get_2dview(), get_clip(), EMAN::IntTranslateProcessor::get_clip_region(), get_col(), get_fft_amplitude(), get_fft_phase(), get_row(), get_top_half(), helicise(), insert_scaled_sum(), EMAN::FourierReconstructorSimple2D::insert_slice(), EMAN::PCA::Lanczos_ooc(), little_big_dot(), main(), max_search(), mult_complex_efficient(), peak_search(), phase_cog(), EMAN::ScaleTransformProcessor::process(), EMAN::TransposeProcessor::process(), EMAN::MeanShrinkProcessor::process(), EMAN::Rotate180Processor::process_inplace(), EMAN::ScaleTransformProcessor::process_inplace(), EMAN::TestImageSinewave::process_inplace(), EMAN::TestImageSphericalWave::process_inplace(), EMAN::TestImageScurve::process_inplace(), EMAN::TestImageFourierNoiseProfile::process_inplace(), EMAN::CTFSNRWeightProcessor::process_inplace(), EMAN::TestImageFourierNoiseGaussian::process_inplace(), EMAN::AutoMask3D2Processor::process_inplace(), EMAN::ACFCenterProcessor::process_inplace(), EMAN::PhaseToMassCenterProcessor::process_inplace(), EMAN::AutoMask2DProcessor::process_inplace(), EMAN::PhaseToCenterProcessor::process_inplace(), EMAN::TransposeProcessor::process_inplace(), EMAN::RotationalSubstractProcessor::process_inplace(), EMAN::RotationalAverageProcessor::process_inplace(), EMAN::FlattenBackgroundProcessor::process_inplace(), EMAN::MeanShrinkProcessor::process_inplace(), EMAN::FourierGriddingProjector::project3d(), EMAN::StandardProjector::project3d(), EMAN::GaussFFTProjector::project3d(), ReadVandBcast(), render_amp24(), render_ap24(), rotate_x(), set_col(), set_row(), setup4slice(), uncut_slice(), unified(), unwrap(), window_center(), EMAN::RT3DSphereAligner::xform_align_nbest(), and EMAN::RT3DGridAligner::xform_align_nbest().

00886                                                 {}
00887 
00888                         int prv_nx, prv_ny, prv_nz, new_nx, new_ny, new_nz;
00889                         int xshift, yshift, zshift;
00890                         int x_iter, y_iter, z_iter;
00891                         int new_z_top, new_z_bottom, new_y_back, new_y_front, new_x_left, new_x_right;

string EMAN::EMData::get_path (  )  const [inline]

Definition at line 1237 of file emdata.h.

int EMAN::EMData::get_pathnum (  )  const [inline]

Definition at line 1242 of file emdata.h.

float EMData::get_pixel_conv ( float  delx,
float  dely,
float  delz,
Util::KaiserBessel kb 
)

Get pixel value image using convolution.

If the image is a volume, then all slices are rotated/translated/scaled.

Parameters:
[in] delx Amount to shift rotation origin along x
[in] dely Amount to shift rotation origin along y
[in] delz Amount to shift rotation origin along z
[in] kb convolution kernel
Exceptions:
ImageDimensionException can not rotate 1 D image
Returns:
New rotated/shifted/scaled image

Definition at line 2774 of file emdata_sparx.cpp.

References EMAN::Util::KaiserBessel::get_window_size(), EMAN::Util::KaiserBessel::i0win_tab(), nx, ny, nz, q, restrict2(), and EMAN::Util::round().

02774                                                                                       {
02775 //  here counting is in C style, so coordinates of the pixel delx should be [0-nx-1]
02776 
02777         int K     = kb.get_window_size();
02778         int kbmin = -K/2;
02779         int kbmax = -kbmin;
02780         int kbc   = kbmax+1;
02781 
02782         float pixel =0.0f;
02783         float w=0.0f;
02784 
02785         delx = restrict2(delx, nx);
02786         int inxold = int(Util::round(delx));
02787         if(ny<2) {  //1D
02788                 if(inxold <= kbc || inxold >=nx-kbc-2 )  {
02789                         //  loop for ends
02790                         for (int m1 =kbmin; m1 <=kbmax; m1++) {
02791                                 float q = kb.i0win_tab(delx - inxold-m1);
02792                                 pixel += (*this)((inxold+m1+nx)%nx)*q; w+=q;
02793                         }
02794                 } else {
02795                         for (int m1 =kbmin; m1 <=kbmax; m1++) {
02796                                 float q = kb.i0win_tab(delx - inxold-m1);
02797                                 pixel += (*this)(inxold+m1)*q; w+=q;
02798                         }
02799                 }
02800 
02801         } else if(nz<2) {  // 2D
02802                 dely = restrict2(dely, ny);
02803                 int inyold = int(Util::round(dely));
02804                 if(inxold <= kbc || inxold >=nx-kbc-2 || inyold <= kbc || inyold >=ny-kbc-2 )  {
02805                         //  loop for strips
02806                         for (int m2 =kbmin; m2 <=kbmax; m2++){ for (int m1 =kbmin; m1 <=kbmax; m1++) {
02807                                 float q = kb.i0win_tab(delx - inxold-m1)*kb.i0win_tab(dely - inyold-m2);
02808                                 pixel += (*this)((inxold+m1+nx)%nx,(inyold+m2+ny)%ny)*q; w+=q;}
02809                         }
02810                 } else {
02811                         for (int m2 =kbmin; m2 <=kbmax; m2++){ for (int m1 =kbmin; m1 <=kbmax; m1++) {
02812                                 float q = kb.i0win_tab(delx - inxold-m1)*kb.i0win_tab(dely - inyold-m2);
02813                                 pixel += (*this)(inxold+m1,inyold+m2)*q; w+=q;}
02814                         }
02815                 }
02816         } else {  //  3D
02817                 dely = restrict2(dely, ny);
02818                 int inyold = int(Util::round(dely));
02819                 delz = restrict2(delz, nz);
02820                 int inzold = int(Util::round(delz));
02821                     //cout << inxold<<"  "<< kbc<<"  "<< nx-kbc-2<<"  "<< endl;
02822                 if(inxold <= kbc || inxold >=nx-kbc-2 || inyold <= kbc || inyold >=ny-kbc-2  || inzold <= kbc || inzold >=nz-kbc-2 )  {
02823                         //  loop for strips
02824                         for (int m3 =kbmin; m3 <=kbmax; m3++){ for (int m2 =kbmin; m2 <=kbmax; m2++){ for (int m1 =kbmin; m1 <=kbmax; m1++) {
02825                                 float q = kb.i0win_tab(delx - inxold-m1)*kb.i0win_tab(dely - inyold-m2)*kb.i0win_tab(delz - inzold-m3);
02826                                 //cout << "BB  "<<m1<<"  "<< m2<<"  "<< m3<<"  "<< q<<"  "<< q<<"  "<<(*this)((inxold+m1+nx)%nx,(inyold+m2+ny)%ny,(inzold+m3+nz)%nz)<< endl;
02827                                 pixel += (*this)((inxold+m1+nx)%nx,(inyold+m2+ny)%ny,(inzold+m3+nz)%nz)*q ;w+=q;}}
02828                         }
02829                 } else {
02830                         for (int m3 =kbmin; m3 <=kbmax; m3++){ for (int m2 =kbmin; m2 <=kbmax; m2++){ for (int m1 =kbmin; m1 <=kbmax; m1++) {
02831                                 float q = kb.i0win_tab(delx - inxold-m1)*kb.i0win_tab(dely - inyold-m2)*kb.i0win_tab(delz - inzold-m3);
02832                                 //cout << "OO  "<<m1<<"  "<< m2<<"  "<< m3<<"  "<< q<<"  "<< q<<"  "<<(*this)(inxold+m1,inyold+m2,inzold+m3)<< endl;
02833                                 pixel += (*this)(inxold+m1,inyold+m2,inzold+m3)*q; w+=q;}}
02834                         }
02835                 }
02836         }
02837         return pixel/w;
02838 }

float EMData::get_pixel_conv7 ( float  delx,
float  dely,
float  delz,
Util::KaiserBessel kb 
)

Definition at line 2918 of file emdata_sparx.cpp.

References get_data(), get_pixel_conv_new(), get_xsize(), get_ysize(), get_zsize(), nx, ny, and nz.

02918                                                                                        {
02919 //  here counting is in C style, so coordinates of the pixel delx should be [0-nx-1]
02920 
02921         float *image=(this->get_data());
02922         int nx = this->get_xsize();
02923         int ny = this->get_ysize();
02924         int nz = this->get_zsize();
02925 
02926         float result;
02927 
02928         result = Util::get_pixel_conv_new(nx,ny,nz,delx,dely,delz,image,kb);
02929         return result;
02930 }

float EMData::get_pixel_filtered ( float  delx,
float  dely,
float  delz,
Util::sincBlackman kb 
)

Definition at line 2841 of file emdata_sparx.cpp.

References EMAN::Util::sincBlackman::get_sB_size(), nx, ny, q, EMAN::Util::round(), EMAN::Util::sincBlackman::sBwin_tab(), and t.

02841                                                                                           {
02842 //  here counting is in C style, so coordinates of the pixel delx should be [0-nx-1]
02843 
02844         int K     = kb.get_sB_size();
02845         int kbmin = -K/2;
02846         int kbmax = -kbmin;
02847         int kbc   = kbmax+1;
02848 
02849         float pixel =0.0f;
02850         float w=0.0f;
02851 
02852         //delx = restrict2(delx, nx);   //  In this function the old location is always within the      image
02853         int inxold = int(Util::round(delx));
02854         /*if(ny<2) {  //1D
02855                 if(inxold <= kbc || inxold >=nx-kbc-2 )  {
02856                         //  loop for ends
02857                         for (int m1 =kbmin; m1 <=kbmax; m1++) {
02858                                 float q = kb.sBwin_tab(delx - inxold-m1);
02859                                 pixel += (*this)((inxold+m1+nx)%nx)*q; w+=q;
02860                         }
02861                 } else {
02862                         for (int m1 =kbmin; m1 <=kbmax; m1++) {
02863                                 float q = kb.sBwin_tab(delx - inxold-m1);
02864                                 pixel += (*this)(inxold+m1)*q; w+=q;
02865                         }
02866                 }
02867 
02868         } else if(nz<2) {  // 2D*/
02869                 //dely = restrict2(dely, ny);
02870                 int inyold = int(Util::round(dely));
02871                 if(inxold <= kbc || inxold >=nx-kbc-2 || inyold <= kbc || inyold >=ny-kbc-2 )  {
02872                         //  loop for strips
02873                         for (int m2 =kbmin; m2 <=kbmax; m2++){
02874                                 float t = kb.sBwin_tab(dely - inyold-m2);
02875                                 for (int m1 =kbmin; m1 <=kbmax; m1++) {
02876                                         float q = kb.sBwin_tab(delx - inxold-m1)*t;
02877                                         pixel += (*this)((inxold+m1+nx)%nx,(inyold+m2+ny)%ny)*q;
02878                                         w += q;
02879                                 }
02880                         }
02881                 } else {
02882                         for (int m2 =kbmin; m2 <=kbmax; m2++){
02883                                 float t = kb.sBwin_tab(dely - inyold-m2);
02884                                 for (int m1 =kbmin; m1 <=kbmax; m1++) {
02885                                         float q = kb.sBwin_tab(delx - inxold-m1)*t;
02886                                         pixel += (*this)(inxold+m1,inyold+m2)*q;
02887                                         w += q;
02888                                 }
02889                         }
02890                 }
02891         /*} else {  //  3D
02892                 dely = restrict2(dely, ny);
02893                 int inyold = int(Util::round(dely));
02894                 delz = restrict2(delz, nz);
02895                 int inzold = int(Util::round(delz));
02896                     //cout << inxold<<"  "<< kbc<<"  "<< nx-kbc-2<<"  "<< endl;
02897                 if(inxold <= kbc || inxold >=nx-kbc-2 || inyold <= kbc || inyold >=ny-kbc-2  || inzold <= kbc || inzold >=nz-kbc-2 )  {
02898                         //  loop for strips
02899                         for (int m3 =kbmin; m3 <=kbmax; m3++){ for (int m2 =kbmin; m2 <=kbmax; m2++){ for (int m1 =kbmin; m1 <=kbmax; m1++) {
02900                                 float q = kb.sBwin_tab(delx - inxold-m1)*kb.sBwin_tab(dely - inyold-m2)*kb.sBwin_tab(delz - inzold-m3);
02901                                 //cout << "BB  "<<m1<<"  "<< m2<<"  "<< m3<<"  "<< q<<"  "<< q<<"  "<<(*this)((inxold+m1+nx)%nx,(inyold+m2+ny)%ny,(inzold+m3+nz)%nz)<< endl;
02902                                 pixel += (*this)((inxold+m1+nx)%nx,(inyold+m2+ny)%ny,(inzold+m3+nz)%nz)*q ;w+=q;}}
02903                         }
02904                 } else {
02905                         for (int m3 =kbmin; m3 <=kbmax; m3++){ for (int m2 =kbmin; m2 <=kbmax; m2++){ for (int m1 =kbmin; m1 <=kbmax; m1++) {
02906                                 float q = kb.sBwin_tab(delx - inxold-m1)*kb.sBwin_tab(dely - inyold-m2)*kb.sBwin_tab(delz - inzold-m3);
02907                                 //cout << "OO  "<<m1<<"  "<< m2<<"  "<< m3<<"  "<< q<<"  "<< q<<"  "<<(*this)(inxold+m1,inyold+m2,inzold+m3)<< endl;
02908                                 pixel += (*this)(inxold+m1,inyold+m2,inzold+m3)*q; w+=q;}}
02909                         }
02910                 }
02911         }*/
02912         return pixel/w;
02913 }

EMData * EMData::get_pow ( float  n_pow  ) 

Definition at line 4877 of file emdata_sparx.cpp.

References copy_head(), get_data(), in, nx, ny, and nz.

04878 {
04879         EMData* buf_new = this->copy_head();
04880         float *in  = this->get_data();
04881         float *out = buf_new->get_data();
04882         for(int i=0; i<nx*ny*nz; i++) out[i] = pow(in[i],n_pow);
04883         return buf_new;
04884 }

EMData * EMData::get_rotated_clip ( const Transform xform,
const IntSize size,
float  scale = 1.0 
)

This will extract an arbitrarily oriented and sized region from the image.

Parameters:
xform The transformation of the region.
size Size of the clip.
scale Scaling put on the returned image.
Returns:
The clip image.

Definition at line 674 of file emdata.cpp.

References EMData(), nx, ny, nz, set_size(), set_value_at(), sget_value_at_interp(), EMAN::Transform::transform(), update(), v, x, and y.

00676 {
00677         EMData *result = new EMData();
00678         result->set_size(size[0],size[1],size[2]);
00679 
00680         if (nz==1) {
00681                 for (int y=-size[1]/2; y<(size[1]+1)/2; y++) {
00682                         for (int x=-size[0]/2; x<(size[0]+1)/2; x++) {
00683                                 Vec3f xv=xform.transform(Vec3f((float)x,(float)y,0.0f));
00684                                 float v = 0;
00685 
00686                                 if (xv[0]<0||xv[1]<0||xv[0]>nx-2||xv[1]>ny-2) v=0.;
00687                                 else v=sget_value_at_interp(xv[0],xv[1]);
00688                                 result->set_value_at(x+size[0]/2,y+size[1]/2,v);
00689                         }
00690                 }
00691         }
00692         else {
00693                 for (int z=-size[2]/2; z<(size[2]+1)/2; z++) {
00694                         for (int y=-size[1]/2; y<(size[1]+1)/2; y++) {
00695                                 for (int x=-size[0]/2; x<(size[0]+1)/2; x++) {
00696                                         Vec3f xv=xform.transform(Vec3f((float)x,(float)y,0.0f));
00697                                         float v = 0;
00698 
00699                                         if (xv[0]<0||xv[1]<0||xv[2]<0||xv[0]>nx-2||xv[1]>ny-2||xv[2]>nz-2) v=0.;
00700                                         else v=sget_value_at_interp(xv[0],xv[1],xv[2]);
00701                                         result->set_value_at(x+size[0]/2,y+size[1]/2,z+size[2]/2,v);
00702                                 }
00703                         }
00704                 }
00705         }
00706         result->update();
00707 
00708         return result;
00709 }

EMData * EMData::get_row ( int  row_index  )  const

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

Parameters:
row_index Index of the row.
Exceptions:
ImageDimensionException If this image is 3D.
Returns:
A 1D image with the row data.

Definition at line 659 of file emdata_core.cpp.

References EMData(), ENTERFUNC, EXITFUNC, get_data(), get_ndim(), ImageDimensionException, nx, set_size(), and update().

Referenced by EMAN::CCDNormProcessor::process_inplace().

00660 {
00661         ENTERFUNC;
00662 
00663         if (get_ndim() > 2) {
00664                 throw ImageDimensionException("1D/2D image only");
00665         }
00666 
00667         EMData *ret = new EMData();
00668         ret->set_size(nx, 1, 1);
00669         memcpy(ret->get_data(), get_data() + nx * row_index, nx * sizeof(float));
00670         ret->update();
00671         EXITFUNC;
00672         return ret;
00673 }

size_t EMAN::EMData::get_size (  )  const [inline]

Get the number of allocated floats in the image (nx*ny*nz).

Returns:
nx*ny*nz

Definition at line 860 of file emdata.h.

References EMAN::EMData::ClipInplaceVariables::new_nz, EMAN::EMData::ClipInplaceVariables::prv_z_top, and EMAN::EMData::ClipInplaceVariables::z_iter.

Referenced by calc_fast_sigma_image(), EMAN::TomoDotCmp::cmp(), operator==(), EMAN::BinaryOperateProcessor< Type >::process_inplace(), EMAN::HistogramBin::process_inplace(), EMAN::ClampingProcessor::process_inplace(), EMAN::AutoMask3D2Processor::process_inplace(), EMAN::AutoMask2DProcessor::process_inplace(), EMAN::AddNoiseProcessor::process_inplace(), EMAN::BinarizeFourierProcessor::process_inplace(), EMAN::NormalizeByMassProcessor::process_inplace(), EMAN::WatershedProcessor::process_inplace(), and to_value().

00862                                 {
00863                                         prv_z_top = prv_nz - new_nz - ztrans;

int EMData::get_supp_pickle (  )  const

Definition at line 1181 of file emdata_metadata.cpp.

01182 {
01183         return 0;
01184 }

EMData * EMData::get_top_half (  )  const

Get the top half of this 3D image.

Exceptions:
ImageDimensionException If this image is not 3D.
Returns:
The top half of this image.

Definition at line 648 of file emdata.cpp.

References attr_dict, EMAN::EMUtil::em_memcpy(), EMData(), ENTERFUNC, EXITFUNC, get_data(), get_ndim(), ImageDimensionException, nx, ny, nz, set_size(), and update().

00649 {
00650         ENTERFUNC;
00651 
00652         if (get_ndim() != 3) {
00653                 throw ImageDimensionException("3D only");
00654         }
00655 
00656         EMData *half = new EMData();
00657         half->attr_dict = attr_dict;
00658         half->set_size(nx, ny, nz / 2);
00659 
00660         float *half_data = half->get_data();
00661         EMUtil::em_memcpy(half_data, &(get_data()[nz / 2 * nx * ny]), sizeof(float) * nx * ny * nz / 2);
00662 
00663         float apix_z = attr_dict["apix_z"];
00664         float origin_z = attr_dict["origin_z"];
00665         origin_z += apix_z * nz / 2;
00666         half->attr_dict["origin_z"] = origin_z;
00667         half->update();
00668 
00669         EXITFUNC;
00670         return half;
00671 }

Transform EMAN::EMData::get_transform (  )  const [inline]

Get the 3D orientation of 'this' image.

Returns:
The 3D orientation of 'this' image.

Definition at line 545 of file emdata.h.

00749                                           {

Vec3f EMAN::EMData::get_translation (  )  const [inline]

Get 'this' image's translation vector from the original location.

Returns:
'this' image's translation vector from the original location.

Definition at line 514 of file emdata.h.

00749                                           {

float EMAN::EMData::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:
i 1D data array index.
Returns:
The pixel density value

Definition at line 1869 of file emdata.h.

float EMAN::EMData::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:
x The x cooridinate.
y The y cooridinate.
Returns:
The pixel density value at coordinates (x,y).

Definition at line 1856 of file emdata.h.

float EMAN::EMData::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:
x The x cooridinate.
y The y cooridinate.
z The z cooridinate.
Returns:
The pixel density value at coordinates (x,y,z).

Definition at line 1843 of file emdata.h.

Referenced by EMAN::MinMaxAverager::add_image(), EMAN::BoxingTools::auto_correlation_pick(), bispecRotTransInvDirect(), bispecRotTransInvN(), calc_fast_sigma_image(), EMAN::XYZCmp::cmp(), common_lines(), EMAN::BoxingTools::find_radial_max(), EMAN::WatershedProcessor::find_region(), find_region(), EMAN::BoxingTools::get_min_delta_profile(), EMAN::MarchingCubes::get_normal(), wustl_mm::SkeletonMaker::VolumeData::GetDataAt(), EMAN::BoxingTools::hi_brid(), EMAN::nn4Reconstructor::insert_slice(), EMAN::BoxingTools::is_local_maximum(), make_footprint(), EMAN::MarchingCubes::marching_cube(), EMAN::PointArray::match_points(), printImage(), EMAN::DirectionalSumProcessor::process(), EMAN::TransposeProcessor::process(), EMAN::BooleanShrinkProcessor::process(), EMAN::KmeansSegmentProcessor::process(), EMAN::TomoTiltEdgeMaskProcessor::process_inplace(), EMAN::Rotate180Processor::process_inplace(), EMAN::WaveletProcessor::process_inplace(), EMAN::CCDNormProcessor::process_inplace(), EMAN::TransposeProcessor::process_inplace(), EMAN::RealToFFTProcessor::process_inplace(), EMAN::FlattenBackgroundProcessor::process_inplace(), EMAN::BooleanShrinkProcessor::process_inplace(), EMAN::BoxingTools::set_region(), and EMAN::WatershedProcessor::watershed().

float & EMData::get_value_at_wrap ( int  x  ) 

Definition at line 739 of file emdata_core.cpp.

References get_data(), and nx.

00740 {
00741         if (x < 0) x = nx + x;
00742         return get_data()[x];
00743 }

float EMData::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:
x The x cooridinate.
Returns:
The pixel density value at circulant coordinates (x).

Definition at line 766 of file emdata_core.cpp.

References get_data(), and nx.

00767 {
00768         if (x < 0) x = nx - x;
00769         return get_data()[x];
00770 }

float & EMData::get_value_at_wrap ( int  x,
int  y 
)

Definition at line 745 of file emdata_core.cpp.

References get_data(), nx, and ny.

00746 {
00747         if (x < 0) x = nx + x;
00748         if (y < 0) y = ny + y;
00749 
00750         return get_data()[x + y * nx];
00751 }

float EMData::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:
x The x cooridinate.
y The y cooridinate.
Returns:
The pixel density value at circulant coordinates (x,y).

Definition at line 772 of file emdata_core.cpp.

References get_data(), nx, and ny.

00773 {
00774         if (x < 0) x = nx - x;
00775         if (y < 0) y = ny - y;
00776 
00777         return get_data()[x + y * nx];
00778 }

float & EMData::get_value_at_wrap ( int  x,
int  y,
int  z 
)

Definition at line 753 of file emdata_core.cpp.

References get_data(), nx, nxy, ny, and nz.

00754 {
00755         int lx = x;
00756         int ly = y;
00757         int lz = z;
00758         if (lx < 0) lx = nx + lx;
00759         if (ly < 0) ly = ny + ly;
00760         if (lz < 0) lz = nz + lz;
00761 
00762         return get_data()[lx + ly * nx + lz * nxy];
00763 }

float EMData::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:
x The x cooridinate.
y The y cooridinate.
z The z cooridinate.
Returns:
The pixel density value at circulant coordinates (x,y,z).

Definition at line 780 of file emdata_core.cpp.

References get_data(), nx, nxy, ny, and nz.

Referenced by calc_max_location_wrap(), EMAN::TomoDotCmp::cmp(), and zero_corner_circulant().

00781 {
00782         int lx = x;
00783         int ly = y;
00784         int lz = z;
00785         if (lx < 0) lx = nx + lx;
00786         if (ly < 0) ly = ny + ly;
00787         if (lz < 0) lz = nz + lz;
00788 
00789         return get_data()[lx + ly * nx + lz * nxy];
00790 }

int EMAN::EMData::get_xoff (  )  const [inline]

Definition at line 1208 of file emdata.h.

int EMAN::EMData::get_xsize (  )  const [inline]

Get the image x-dimensional size.

Returns:
Image x-dimensional size.

Definition at line 833 of file emdata.h.

Referenced by absi(), EMAN::MeanShrinkProcessor::accrue_mean(), EMAN::MeanShrinkProcessor::accrue_mean_one_p_five(), EMAN::MedianShrinkProcessor::accrue_median(), add(), EMAN::file_store::add_image(), EMAN::newfile_store::add_image(), EMAN::CtfAverager::add_image(), EMAN::CtfCWautoAverager::add_image(), EMAN::Util::add_img(), EMAN::Util::add_img2(), EMAN::Util::add_img_abs(), EMAN::Util::addn_img(), addsquare(), ali3d_d(), EMAN::Refine3DAligner::align(), EMAN::RefineAligner::align(), EMAN::RTFSlowExhaustiveAligner::align(), EMAN::RTFExhaustiveAligner::align(), EMAN::RotationalAligner::align_180_ambiguous(), amplitude(), EMAN::SVDAnalyzer::analyze(), apmd(), apmq(), EMAN::BoxingTools::auto_correlation_pick(), EMAN::PawelProjector::backproject3d(), EMAN::ChaoProjector::backproject3d(), bispecRotTransInvDirect(), bispecRotTransInvN(), EMAN::nn4_ctfReconstructor::buildFFTVolume(), EMAN::nn4Reconstructor::buildFFTVolume(), EMAN::nn4_ctfReconstructor::buildNormVolume(), EMAN::nn4Reconstructor::buildNormVolume(), calc_ccf(), calc_ccfx(), calc_dist(), calc_fast_sigma_image(), calc_flcf(), calc_fourier_shell_correlation(), calc_max_location_wrap(), EMAN::NormalizeLREdgeMeanProcessor::calc_mean(), EMAN::NormalizeMaskProcessor::calc_mean(), calc_mutual_correlation(), EMAN::NormalizeMaskProcessor::calc_sigma(), EMAN::NormalizeUnitSumProcessor::calc_sigma(), EMAN::MarchingCubes::calculate_min_max_vals(), circumference(), EMAN::Util::cluster_equalsize(), EMAN::Util::cluster_pairwise(), cm_euc(), EMAN::Util::cml_prepare_line(), EMAN::XYZCmp::cmp(), EMAN::FRCCmp::cmp(), EMAN::PhaseCmp::cmp(), EMAN::OptVarianceCmp::cmp(), EMAN::QuadMinDotCmp::cmp(), EMAN::DotCmp::cmp(), EMAN::SqEuclideanCmp::cmp(), EMAN::CccCmp::cmp(), common_lines(), EMAN::Util::compress_image_mask(), EMAN::EMAN2Ctf::compute_2d_complex(), EMAN::EMAN1Ctf::compute_2d_complex(), convolute(), EMAN::LowpassAutoBProcessor::create_radial_func(), cut_slice(), EMAN::Util::cyclicshift(), EMAN::Util::decimate(), div(), EMAN::Util::div_filter(), EMAN::Util::div_img(), EMAN::Util::divn_filter(), EMAN::Util::divn_img(), EMAN::FourierReconstructor::do_compare_slice_work(), EMAN::FourierReconstructor::do_insert_slice_work(), EMAN::PCA::dopca_ooc(), EMAN::MarchingCubes::draw_cube(), EMAN::TestUtil::dump_emdata(), EMAN::Processor::EMFourierFilterFunc(), EMAN::FFTResampleProcessor::fft_resample(), FH2F(), EMAN::filt_dilation_(), EMAN::filt_erosion_(), EMAN::filt_median_(), filter_by_image(), find_group(), EMAN::BoxingTools::find_radial_max(), EMAN::WatershedProcessor::find_region(), find_region(), EMAN::CtfCWautoAverager::finish(), EMAN::IterationAverager::finish(), EMAN::ImageAverager::finish(), EMAN::Phase180Processor::fourier_phaseshift180(), EMAN::fourierproduct(), EMAN::Util::get_biggest_cluster(), EMAN::IntTranslateProcessor::get_clip_region(), EMAN::file_store::get_image(), EMAN::newfile_store::get_image(), EMAN::BoxingTools::get_min_delta_profile(), get_pixel_conv7(), EMAN::Util::get_slice(), wustl_mm::SkeletonMaker::VolumeData::GetSizeX(), EMAN::BoxingTools::hi_brid(), EMAN::Util::histc(), EMAN::Util::histogram(), imag(), EMAN::Util::image_mutation(), EMAN::Util::infomask(), EMAN::FourierPixelInserter3D::init(), EMAN::nn4_ctfReconstructor::insert_buffed_slice(), insert_clip(), EMAN::SVDAnalyzer::insert_image(), EMAN::PCAlarge::insert_image(), EMAN::PCAsmall::insert_image(), insert_scaled_sum(), EMAN::nnSSNR_ctfReconstructor::insert_slice(), EMAN::nn4_ctfReconstructor::insert_slice(), EMAN::nnSSNR_Reconstructor::insert_slice(), EMAN::nn4Reconstructor::insert_slice(), EMAN::BackProjectionReconstructor::insert_slice(), EMAN::FourierReconstructorSimple2D::insert_slice(), EMAN::GaussFFTProjector::interp_ft_3d(), EMAN::BoxingTools::is_local_maximum(), EMAN::EMUtil::is_same_size(), EMAN::PCA::Lanczos_ooc(), little_big_dot(), EMAN::Util::mad_scalar(), EMAN::Util::madn_scalar(), main(), make_footprint(), EMAN::EMUtil::make_image_median(), make_rotational_footprint_cmc(), make_rotational_footprint_e1(), EMAN::MarchingCubes::marching_cube(), EMAN::PointArray::match_points(), max_search(), EMAN::Util::min_dist_real(), EMAN::Util::move_points(), EMAN::Util::mul_img(), EMAN::Util::mul_scalar(), EMAN::Util::muln_img(), mult(), mult_complex_efficient(), mult_radial(), EMAN::Util::mult_scalar(), norm_pad(), EMAN::Util::Normalize_ring(), operator==(), EMAN::Util::pack_complex_to_real(), EMAN::Util::pad(), EMAN::padfft_slice(), peak_ccf(), peak_search(), EMAN::periodogram(), phase(), EMAN::Util::Polar2D(), EMAN::Util::Polar2Dm(), EMAN::Util::Polar2Dmi(), EMAN::TestImageProcessor::preprocess(), EMAN::FourierReconstructor::preprocess_slice(), print_image(), printImage(), EMAN::ScaleTransformProcessor::process(), EMAN::TransformProcessor::process(), EMAN::DirectionalSumProcessor::process(), EMAN::TransposeProcessor::process(), EMAN::BooleanShrinkProcessor::process(), EMAN::MeanShrinkProcessor::process(), EMAN::MedianShrinkProcessor::process(), EMAN::KmeansSegmentProcessor::process(), EMAN::XYZProcessor::process_inplace(), EMAN::BinaryOperateProcessor< Type >::process_inplace(), EMAN::ApplyPolynomialProfileToHelix::process_inplace(), EMAN::ModelEMCylinderProcessor::process_inplace(), EMAN::ZGradientProcessor::process_inplace(), EMAN::YGradientProcessor::process_inplace(), EMAN::TomoTiltEdgeMaskProcessor::process_inplace(), EMAN::XGradientProcessor::process_inplace(), EMAN::ConvolutionProcessor::process_inplace(), EMAN::TestTomoImage::process_inplace(), EMAN::Rotate180Processor::process_inplace(), EMAN::ScaleTransformProcessor::process_inplace(), EMAN::TransformProcessor::process_inplace(), EMAN::MirrorProcessor::process_inplace(), EMAN::RadialProcessor::process_inplace(), EMAN::WaveletProcessor::process_inplace(), EMAN::CCDNormProcessor::process_inplace(), EMAN::RampProcessor::process_inplace(), EMAN::TestImageCylinder::process_inplace(), EMAN::TestImagePureGaussian::process_inplace(), EMAN::TestImageScurve::process_inplace(), EMAN::TestImageLineWave::process_inplace(), EMAN::TestImageFourierNoiseProfile::process_inplace(), EMAN::CTFSNRWeightProcessor::process_inplace(), EMAN::TestImageFourierNoiseGaussian::process_inplace(), EMAN::IterBinMaskProcessor::process_inplace(), EMAN::AutoMask3D2Processor::process_inplace(), EMAN::AutoMask3DProcessor::process_inplace(), EMAN::SmartMaskProcessor::process_inplace(), EMAN::CoordinateMaskFileProcessor::process_inplace(), EMAN::SymSearchProcessor::process_inplace(), EMAN::FileFourierProcessor::process_inplace(), EMAN::SNRProcessor::process_inplace(), EMAN::ACFCenterProcessor::process_inplace(), EMAN::ToMassCenterProcessor::process_inplace(), EMAN::AddMaskShellProcessor::process_inplace(), EMAN::AddRandomNoiseProcessor::process_inplace(), EMAN::AutoMask2DProcessor::process_inplace(), EMAN::AutoMaskAsymUnit::process_inplace(), EMAN::PhaseToCenterProcessor::process_inplace(), EMAN::PhaseToCornerProcessor::process_inplace(), EMAN::FourierToCenterProcessor::process_inplace(), EMAN::FourierToCornerProcessor::process_inplace(), EMAN::FlipProcessor::process_inplace(), EMAN::TransposeProcessor::process_inplace(), EMAN::RotationalSubstractProcessor::process_inplace(), EMAN::RotationalAverageProcessor::process_inplace(), EMAN::BilateralProcessor::process_inplace(), EMAN::NormalizeToLeastSquareProcessor::process_inplace(), EMAN::NormalizeRowProcessor::process_inplace(), EMAN::NormalizeRampNormVar::process_inplace(), EMAN::NormalizeProcessor::process_inplace(), EMAN::ZeroEdgePlaneProcessor::process_inplace(), EMAN::ZeroEdgeRowProcessor::process_inplace(), EMAN::DecayEdgeProcessor::process_inplace(), EMAN::AverageXProcessor::process_inplace(), EMAN::MeanZeroEdgeProcessor::process_inplace(), EMAN::BeamstopProcessor::process_inplace(), EMAN::SigmaZeroEdgeProcessor::process_inplace(), EMAN::RealToFFTProcessor::process_inplace(), EMAN::VerticalStripeProcessor::process_inplace(), EMAN::GradientPlaneRemoverProcessor::process_inplace(), EMAN::FlattenBackgroundProcessor::process_inplace(), EMAN::GradientRemoverProcessor::process_inplace(), EMAN::BooleanShrinkProcessor::process_inplace(), EMAN::MeanShrinkProcessor::process_inplace(), EMAN::MedianShrinkProcessor::process_inplace(), EMAN::CutoffBlockProcessor::process_inplace(), EMAN::DiffBlockProcessor::process_inplace(), EMAN::BoxStatProcessor::process_inplace(), EMAN::AreaProcessor::process_inplace(), EMAN::ComplexPixelProcessor::process_inplace(), EMAN::ToMinvalProcessor::process_inplace(), EMAN::PaintProcessor::process_inplace(), EMAN::CoordinateProcessor::process_inplace(), EMAN::RealPixelProcessor::process_inplace(), EMAN::Wiener2DFourierProcessor::process_inplace(), EMAN::Wiener2DAutoAreaProcessor::process_inplace(), EMAN::LinearPyramidProcessor::process_inplace(), EMAN::AmpweightFourierProcessor::process_inplace(), EMAN::FourierAnlProcessor::process_inplace(), EMAN::FourierProcessor::process_inplace(), EMAN::ChaoProjector::project3d(), EMAN::FourierGriddingProjector::project3d(), EMAN::StandardProjector::project3d(), EMAN::PawelProjector::project3d(), EMAN::GaussFFTProjector::project3d(), ReadVandBcast(), real(), real2complex(), real2FH(), EMAN::Util::reconstitute_image_mask(), refalifnfast(), replace_amplitudes(), EMAN::rsconvolution(), EMAN::PointArray::set_from_density_map(), EMAN::Util::set_line(), EMAN::SVDAnalyzer::set_params(), EMAN::varimax::set_params(), EMAN::PCAlarge::set_params(), EMAN::PCAsmall::set_params(), EMAN::BoxingTools::set_radial_non_zero(), EMAN::BoxingTools::set_region(), EMAN::WienerFourierReconstructor::setup(), EMAN::FourierReconstructor::setup_seed(), sub(), EMAN::Util::sub_img(), EMAN::Util::subn_img(), subsquare(), EMAN::Phase180Processor::swap_central_slices_180(), EMAN::Phase180Processor::swap_corners_180(), EMAN::TransformProcessor::transform(), uncut_slice(), unified(), unwrap_largerR(), EMAN::EMUtil::vertical_acf(), EMAN::WatershedProcessor::watershed(), and EMAN::Util::window().

int EMAN::EMData::get_yoff (  )  const [inline]

Definition at line 1213 of file emdata.h.

int EMAN::EMData::get_ysize (  )  const [inline]

Get the image y-dimensional size.

Returns:
Image y-dimensional size.

Definition at line 842 of file emdata.h.

References EMAN::EMData::ClipInplaceVariables::x_iter, and EMAN::EMData::ClipInplaceVariables::y_iter.

Referenced by absi(), EMAN::MeanShrinkProcessor::accrue_mean(), EMAN::MeanShrinkProcessor::accrue_mean_one_p_five(), EMAN::MedianShrinkProcessor::accrue_median(), add(), EMAN::file_store::add_image(), EMAN::newfile_store::add_image(), EMAN::CtfAverager::add_image(), EMAN::CtfCWautoAverager::add_image(), EMAN::Util::add_img(), EMAN::Util::add_img2(), EMAN::Util::add_img_abs(), EMAN::Util::addn_img(), addsquare(), ali3d_d(), EMAN::RTFExhaustiveAligner::align(), EMAN::RotatePrecenterAligner::align(), EMAN::RotationalAligner::align_180_ambiguous(), amplitude(), EMAN::SVDAnalyzer::analyze(), apmd(), apmq(), EMAN::BoxingTools::auto_correlation_pick(), EMAN::PawelProjector::backproject3d(), EMAN::ChaoProjector::backproject3d(), EMAN::nn4_ctfReconstructor::buildFFTVolume(), EMAN::nn4Reconstructor::buildFFTVolume(), EMAN::nn4_ctfReconstructor::buildNormVolume(), EMAN::nn4Reconstructor::buildNormVolume(), calc_ccf(), calc_ccfx(), calc_dist(), calc_fast_sigma_image(), calc_flcf(), calc_fourier_shell_correlation(), calc_max_location_wrap(), EMAN::NormalizeLREdgeMeanProcessor::calc_mean(), EMAN::NormalizeMaskProcessor::calc_mean(), calc_mutual_correlation(), EMAN::NormalizeMaskProcessor::calc_sigma(), EMAN::NormalizeUnitSumProcessor::calc_sigma(), EMAN::MarchingCubes::calculate_min_max_vals(), circumference(), EMAN::XYZCmp::cmp(), EMAN::FRCCmp::cmp(), EMAN::PhaseCmp::cmp(), EMAN::OptVarianceCmp::cmp(), EMAN::QuadMinDotCmp::cmp(), EMAN::DotCmp::cmp(), EMAN::SqEuclideanCmp::cmp(), EMAN::CccCmp::cmp(), common_lines(), EMAN::Util::compress_image_mask(), EMAN::EMAN2Ctf::compute_2d_complex(), EMAN::EMAN1Ctf::compute_2d_complex(), convolute(), EMAN::MatchSFProcessor::create_radial_func(), cut_slice(), EMAN::Util::cyclicshift(), EMAN::Util::decimate(), div(), EMAN::Util::div_filter(), EMAN::Util::div_img(), EMAN::Util::divn_filter(), EMAN::Util::divn_img(), EMAN::FourierReconstructor::do_compare_slice_work(), do_fft(), do_ift(), EMAN::FourierReconstructor::do_insert_slice_work(), EMAN::MarchingCubes::draw_cube(), EMAN::TestUtil::dump_emdata(), EMAN::Processor::EMFourierFilterFunc(), EMAN::FFTResampleProcessor::fft_resample(), FH2F(), EMAN::filt_dilation_(), EMAN::filt_erosion_(), EMAN::filt_median_(), filter_by_image(), find_group(), EMAN::BoxingTools::find_radial_max(), EMAN::WatershedProcessor::find_region(), find_region(), EMAN::FourierReconstructor::finish(), EMAN::CtfCWautoAverager::finish(), EMAN::IterationAverager::finish(), EMAN::ImageAverager::finish(), EMAN::Phase180Processor::fourier_phaseshift180(), EMAN::fourierproduct(), EMAN::Util::get_biggest_cluster(), EMAN::IntTranslateProcessor::get_clip_region(), get_fft_amplitude(), get_fft_phase(), EMAN::file_store::get_image(), EMAN::BoxingTools::get_min_delta_profile(), get_pixel_conv7(), EMAN::Util::get_slice(), wustl_mm::SkeletonMaker::VolumeData::GetSizeY(), EMAN::BoxingTools::hi_brid(), EMAN::Util::histc(), EMAN::Util::histogram(), imag(), EMAN::Util::infomask(), EMAN::FourierPixelInserter3D::init(), insert_clip(), EMAN::SVDAnalyzer::insert_image(), insert_scaled_sum(), EMAN::nnSSNR_ctfReconstructor::insert_slice(), EMAN::nn4_ctfReconstructor::insert_slice(), EMAN::nnSSNR_Reconstructor::insert_slice(), EMAN::nn4Reconstructor::insert_slice(), EMAN::BackProjectionReconstructor::insert_slice(), EMAN::GaussFFTProjector::interp_ft_3d(), EMAN::BoxingTools::is_local_maximum(), EMAN::EMUtil::is_same_size(), little_big_dot(), EMAN::Util::mad_scalar(), EMAN::Util::madn_scalar(), main(), make_footprint(), EMAN::EMUtil::make_image_median(), make_rotational_footprint_cmc(), make_rotational_footprint_e1(), EMAN::MarchingCubes::marching_cube(), max_search(), EMAN::Util::min_dist_real(), EMAN::Util::move_points(), EMAN::Util::mul_img(), EMAN::Util::mul_scalar(), EMAN::Util::muln_img(), mult(), mult_complex_efficient(), EMAN::Util::mult_scalar(), norm_pad(), EMAN::Util::Normalize_ring(), operator==(), EMAN::Util::pack_complex_to_real(), EMAN::Util::pad(), EMAN::padfft_slice(), peak_ccf(), peak_search(), EMAN::periodogram(), phase(), EMAN::Util::Polar2D(), EMAN::Util::Polar2Dm(), EMAN::Util::Polar2Dmi(), EMAN::TestImageProcessor::preprocess(), EMAN::FourierReconstructor::preprocess_slice(), print_image(), printImage(), EMAN::ScaleTransformProcessor::process(), EMAN::TransformProcessor::process(), EMAN::DirectionalSumProcessor::process(), EMAN::TransposeProcessor::process(), EMAN::BooleanShrinkProcessor::process(), EMAN::MeanShrinkProcessor::process(), EMAN::MedianShrinkProcessor::process(), EMAN::KmeansSegmentProcessor::process(), EMAN::XYZProcessor::process_inplace(), EMAN::BinaryOperateProcessor< Type >::process_inplace(), EMAN::ApplyPolynomialProfileToHelix::process_inplace(), EMAN::ModelEMCylinderProcessor::process_inplace(), EMAN::ZGradientProcessor::process_inplace(), EMAN::YGradientProcessor::process_inplace(), EMAN::TomoTiltEdgeMaskProcessor::process_inplace(), EMAN::XGradientProcessor::process_inplace(), EMAN::ConvolutionProcessor::process_inplace(), EMAN::TestTomoImage::process_inplace(), EMAN::Rotate180Processor::process_inplace(), EMAN::ScaleTransformProcessor::process_inplace(), EMAN::TransformProcessor::process_inplace(), EMAN::MirrorProcessor::process_inplace(), EMAN::RadialProcessor::process_inplace(), EMAN::WaveletProcessor::process_inplace(), EMAN::CCDNormProcessor::process_inplace(), EMAN::RampProcessor::process_inplace(), EMAN::TestImageCylinder::process_inplace(), EMAN::TestImagePureGaussian::process_inplace(), EMAN::TestImageScurve::process_inplace(), EMAN::TestImageLineWave::process_inplace(), EMAN::TestImageFourierNoiseProfile::process_inplace(), EMAN::CTFSNRWeightProcessor::process_inplace(), EMAN::TestImageFourierNoiseGaussian::process_inplace(), EMAN::IterBinMaskProcessor::process_inplace(), EMAN::AutoMask3D2Processor::process_inplace(), EMAN::AutoMask3DProcessor::process_inplace(), EMAN::SmartMaskProcessor::process_inplace(), EMAN::CoordinateMaskFileProcessor::process_inplace(), EMAN::SymSearchProcessor::process_inplace(), EMAN::LocalNormProcessor::process_inplace(), EMAN::SNRProcessor::process_inplace(), EMAN::ToMassCenterProcessor::process_inplace(), EMAN::AddMaskShellProcessor::process_inplace(), EMAN::AddRandomNoiseProcessor::process_inplace(), EMAN::AutoMask2DProcessor::process_inplace(), EMAN::AutoMaskAsymUnit::process_inplace(), EMAN::PhaseToCenterProcessor::process_inplace(), EMAN::PhaseToCornerProcessor::process_inplace(), EMAN::FourierToCenterProcessor::process_inplace(), EMAN::FourierToCornerProcessor::process_inplace(), EMAN::FlipProcessor::process_inplace(), EMAN::TransposeProcessor::process_inplace(), EMAN::RotationalSubstractProcessor::process_inplace(), EMAN::RotationalAverageProcessor::process_inplace(), EMAN::BilateralProcessor::process_inplace(), EMAN::NormalizeToLeastSquareProcessor::process_inplace(), EMAN::NormalizeRowProcessor::process_inplace(), EMAN::NormalizeProcessor::process_inplace(), EMAN::ZeroEdgePlaneProcessor::process_inplace(), EMAN::ZeroEdgeRowProcessor::process_inplace(), EMAN::DecayEdgeProcessor::process_inplace(), EMAN::AverageXProcessor::process_inplace(), EMAN::MeanZeroEdgeProcessor::process_inplace(), EMAN::BeamstopProcessor::process_inplace(), EMAN::SigmaZeroEdgeProcessor::process_inplace(), EMAN::RealToFFTProcessor::process_inplace(), EMAN::VerticalStripeProcessor::process_inplace(), EMAN::GradientPlaneRemoverProcessor::process_inplace(), EMAN::FlattenBackgroundProcessor::process_inplace(), EMAN::GradientRemoverProcessor::process_inplace(), EMAN::BooleanShrinkProcessor::process_inplace(), EMAN::MeanShrinkProcessor::process_inplace(), EMAN::MedianShrinkProcessor::process_inplace(), EMAN::CutoffBlockProcessor::process_inplace(), EMAN::DiffBlockProcessor::process_inplace(), EMAN::BoxStatProcessor::process_inplace(), EMAN::AreaProcessor::process_inplace(), EMAN::ComplexPixelProcessor::process_inplace(), EMAN::ToMinvalProcessor::process_inplace(), EMAN::PaintProcessor::process_inplace(), EMAN::CoordinateProcessor::process_inplace(), EMAN::RealPixelProcessor::process_inplace(), EMAN::Wiener2DFourierProcessor::process_inplace(), EMAN::Wiener2DAutoAreaProcessor::process_inplace(), EMAN::LinearPyramidProcessor::process_inplace(), EMAN::AmpweightFourierProcessor::process_inplace(), EMAN::SNREvalProcessor::process_inplace(), EMAN::FourierAnlProcessor::process_inplace(), EMAN::FourierProcessor::process_inplace(), EMAN::ChaoProjector::project3d(), EMAN::FourierGriddingProjector::project3d(), EMAN::StandardProjector::project3d(), EMAN::PawelProjector::project3d(), EMAN::GaussFFTProjector::project3d(), ReadVandBcast(), real(), real2complex(), real2FH(), EMAN::Util::reconstitute_image_mask(), refalifnfast(), replace_amplitudes(), EMAN::rsconvolution(), EMAN::PointArray::set_from_density_map(), EMAN::SVDAnalyzer::set_params(), EMAN::varimax::set_params(), EMAN::PCAlarge::set_params(), EMAN::PCAsmall::set_params(), EMAN::BoxingTools::set_radial_non_zero(), EMAN::BoxingTools::set_region(), EMAN::WienerFourierReconstructor::setup(), EMAN::FourierReconstructor::setup_seed(), sub(), EMAN::Util::sub_img(), EMAN::Util::subn_img(), subsquare(), EMAN::Phase180Processor::swap_central_slices_180(), EMAN::Phase180Processor::swap_corners_180(), EMAN::TransformProcessor::transform(), uncut_slice(), unified(), unwrap_largerR(), EMAN::Util::vareas(), EMAN::EMUtil::vertical_acf(), EMAN::WatershedProcessor::watershed(), and EMAN::Util::window().

00842                                                                                                                                                                                                           :
00843                                         prv_nx(p_nx), prv_ny(p_ny), prv_nz(p_nz), new_nx(n_nx), new_ny(n_ny), new_nz(n_nz), xshift(xtrans), yshift(ytrans), zshift(ztrans),
00844                                  x_iter(prv_nx), y_iter(prv_ny), z_iter(prv_nz), new_z_top(0), new_z_bottom(0),  new_y_back(0), new_y_front(0),new_x_left(0), new_x_right(0),
00845                                 prv_z_top(0), prv_z_bottom(0), prv_y_back(0), prv_y_front(0), prv_x_left(0), prv_x_right(0)
                        {

int EMAN::EMData::get_zoff (  )  const [inline]

Definition at line 1218 of file emdata.h.

int EMAN::EMData::get_zsize (  )  const [inline]

Get the image z-dimensional size.

Returns:
Image z-dimensional size.

Definition at line 851 of file emdata.h.

Referenced by absi(), EMAN::MeanShrinkProcessor::accrue_mean(), EMAN::MedianShrinkProcessor::accrue_median(), add(), EMAN::file_store::add_image(), EMAN::CtfAverager::add_image(), EMAN::Util::add_img(), EMAN::Util::add_img2(), EMAN::Util::add_img_abs(), EMAN::Util::addn_img(), addsquare(), ali3d_d(), amplitude(), EMAN::SVDAnalyzer::analyze(), apmd(), apmq(), EMAN::ChaoProjector::backproject3d(), EMAN::nn4_ctfReconstructor::buildFFTVolume(), EMAN::nn4Reconstructor::buildFFTVolume(), EMAN::nn4_ctfReconstructor::buildNormVolume(), EMAN::nn4Reconstructor::buildNormVolume(), calc_ccf(), calc_ccfx(), calc_fast_sigma_image(), calc_flcf(), calc_fourier_shell_correlation(), calc_max_location_wrap(), EMAN::NormalizeLREdgeMeanProcessor::calc_mean(), EMAN::NormalizeMaskProcessor::calc_mean(), calc_mutual_correlation(), EMAN::NormalizeMaskProcessor::calc_sigma(), EMAN::NormalizeUnitSumProcessor::calc_sigma(), EMAN::MarchingCubes::calculate_min_max_vals(), circumference(), EMAN::FRCCmp::cmp(), EMAN::PhaseCmp::cmp(), EMAN::OptVarianceCmp::cmp(), EMAN::QuadMinDotCmp::cmp(), EMAN::DotCmp::cmp(), EMAN::SqEuclideanCmp::cmp(), EMAN::CccCmp::cmp(), EMAN::Util::compress_image_mask(), convolute(), cut_slice(), EMAN::Util::cyclicshift(), EMAN::Util::decimate(), div(), EMAN::Util::div_filter(), EMAN::Util::div_img(), EMAN::Util::divn_filter(), EMAN::Util::divn_img(), do_fft(), do_ift(), EMAN::MarchingCubes::draw_cube(), EMAN::TestUtil::dump_emdata(), EMAN::Processor::EMFourierFilterFunc(), EMAN::FFTResampleProcessor::fft_resample(), FH2F(), EMAN::filt_dilation_(), EMAN::filt_erosion_(), EMAN::filt_median_(), filter_by_image(), find_group(), EMAN::WatershedProcessor::find_region(), find_region(), EMAN::FourierReconstructor::finish(), EMAN::IterationAverager::finish(), EMAN::ImageAverager::finish(), EMAN::Phase180Processor::fourier_phaseshift180(), EMAN::fourierproduct(), EMAN::Util::get_biggest_cluster(), EMAN::IntTranslateProcessor::get_clip_region(), get_fft_amplitude(), get_fft_phase(), EMAN::file_store::get_image(), get_pixel_conv7(), EMAN::Util::get_slice(), wustl_mm::SkeletonMaker::VolumeData::GetSizeZ(), EMAN::Util::histc(), EMAN::Util::histogram(), imag(), EMAN::Util::infomask(), EMAN::FourierPixelInserter3D::init(), insert_clip(), EMAN::SVDAnalyzer::insert_image(), insert_scaled_sum(), EMAN::GaussFFTProjector::interp_ft_3d(), EMAN::EMUtil::is_same_size(), EMAN::Util::mad_scalar(), EMAN::Util::madn_scalar(), main(), EMAN::EMUtil::make_image_median(), make_rotational_footprint_cmc(), make_rotational_footprint_e1(), EMAN::MarchingCubes::marching_cube(), max_search(), EMAN::Util::move_points(), EMAN::Util::mul_img(), EMAN::Util::mul_scalar(), EMAN::Util::muln_img(), mult(), mult_complex_efficient(), EMAN::Util::mult_scalar(), norm_pad(), EMAN::Util::Normalize_ring(), operator==(), EMAN::Util::pack_complex_to_real(), EMAN::Util::pad(), peak_search(), EMAN::periodogram(), phase(), EMAN::Util::Polar2Dmi(), EMAN::TestImageProcessor::preprocess(), print_image(), printImage(), EMAN::ScaleTransformProcessor::process(), EMAN::TransformProcessor::process(), EMAN::DirectionalSumProcessor::process(), EMAN::BooleanShrinkProcessor::process(), EMAN::MeanShrinkProcessor::process(), EMAN::MedianShrinkProcessor::process(), EMAN::KmeansSegmentProcessor::process(), EMAN::XYZProcessor::process_inplace(), EMAN::BinaryOperateProcessor< Type >::process_inplace(), EMAN::ApplyPolynomialProfileToHelix::process_inplace(), EMAN::ModelEMCylinderProcessor::process_inplace(), EMAN::ZGradientProcessor::process_inplace(), EMAN::YGradientProcessor::process_inplace(), EMAN::XGradientProcessor::process_inplace(), EMAN::ConvolutionProcessor::process_inplace(), EMAN::TestTomoImage::process_inplace(), EMAN::ScaleTransformProcessor::process_inplace(), EMAN::TransformProcessor::process_inplace(), EMAN::MirrorProcessor::process_inplace(), EMAN::RadialProcessor::process_inplace(), EMAN::WaveletProcessor::process_inplace(), EMAN::CCDNormProcessor::process_inplace(), EMAN::RampProcessor::process_inplace(), EMAN::TestImageCylinder::process_inplace(), EMAN::TestImagePureGaussian::process_inplace(), EMAN::TestImageLineWave::process_inplace(), EMAN::TestImageFourierNoiseProfile::process_inplace(), EMAN::CTFSNRWeightProcessor::process_inplace(), EMAN::TestImageFourierNoiseGaussian::process_inplace(), EMAN::IterBinMaskProcessor::process_inplace(), EMAN::AutoMask3D2Processor::process_inplace(), EMAN::AutoMask3DProcessor::process_inplace(), EMAN::SmartMaskProcessor::process_inplace(), EMAN::CoordinateMaskFileProcessor::process_inplace(), EMAN::SymSearchProcessor::process_inplace(), EMAN::ToMassCenterProcessor::process_inplace(), EMAN::AddMaskShellProcessor::process_inplace(), EMAN::AddRandomNoiseProcessor::process_inplace(), EMAN::AutoMaskAsymUnit::process_inplace(), EMAN::PhaseToCenterProcessor::process_inplace(), EMAN::PhaseToCornerProcessor::process_inplace(), EMAN::FourierToCenterProcessor::process_inplace(), EMAN::FourierToCornerProcessor::process_inplace(), EMAN::FlipProcessor::process_inplace(), EMAN::RotationalAverageProcessor::process_inplace(), EMAN::BilateralProcessor::process_inplace(), EMAN::NormalizeToLeastSquareProcessor::process_inplace(), EMAN::NormalizeRowProcessor::process_inplace(), EMAN::NormalizeProcessor::process_inplace(), EMAN::ZeroEdgePlaneProcessor::process_inplace(), EMAN::ZeroEdgeRowProcessor::process_inplace(), EMAN::DecayEdgeProcessor::process_inplace(), EMAN::AverageXProcessor::process_inplace(), EMAN::MeanZeroEdgeProcessor::process_inplace(), EMAN::BeamstopProcessor::process_inplace(), EMAN::SigmaZeroEdgeProcessor::process_inplace(), EMAN::RealToFFTProcessor::process_inplace(), EMAN::VerticalStripeProcessor::process_inplace(), EMAN::GradientPlaneRemoverProcessor::process_inplace(), EMAN::FlattenBackgroundProcessor::process_inplace(), EMAN::GradientRemoverProcessor::process_inplace(), EMAN::BooleanShrinkProcessor::process_inplace(), EMAN::MeanShrinkProcessor::process_inplace(), EMAN::MedianShrinkProcessor::process_inplace(), EMAN::CutoffBlockProcessor::process_inplace(), EMAN::DiffBlockProcessor::process_inplace(), EMAN::BoxStatProcessor::process_inplace(), EMAN::AreaProcessor::process_inplace(), EMAN::ComplexPixelProcessor::process_inplace(), EMAN::ToMinvalProcessor::process_inplace(), EMAN::PaintProcessor::process_inplace(), EMAN::CoordinateProcessor::process_inplace(), EMAN::RealPixelProcessor::process_inplace(), EMAN::Wiener2DFourierProcessor::process_inplace(), EMAN::Wiener2DAutoAreaProcessor::process_inplace(), EMAN::LinearPyramidProcessor::process_inplace(), EMAN::AmpweightFourierProcessor::process_inplace(), EMAN::FourierAnlProcessor::process_inplace(), EMAN::FourierProcessor::process_inplace(), EMAN::ChaoProjector::project3d(), EMAN::FourierGriddingProjector::project3d(), EMAN::StandardProjector::project3d(), EMAN::PawelProjector::project3d(), EMAN::GaussFFTProjector::project3d(), ReadVandBcast(), real(), real2complex(), real2FH(), EMAN::Util::reconstitute_image_mask(), replace_amplitudes(), EMAN::rsconvolution(), EMAN::PointArray::set_from_density_map(), EMAN::SVDAnalyzer::set_params(), EMAN::varimax::set_params(), EMAN::PCAlarge::set_params(), EMAN::PCAsmall::set_params(), EMAN::WienerFourierReconstructor::setup(), EMAN::FourierReconstructor::setup_seed(), sub(), EMAN::Util::sub_img(), EMAN::Util::subn_img(), subsquare(), EMAN::Phase180Processor::swap_central_slices_180(), EMAN::Phase180Processor::swap_corners_180(), EMAN::TransformProcessor::transform(), uncut_slice(), unified(), EMAN::WatershedProcessor::watershed(), and EMAN::Util::window().

00862                                 {

float EMData::getconvpt2d_kbi0 ( float  x,
float  y,
Util::KaiserBessel::kbi0_win  win,
int  size = 7 
)

Value of 2-D analytic masking (or 2-D convolution) at off-grid point.

The only requirement for the window function object is that it overload operator()(const float) and return a float.

Parameters:
[in] x x-value of the desired (potentially off-grid) point
[in] y y-value of the desired (potentially off-grid) point
[in] win Window (mask/kernel) function object.
[in] size Size of real-space kernel/mask.
Returns:
Value of masked/convolved image at (x,y)

Definition at line 2932 of file emdata_sparx.cpp.

References abs, get_array_offsets(), InvalidValueException, nx, ny, set_array_offsets(), and EMAN::Util::sgn().

02932                                                                                        {
02933         const int nxhalf = nx/2;
02934         const int nyhalf = ny/2;
02935         const int bd = size/2;
02936         float* wxarr = new float[size];
02937         float* wyarr = new float[size];
02938         float* wx = wxarr + bd; // wx[-bd] = wxarr[0]
02939         float* wy = wyarr + bd;
02940         int ixc = int(x + 0.5f*Util::sgn(x));
02941         int iyc = int(y + 0.5f*Util::sgn(y));
02942         if (abs(ixc) > nxhalf)
02943                 throw InvalidValueException(ixc, "getconv: X value out of range");
02944         if (abs(iyc) > nyhalf)
02945                 throw InvalidValueException(ixc, "getconv: Y value out of range");
02946         for (int i = -bd; i <= bd; i++) {
02947                 int iyp = iyc + i;
02948                 wy[i] = win(y - iyp);
02949                 int ixp = ixc + i;
02950                 wx[i] = win(x - ixp);
02951         }
02952         vector<int> saved_offsets = get_array_offsets();
02953         set_array_offsets(-nxhalf, -nyhalf);
02954         float conv = 0.f, wsum = 0.f;
02955         for (int iy = -bd; iy <= bd; iy++) {
02956                 int iyp = iyc + iy;
02957                 for (int ix = -bd; ix <= bd; ix++) {
02958                         int ixp = ixc + ix;
02959                         float wg = wx[ix]*wy[iy];
02960                         conv += (*this)(ixp,iyp)*wg;
02961                         wsum += wg;
02962                 }
02963         }
02964         set_array_offsets(saved_offsets);
02965         delete [] wxarr;
02966         delete [] wyarr;
02967         //return conv/wsum;
02968         return conv;
02969 }

int EMAN::EMData::getResolution (  )  const [inline]

function for MarchingCubes, for 3D image display

Returns:
the resolution

Definition at line 3720 of file emdata.h.

bool EMAN::EMData::has_attr ( const string &  key  )  const [inline]

Ask if the header has a particular attribute.

Parameters:
key the header attribute name
Returns:
whether or not the header has the name as a key/value entry

Definition at line 795 of file emdata.h.

Referenced by EMAN::FRCCmp::cmp(), EMAN::PhaseCmp::cmp(), EMAN::SqEuclideanCmp::cmp(), EMAN::FourierPixelInserter3D::init(), EMAN::BackProjectionReconstructor::insert_slice(), and EMAN::NormalizeByMassProcessor::process_inplace().

00797                                                                           : is the CPU version of the image out out data

bool EMAN::EMData::has_ctff (  )  const [inline]

check whether the image physical file has the CTF info or not.

Returns:
True if it has the CTF information. Otherwise, false.

Definition at line 398 of file emdata.h.

Referenced by EMAN::EMUtil::is_same_ctf().

00428                           : this routine will modify the 'this' and 'with' to contain

EMData * EMData::helicise ( float  pixel_size,
float  dp,
float  dphi,
float  section_use = 1.0f,
float  radius = -1.0f,
float  minrad = -1.0f 
)

Apply helical symmetry.

Works only for a volume.

Parameters:
[in] pixel_size,: pixel size in Angstroms.
[in] dp,: repeat in z direction in Angstroms.
[in] dphi,: angular repeat in degrees.
[in] section_use,: how much of z section to use for symmetrization (between zero and one).
[in] radius,: radius of the structure (default nx/2-1).
Returns:
New image

Definition at line 4937 of file emdata_sparx.cpp.

References copy_head(), DGR_TO_RAD, get_ndim(), ImageDimensionException, ImageFormatException, InvalidValueException, is_complex(), min, nx, ny, nz, to_zero(), and update().

04937                                                                                                               {
04938         if (3 != get_ndim())
04939                 throw ImageDimensionException("helicise needs a 3-D image.");
04940         if (is_complex())
04941                 throw ImageFormatException("helicise requires a real image");
04942 
04943         EMData* result = this->copy_head();
04944         result->to_zero();
04945         int nyc = ny/2;
04946         int nxc = nx/2;
04947         int nb = int(nx*(1.0f - section_use)/2.);
04948         int ne = nx - nb -1;
04949         int numst = int((ne - nb)/dp*pixel_size + 0.5);
04950         // how many steps needed
04951         int nst = int(nz*pixel_size/dp+0.5);
04952         float r2, ir;
04953         if(radius < 0.0f) r2 = (float)((nxc-1)*(nxc-1));
04954         else r2 = radius*radius;
04955         if(minrad < 0.0f) ir = 0.0f;
04956         else ir = minrad*minrad;
04957         for (int k = 0; k<nz; k++) {
04958                 for (int j = 0; j<ny; j++) {
04959                         int jy = j - nyc;
04960                         int jj = jy*jy;
04961                         for (int i = 0; i<nx; i++) {
04962                                 int ix = i - nxc;
04963                                 float d2 = (float)(ix*ix + jj);
04964                                 if(d2 <= r2 && d2>=ir) {
04965                                         int nq = 1;
04966                                         for ( int ist = -nst; ist <= nst; ist++) {
04967                                                 float zold = (k*pixel_size + ist*dp)/pixel_size;
04968                                                 int IOZ = int(zold);
04969                                                 if(IOZ >= nb && IOZ <= ne) {
04970                                                         // now x-y position
04971                                                         float cphi = ist*dphi*(float)DGR_TO_RAD;
04972                                                         float ca = cos(cphi);
04973                                                         float sa = sin(cphi);
04974                                                         float xold = ix*ca - jy*sa + nxc;
04975                                                         float yold = ix*sa + jy*ca + nyc;
04976                                                         nq++;
04977 
04978 
04979                                         //  Do tri-linear interpolation
04980                                         int IOX = int(xold);
04981                                         int IOY = int(yold);
04982                                         //int IOZ = int(zold);
04983 
04984                                         #ifdef _WIN32
04985                                         int IOXp1 = _MIN( nx-1 ,IOX+1);
04986                                         #else
04987                                         int IOXp1 = std::min( nx-1 ,IOX+1);
04988                                         #endif  //_WIN32
04989 
04990                                         #ifdef _WIN32
04991                                         int IOYp1 = _MIN( ny-1 ,IOY+1);
04992                                         #else
04993                                         int IOYp1 = std::min( ny-1 ,IOY+1);
04994                                         #endif  //_WIN32
04995 
04996                                         #ifdef _WIN32
04997                                         int IOZp1 = _MIN( nz-1 ,IOZ+1);
04998                                         #else
04999                                         int IOZp1 = std::min( nz-1 ,IOZ+1);
05000                                         #endif  //_WIN32
05001 
05002                                         float dx = xold-IOX;
05003                                         float dy = yold-IOY;
05004                                         float dz = zold-IOZ;
05005 
05006                                         float a1 = (*this)(IOX,IOY,IOZ);
05007                                         float a2 = (*this)(IOXp1,IOY,IOZ) - (*this)(IOX,IOY,IOZ);
05008                                         float a3 = (*this)(IOX,IOYp1,IOZ) - (*this)(IOX,IOY,IOZ);
05009                                         float a4 = (*this)(IOX,IOY,IOZp1) - (*this)(IOX,IOY,IOZ);
05010                                         float a5 = (*this)(IOX,IOY,IOZ) - (*this)(IOXp1,IOY,IOZ) - (*this)(IOX,IOYp1,IOZ) + (*this)(IOXp1,IOYp1,IOZ);
05011                                         float a6 = (*this)(IOX,IOY,IOZ) - (*this)(IOXp1,IOY,IOZ) - (*this)(IOX,IOY,IOZp1) + (*this)(IOXp1,IOY,IOZp1);
05012                                         float a7 = (*this)(IOX,IOY,IOZ) - (*this)(IOX,IOYp1,IOZ) - (*this)(IOX,IOY,IOZp1) + (*this)(IOX,IOYp1,IOZp1);
05013                                         float a8 = (*this)(IOXp1,IOY,IOZ) + (*this)(IOX,IOYp1,IOZ)+ (*this)(IOX,IOY,IOZp1)
05014                                                         - (*this)(IOX,IOY,IOZ)- (*this)(IOXp1,IOYp1,IOZ) - (*this)(IOXp1,IOY,IOZp1)
05015                                                         - (*this)(IOX,IOYp1,IOZp1) + (*this)(IOXp1,IOYp1,IOZp1);
05016                                         (*result)(i,j,k) += a1 + dz*(a4 + a6*dx + (a7 + a8*dx)*dy) + a3*dy + dx*(a2 + a5*dy);
05017 
05018                                                         //(*result)(i,j,k) += (*this)(IOX, IOY, IOZ);
05019                                                         if(nq == numst) break;
05020                                                 }
05021                                         }
05022                                         if(nq != numst)
05023                                                 throw InvalidValueException(nq, "incorrect number of repeats encoutered.");
05024                                 }
05025                         }
05026                 }
05027         }
05028         for (int k = 0; k<nz; k++) for (int j = 0; j<ny; j++) for (int i = 0; i<nx; i++) (*result)(i,j,k) /= numst ;
05029 
05030         result->update();
05031         return result;
05032 }

EMData * 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:
InvalidCallException if this image is a real image
InvalidCallException if this image is a complex image in amplitude/phase format

Definition at line 1093 of file emdata_core.cpp.

References data, EMData(), ENTERFUNC, EXITFUNC, get_data(), get_xsize(), get_ysize(), get_zsize(), InvalidCallException, is_real(), is_ri(), nx, ny, nz, set_complex(), set_complex_x(), set_size(), and update().

Referenced by real2FH().

01094 {
01095         ENTERFUNC;
01096 
01097         EMData * e = new EMData();
01098 
01099         if( is_real() ) {       //a real image has no imaginary part, throw exception
01100                 throw InvalidCallException("No imaginary part for a real image, this function call require a complex image.");
01101         }
01102         else {  //for complex image
01103                 if( !is_ri() ) {
01104                         throw InvalidCallException("This image is in amplitude/phase format, this function call require a complex image in real/imaginary format.");
01105                 }
01106                 int nx = get_xsize();
01107                 int ny = get_ysize();
01108                 int nz = get_zsize();
01109                 e->set_size(nx/2, ny, nz);
01110                 float * edata = e->get_data();
01111                 float * data = get_data();
01112                 for( int i=0; i<nx; i++ ) {
01113                         for( int j=0; j<ny; j++ ) {
01114                                 for( int k=0; k<nz; k++ ) {
01115                                         if( i%2 == 1 ) {
01116                                                 //complex data in format [real, complex, real, complex...]
01117                                                 edata[i/2+j*(nx/2)+k*(nx/2)*ny] = data[i+j*nx+k*nx*ny];
01118                                         }
01119                                 }
01120                         }
01121                 }
01122         }
01123 
01124         e->set_complex(false);
01125         if(e->get_ysize()==1 && e->get_zsize()==1) {
01126                 e->set_complex_x(false);
01127         }
01128         e->update();
01129         return e;
01130 
01131         EXITFUNC;
01132 }

void EMData::insert_scaled_sum ( EMData block,
const FloatPoint center,
float  scale = 1.0,
float  mult_factor = 1.0 
)

Add a scaled image into another image at a specified location.

This is used, for example, to accumulate gaussians in programs like pdb2mrc.py. The center of 'block' will be positioned at 'center' with scale factor 'scale'. Densities will be interpolated in 'block' and multiplied by 'mult'.

Parameters:
block The image to inserted.
center The center of the inserted block in 'this'.
scale Scale factor.
mult_factor Number used to multiply the block's densities.
Exceptions:
ImageDimensionException If 'this' image is not 2D/3D.

Definition at line 1810 of file emdata_transform.cpp.

References data, ENTERFUNC, EXITFUNC, get_data(), get_ndim(), get_xsize(), get_ysize(), get_zsize(), ImageDimensionException, LOGERR, nx, ny, sget_value_at_interp(), update(), x, and y.

01812 {
01813         ENTERFUNC;
01814         float * data = get_data();
01815         if (get_ndim()==3) {
01816                 // Start by determining the region to operate on
01817                 int xs=(int)floor(block->get_xsize()*scale/2.0);
01818                 int ys=(int)floor(block->get_ysize()*scale/2.0);
01819                 int zs=(int)floor(block->get_zsize()*scale/2.0);
01820                 int x0=(int)center[0]-xs;
01821                 int x1=(int)center[0]+xs;
01822                 int y0=(int)center[1]-ys;
01823                 int y1=(int)center[1]+ys;
01824                 int z0=(int)center[2]-zs;
01825                 int z1=(int)center[2]+zs;
01826 
01827                 if (x1<0||y1<0||z1<0||x0>get_xsize()||y0>get_ysize()||z0>get_zsize()) return;   // object is completely outside the target volume
01828 
01829                 // make sure we stay inside the volume
01830                 if (x0<0) x0=0;
01831                 if (y0<0) y0=0;
01832                 if (z0<0) z0=0;
01833                 if (x1>=get_xsize()) x1=get_xsize()-1;
01834                 if (y1>=get_ysize()) y1=get_ysize()-1;
01835                 if (z1>=get_zsize()) z1=get_zsize()-1;
01836 
01837                 float bx=block->get_xsize()/2.0f;
01838                 float by=block->get_ysize()/2.0f;
01839                 float bz=block->get_zsize()/2.0f;
01840 
01841                 size_t idx;
01842                 for (int x=x0; x<=x1; x++) {
01843                         for (int y=y0; y<=y1; y++) {
01844                                 for (int z=z0; z<=z1; z++) {
01845                                         idx = x + y * nx + z * nx * ny;
01846                                         data[idx] +=
01847                                                 block->sget_value_at_interp((x-center[0])/scale+bx,(y-center[1])/scale+by,(z-center[2])/scale+bz);
01848                                 }
01849                         }
01850                 }
01851                 update();
01852         }
01853         else if (get_ndim()==2) {
01854                 // Start by determining the region to operate on
01855                 int xs=(int)floor(block->get_xsize()*scale/2.0);
01856                 int ys=(int)floor(block->get_ysize()*scale/2.0);
01857                 int x0=(int)center[0]-xs;
01858                 int x1=(int)center[0]+xs;
01859                 int y0=(int)center[1]-ys;
01860                 int y1=(int)center[1]+ys;
01861 
01862                 if (x1<0||y1<0||x0>get_xsize()||y0>get_ysize()) return; // object is completely outside the target volume
01863 
01864                 // make sure we stay inside the volume
01865                 if (x0<0) x0=0;
01866                 if (y0<0) y0=0;
01867                 if (x1>=get_xsize()) x1=get_xsize()-1;
01868                 if (y1>=get_ysize()) y1=get_ysize()-1;
01869 
01870                 float bx=block->get_xsize()/2.0f;
01871                 float by=block->get_ysize()/2.0f;
01872 
01873                 for (int x=x0; x<=x1; x++) {
01874                         for (int y=y0; y<=y1; y++) {
01875                                 data[x + y * nx] +=
01876                                         block->sget_value_at_interp((x-center[0])/scale+bx,(y-center[1])/scale+by);
01877                         }
01878                 }
01879                 update();
01880         }
01881         else {
01882                 LOGERR("insert_scaled_sum supports only 2D and 3D data");
01883                 throw ImageDimensionException("2D/3D only");
01884         }
01885 
01886         EXITFUNC;
01887 }

bool EMAN::EMData::is_complex (  )  const [inline]

Is this a complex image?

Returns:
Whether this is a complex image or not.

Definition at line 931 of file emdata.h.

Referenced by add(), EMAN::Util::add_img2(), add_incoherent(), EMAN::Util::addn_img(), addsquare(), ap2ri(), apply_radial_func(), calc_az_dist(), calc_fourier_shell_correlation(), calc_highest_locations(), calc_hist(), calc_max_location(), calc_min_location(), calc_n_highest_locations(), calc_radial_dist(), cconj(), center_origin(), center_origin_fft(), center_origin_yz(), EMAN::FRCCmp::cmp(), EMAN::PhaseCmp::cmp(), EMAN::DotCmp::cmp(), EMAN::SqEuclideanCmp::cmp(), EMAN::CccCmp::cmp(), common_lines(), EMAN::EMAN2Ctf::compute_2d_complex(), EMAN::EMAN1Ctf::compute_2d_complex(), EMAN::MatchSFProcessor::create_radial_func(), cut_slice(), EMAN::Util::cyclicshift(), delete_disconnected_regions(), depad(), depad_corner(), EMAN::Util::div_filter(), EMAN::Util::div_img(), divkbsinh(), EMAN::Util::divn_filter(), EMAN::Util::divn_img(), do_fft(), do_fft_inplace(), do_ift(), do_ift_inplace(), EMAN::Processor::EMFourierFilterFunc(), extract_plane(), extractline(), extractpoint(), EMAN::FFTResampleProcessor::fft_resample(), fft_shuffle(), filter_by_image(), EMAN::Phase180Processor::fourier_phaseshift180(), fouriergridrot2d(), fouriergridrot_shift2d(), EMAN::fourierproduct(), FourInterpol(), FourTruncate(), get_attr(), get_fft_amplitude(), get_fft_amplitude2D(), get_fft_phase(), helicise(), EMAN::Util::histc(), EMAN::Util::histogram(), EMAN::WienerFourierReconstructor::insert_slice(), EMAN::FourierReconstructorSimple2D::insert_slice(), log(), log10(), EMAN::Util::madn_scalar(), EMAN::Util::mul_img(), EMAN::Util::muln_img(), mult(), EMAN::Util::mult_scalar(), EMAN::periodogram(), EMAN::TransposeProcessor::process(), EMAN::BooleanShrinkProcessor::process(), EMAN::MeanShrinkProcessor::process(), EMAN::FFTResampleProcessor::process(), EMAN::MedianShrinkProcessor::process(), EMAN::Wiener2DAutoAreaProcessor::process(), EMAN::ZGradientProcessor::process_inplace(), EMAN::YGradientProcessor::process_inplace(), EMAN::XGradientProcessor::process_inplace(), EMAN::ClampingProcessor::process_inplace(), EMAN::RadialProcessor::process_inplace(), EMAN::TestImageFourierNoiseProfile::process_inplace(), EMAN::CTFSNRWeightProcessor::process_inplace(), EMAN::TestImageFourierNoiseGaussian::process_inplace(), EMAN::AddRandomNoiseProcessor::process_inplace(), EMAN::PhaseToCenterProcessor::process_inplace(), EMAN::PhaseToCornerProcessor::process_inplace(), EMAN::FourierToCenterProcessor::process_inplace(), EMAN::FourierToCornerProcessor::process_inplace(), EMAN::TransposeProcessor::process_inplace(), EMAN::RotationalSubstractProcessor::process_inplace(), EMAN::RotationalAverageProcessor::process_inplace(), EMAN::BinarizeFourierProcessor::process_inplace(), EMAN::NormalizeRampNormVar::process_inplace(), EMAN::NormalizeProcessor::process_inplace(), EMAN::RealToFFTProcessor::process_inplace(), EMAN::BooleanShrinkProcessor::process_inplace(), EMAN::MeanShrinkProcessor::process_inplace(), EMAN::FFTResampleProcessor::process_inplace(), EMAN::MedianShrinkProcessor::process_inplace(), EMAN::ComplexPixelProcessor::process_inplace(), EMAN::CoordinateProcessor::process_inplace(), EMAN::AmpweightFourierProcessor::process_inplace(), EMAN::FourierAnlProcessor::process_inplace(), EMAN::FourierProcessor::process_inplace(), EMAN::ImageProcessor::process_inplace(), EMAN::FourierGriddingProjector::project3d(), EMAN::GaussFFTProjector::project3d(), real2complex(), real2FH(), render_amp24(), render_ap24(), replace_amplitudes(), ri2ap(), ri2inten(), setup4slice(), EMAN::FourierReconstructor::setup_seed(), sqrt(), sub(), EMAN::Util::subn_img(), subsquare(), to_one(), to_zero(), uncut_slice(), update_stat(), window_center(), and write_image().

bool EMAN::EMData::is_complex_x (  )  const [inline]

Is this image a 1D FFT image in X direction?

Returns:
Whether this image is a 1D FFT image in X direction.

Definition at line 1010 of file emdata.h.

Referenced by calc_ccfx().

bool EMAN::EMData::is_fftodd (  )  const [inline]

Does this image correspond to a (real-space) odd nx?

Returns:
Whether this image has a (real-space) odd nx.

Definition at line 1147 of file emdata.h.

Referenced by EMAN::Util::addn_img(), calc_fourier_shell_correlation(), cconj(), center_origin_fft(), EMAN::DotCmp::cmp(), EMAN::SqEuclideanCmp::cmp(), depad(), depad_corner(), EMAN::Util::divn_img(), do_fft_inplace(), do_ift(), do_ift_inplace(), EMAN::Processor::EMFourierFilterFunc(), filter_by_image(), fouriergridrot2d(), fouriergridrot_shift2d(), EMAN::fourierproduct(), EMAN::Util::madn_scalar(), EMAN::Util::muln_img(), EMAN::Util::mult_scalar(), nn_SSNR(), nn_SSNR_ctf(), EMAN::Util::pack_complex_to_real(), EMAN::periodogram(), replace_amplitudes(), EMAN::Util::subn_img(), and window_center().

bool EMAN::EMData::is_fftpadded (  )  const [inline]

Is this image already extended along x for ffts?

Returns:
Whether this image is extended along x for ffts.

Definition at line 1114 of file emdata.h.

Referenced by do_fft_inplace(), and window_center().

bool EMAN::EMData::is_FH (  )  const [inline]

Is this a FH image?

Returns:
Whether this is a FH image or not.

Definition at line 914 of file emdata.h.

bool EMAN::EMData::is_flipped (  )  const [inline]

Is this image flipped?

Returns:
Whether this image is flipped or not.

Definition at line 1044 of file emdata.h.

bool EMAN::EMData::is_real (  )  const [inline]

Is this a real image?

Returns:
Whether this is image is real (not complex) or not.

Definition at line 950 of file emdata.h.

Referenced by absi(), add(), amplitude(), div(), EMAN::fourierproduct(), imag(), mult(), mult_complex_efficient(), phase(), real(), and sub().

bool EMAN::EMData::is_ri (  )  const [inline]

Is this image a real/imaginary format complex image?

Returns:
Whether this image is real/imaginary format complex image.

Definition at line 1080 of file emdata.h.

Referenced by absi(), amplitude(), ap2ri(), calc_az_dist(), calc_highest_locations(), calc_max_location(), calc_min_location(), calc_n_highest_locations(), calc_radial_dist(), cconj(), center_origin_fft(), do_ift(), do_ift_inplace(), imag(), phase(), real(), ri2ap(), ri2inten(), and update_stat().

bool EMAN::EMData::is_shuffled (  )  const [inline]

Has this image been shuffled?

Returns:
Whether this image has been shuffled to put origin in the center.

Definition at line 897 of file emdata.h.

Referenced by fft_shuffle(), fouriergridrot2d(), fouriergridrot_shift2d(), and write_image().

EMData * EMData::little_big_dot ( EMData little_img,
bool  do_sigma = false 
)

This does a normalized dot product of a little image with a big image using real-space methods.

The result is the same size as 'this', but a border 1/2 the size of 'little_img' will be zero. This routine is only efficient when 'little_img' is fairly small.

Parameters:
little_img A small image.
do_sigma Calculate sigma or not.
Exceptions:
ImageDimensionException If the image is not 1D/2D.
Returns:
normalized dot product image.

Definition at line 1247 of file emdata.cpp.

References copy_head(), data, dot(), ENTERFUNC, EXITFUNC, get_attr(), get_data(), get_edge_mean(), get_ndim(), get_xsize(), get_ysize(), ImageDimensionException, nx, ny, nz, set_size(), sqrt(), EMAN::Util::square(), square, to_zero(), and update().

01248 {
01249         ENTERFUNC;
01250 
01251         if (get_ndim() > 2) {
01252                 throw ImageDimensionException("1D/2D only");
01253         }
01254 
01255         EMData *ret = copy_head();
01256         ret->set_size(nx,ny,nz);
01257         ret->to_zero();
01258 
01259         int nx2 = with->get_xsize();
01260         int ny2 = with->get_ysize();
01261         float em = with->get_edge_mean();
01262 
01263         float *data = get_data();
01264         float *with_data = with->get_data();
01265         float *ret_data = ret->get_data();
01266 
01267         float sum2 = (Util::square((float)with->get_attr("sigma")) +
01268                                   Util::square((float)with->get_attr("mean")));
01269         if (do_sigma) {
01270                 for (int j = ny2 / 2; j < ny - ny2 / 2; j++) {
01271                         for (int i = nx2 / 2; i < nx - nx2 / 2; i++) {
01272                                 float sum = 0;
01273                                 float sum1 = 0;
01274                                 float summ = 0;
01275                                 int k = 0;
01276 
01277                                 for (int jj = j - ny2 / 2; jj < j + ny2 / 2; jj++) {
01278                                         for (int ii = i - nx2 / 2; ii < i + nx2 / 2; ii++) {
01279                                                 int l = ii + jj * nx;
01280                                                 sum1 += Util::square(data[l]);
01281                                                 summ += data[l];
01282                                                 sum += data[l] * with_data[k];
01283                                                 k++;
01284                                         }
01285                                 }
01286                                 float tmp_f1 = (sum1 / 2.0f - sum) / (nx2 * ny2);
01287                                 float tmp_f2 = Util::square((float)with->get_attr("mean") -
01288                                                                                         summ / (nx2 * ny2));
01289                                 ret_data[i + j * nx] = sum2 + tmp_f1 - tmp_f2;
01290                         }
01291                 }
01292         }
01293         else {
01294                 for (int j = ny2 / 2; j < ny - ny2 / 2; j++) {
01295                         for (int i = nx2 / 2; i < nx - nx2 / 2; i++) {
01296                                 float eml = 0;
01297                                 float dot = 0;
01298                                 float dot2 = 0;
01299 
01300                                 for (int ii = i - nx2 / 2; ii < i + nx2 / 2; ii++) {
01301                                         eml += data[ii + (j - ny2 / 2) * nx] + data[ii + (j + ny2 / 2 - 1) * nx];
01302                                 }
01303 
01304                                 for (int jj = j - ny2 / 2; jj < j + ny2 / 2; jj++) {
01305                                         eml += data[i - nx2 / 2 + jj * nx] + data[i + nx2 / 2 - 1 + jj * nx];
01306                                 }
01307 
01308                                 eml /= (nx2 + ny2) * 2.0f;
01309                                 int k = 0;
01310 
01311                                 for (int jj = j - ny2 / 2; jj < j + ny2 / 2; jj++) {
01312                                         for (int ii = i - nx2 / 2; ii < i + nx2 / 2; ii++) {
01313                                                 dot += (data[ii + jj * nx] - eml) * (with_data[k] - em);
01314                                                 dot2 += Util::square(data[ii + jj * nx] - eml);
01315                                                 k++;
01316                                         }
01317                                 }
01318 
01319                                 dot2 = std::sqrt(dot2);
01320 
01321                                 if (dot2 == 0) {
01322                                         ret_data[i + j * nx] = 0;
01323                                 }
01324                                 else {
01325                                         ret_data[i + j * nx] = dot / (nx2 * ny2 * dot2 * (float)with->get_attr("sigma"));
01326                                 }
01327                         }
01328                 }
01329         }
01330 
01331         ret->update();
01332 
01333         EXITFUNC;
01334         return ret;
01335 }

EMData * EMData::log (  )  const

return natural logarithm image for a image

Returns:
a image which is the natural logarithm of this image
Exceptions:
InvalidValueException pixel value must be >= 0
ImageFormatException real image only

Definition at line 980 of file emdata_core.cpp.

References copy(), data, ENTERFUNC, EXITFUNC, get_data(), ImageFormatException, InvalidValueException, is_complex(), log(), nxyz, and update().

00981 {
00982         ENTERFUNC;
00983 
00984         if (is_complex()) {
00985                 throw ImageFormatException("real image only");
00986         }
00987 
00988         EMData * r = this->copy();
00989         float * new_data = r->get_data();
00990         float * data = get_data();
00991         size_t size = nxyz;
00992         for (size_t i = 0; i < size; ++i) {
00993                 if(data[i] < 0) {
00994                         throw InvalidValueException(data[i], "pixel value must be non-negative for logrithm");
00995                 }
00996                 else {
00997                         if(data[i]) {   //do nothing with pixel has value zero
00998                                 new_data[i] = std::log(data[i]);
00999                         }
01000                 }
01001         }
01002 
01003         r->update();
01004         return r;
01005 
01006         EXITFUNC;
01007 }

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:
InvalidValueException pixel value must be >= 0
ImageFormatException real image only

Definition at line 1010 of file emdata_core.cpp.

References copy(), data, ENTERFUNC, EXITFUNC, get_data(), ImageFormatException, InvalidValueException, is_complex(), log10(), nxyz, and update().

01011 {
01012         ENTERFUNC;
01013 
01014         if (is_complex()) {
01015                 throw ImageFormatException("real image only");
01016         }
01017 
01018         EMData * r = this->copy();
01019         float * new_data = r->get_data();
01020         float * data = get_data();
01021         size_t size = nxyz;
01022         for (size_t i = 0; i < size; ++i) {
01023                 if(data[i] < 0) {
01024                         throw InvalidValueException(data[i], "pixel value must be non-negative for logrithm");
01025                 }
01026                 else {
01027                         if(data[i]) {   //do nothing with pixel has value zero
01028                                 new_data[i] = std::log10(data[i]);
01029                         }
01030                 }
01031         }
01032 
01033         r->update();
01034         return r;
01035 
01036         EXITFUNC;
01037 }

EMData * EMData::make_footprint ( int  type = 0  ) 

Makes a 'footprint' for the current image.

This is image containing a rotational & translational invariant of the parent image. The size of the resulting image depends on the selected type.

type 0- The original, default footprint derived from the rotational footprint types 1-6 - bispectrum-based types 1,3,5 - returns Fouier-like images types 2,4,6 - returns real-space-like images type 1,2 - simple r1,r2, 2-D footprints type 3,4 - r1,r2,anle 3D footprints type 5,6 - same as 1,2 but with the cube root of the final products used

Parameters:
type Select one of several possible algorithms for producing the invariants
Exceptions:
ImageFormatException If image size is not even.
Returns:
The footprint image.

Definition at line 1781 of file emdata.cpp.

References abs, calc_ccfx(), do_fft(), do_ift(), dot(), EMData(), get_clip(), get_complex_at(), get_value_at(), get_xsize(), get_ysize(), make_rotational_footprint_e1(), mult(), norm(), process_inplace(), set_complex(), set_value_at(), to_zero(), and UnexpectedBehaviorException.

01782 {
01783 //      printf("Make fp %d\n",type);
01784         if (type==0) {
01785                 EMData *un=make_rotational_footprint_e1(); // Use EMAN1's footprint strategy
01786                 if (un->get_ysize() <= 6) {
01787                         throw UnexpectedBehaviorException("In EMData::make_footprint. The rotational footprint is too small");
01788                 }
01789                 EMData *tmp=un->get_clip(Region(0,4,un->get_xsize(),un->get_ysize()-6));        // 4 and 6 are empirical
01790                 EMData *cx=tmp->calc_ccfx(tmp,0,-1,1);
01791                 EMData *fp=cx->get_clip(Region(0,0,cx->get_xsize()/2,cx->get_ysize()));
01792                 delete un;
01793                 delete tmp;
01794                 delete cx;
01795                 return fp;
01796         }
01797         else if (type==1 || type==2 ||type==5 || type==6) {
01798                 int i,j,kx,ky,lx,ly;
01799 
01800                 EMData *fft=do_fft();
01801 
01802                 // map for x,y -> radius for speed
01803                 int rmax=(get_xsize()+1)/2;
01804                 float *rmap=(float *)malloc(rmax*rmax*sizeof(float));
01805                 for (i=0; i<rmax; i++) {
01806                         for (j=0; j<rmax; j++) {
01807 #ifdef _WIN32
01808                                 rmap[i+j*rmax]=_hypotf((float)i,(float)j);
01809 #else
01810                                 rmap[i+j*rmax]=hypot((float)i,(float)j);
01811 #endif  //_WIN32
01812 //                              printf("%d\t%d\t%f\n",i,j,rmap[i+j*rmax]);
01813                         }
01814                 }
01815 
01816                 EMData *fp=new EMData(rmax*2+2,rmax*2,1);
01817                 fp->set_complex(1);
01818                 fp->to_zero();
01819 
01820                 // Two vectors in to complex space (kx,ky) and (lx,ly)
01821                 // We are computing the bispectrum, f(k).f(l).f*(k+l)
01822                 // but integrating out two dimensions, leaving |k|,|l|
01823                 for (kx=-rmax+1; kx<rmax; kx++) {
01824                         for (ky=-rmax+1; ky<rmax; ky++) {
01825                                 for (lx=-rmax+1; lx<rmax; lx++) {
01826                                         for (ly=-rmax+1; ly<rmax; ly++) {
01827                                                 int ax=kx+lx;
01828                                                 int ay=ky+ly;
01829                                                 if (abs(ax)>=rmax || abs(ay)>=rmax) continue;
01830                                                 int r1=(int)floor(.5+rmap[abs(kx)+rmax*abs(ky)]);
01831                                                 int r2=(int)floor(.5+rmap[abs(lx)+rmax*abs(ly)]);
01832 //                                              if (r1>500 ||r2>500) printf("%d\t%d\t%d\t%d\t%d\t%d\n",kx,ky,lx,ly,r1,r2);
01833 //                                              float r3=rmap[ax+rmax*ay];
01834                                                 if (r1+r2>=rmax) continue;
01835 
01836                                                 std::complex<float> p=fft->get_complex_at(kx,ky)*fft->get_complex_at(lx,ly)*conj(fft->get_complex_at(ax,ay));
01837                                                 fp->set_value_at(r1*2,r2,p.real()+fp->get_value_at(r1*2,r2));           // We keep only the real component in anticipation of zero phase sum
01838 //                                              fp->set_value_at(r1*2,rmax*2-r2-1,  fp->get_value_at(r1*2,r2));         // We keep only the real component in anticipation of zero phase sum
01839 //                                              fp->set_value_at(r1*2+1,r2,p.real()+fp->get_value_at(r1*2+1,r2));               // We keep only the real component in anticipation of zero phase sum
01840                                                 fp->set_value_at(r1*2+1,r2,fp->get_value_at(r1*2+1,r2)+1);                      // a normalization counter
01841                                         }
01842                                 }
01843                         }
01844                 }
01845 
01846                 // Normalizes the pixels based on the accumulated counts then sets the imaginary components back to zero
01847                 if (type==5 || type==6) {
01848                         for (i=0; i<rmax*2; i+=2) {
01849                                 for (j=0; j<rmax; j++) {
01850                                         float norm=fp->get_value_at(i+1,j);
01851 #ifdef _WIN32
01852                                         fp->set_value_at(i,rmax*2-j-1,pow(fp->get_value_at(i,j)/(norm==0.0f?1.0f:norm), 1.0f/3.0f));
01853                                         fp->set_value_at(i,j,pow(fp->get_value_at(i,j)/(norm==0.0f?1.0f:norm), 1.0f/3.0f));
01854 #else
01855                                         fp->set_value_at(i,rmax*2-j-1,cbrt(fp->get_value_at(i,j)/(norm==0?1.0:norm)));
01856                                         fp->set_value_at(i,j,cbrt(fp->get_value_at(i,j)/(norm==0?1.0:norm)));
01857 #endif  //_WIN32
01858                                         fp->set_value_at(i+1,j,0.0);
01859                                 }
01860                         }
01861                 }
01862                 else {
01863                         for (i=0; i<rmax*2; i+=2) {
01864                                 for (j=0; j<rmax; j++) {
01865                                         float norm=fp->get_value_at(i+1,j);
01866                                         fp->set_value_at(i,rmax*2-j-1,fp->get_value_at(i,j)/(norm==0.0f?1.0f:norm));
01867                                         fp->set_value_at(i,j,fp->get_value_at(i,j)/(norm==0.0f?1.0f:norm));
01868                                         fp->set_value_at(i+1,j,0.0);
01869                                 }
01870                         }
01871                 }
01872 
01873                 free(rmap);
01874                 if (type==2||type==6) {
01875                         EMData *f2=fp->do_ift();
01876                         if (f2->get_value_at(0,0)<0) f2->mult(-1.0f);
01877                         f2->process_inplace("xform.phaseorigin.tocorner");
01878                         delete fp;
01879                         return f2;
01880                 }
01881                 return fp;
01882         }
01883         else if (type==3 || type==4) {
01884                 int h,i,j,kx,ky,lx,ly;
01885 
01886                 EMData *fft=do_fft();
01887 
01888                 // map for x,y -> radius for speed
01889                 int rmax=(get_xsize()+1)/2;
01890                 float *rmap=(float *)malloc(rmax*rmax*sizeof(float));
01891                 for (i=0; i<rmax; i++) {
01892                         for (j=0; j<rmax; j++) {
01893 #ifdef _WIN32
01894                                 rmap[i+j*rmax]=_hypotf((float)i,(float)j);
01895 #else
01896                                 rmap[i+j*rmax]=hypot((float)i,(float)j);
01897 #endif  //_WIN32
01898 //                              printf("%d\t%d\t%f\n",i,j,rmap[i+j*rmax]);
01899                         }
01900                 }
01901 
01902                 EMData *fp=new EMData(rmax*2+2,rmax*2,16);
01903 
01904                 fp->set_complex(1);
01905                 fp->to_zero();
01906 
01907                 // Two vectors in to complex space (kx,ky) and (lx,ly)
01908                 // We are computing the bispectrum, f(k).f(l).f*(k+l)
01909                 // but integrating out two dimensions, leaving |k|,|l|
01910                 for (kx=-rmax+1; kx<rmax; kx++) {
01911                         for (ky=-rmax+1; ky<rmax; ky++) {
01912                                 for (lx=-rmax+1; lx<rmax; lx++) {
01913                                         for (ly=-rmax+1; ly<rmax; ly++) {
01914                                                 int ax=kx+lx;
01915                                                 int ay=ky+ly;
01916                                                 if (abs(ax)>=rmax || abs(ay)>=rmax) continue;
01917                                                 float rr1=rmap[abs(kx)+rmax*abs(ky)];
01918                                                 float rr2=rmap[abs(lx)+rmax*abs(ly)];
01919                                                 int r1=(int)floor(.5+rr1);
01920                                                 int r2=(int)floor(.5+rr2);
01921 //                                              if (r1>500 ||r2>500) printf("%d\t%d\t%d\t%d\t%d\t%d\n",kx,ky,lx,ly,r1,r2);
01922 //                                              float r3=rmap[ax+rmax*ay];
01923                                                 if (r1+r2>=rmax || rr1==0 ||rr2==0) continue;
01924 
01925                                                 std::complex<float> p=fft->get_complex_at(kx,ky)*fft->get_complex_at(lx,ly)*conj(fft->get_complex_at(ax,ay));
01926                                                 int dot=(int)floor((kx*lx+ky*ly)/(rr1*rr2)*7.5);                                        // projection of k on l 0-31
01927                                                 if (dot<0) dot=16+dot;
01928 //                                              int dot=(int)floor((kx*lx+ky*ly)/(rr1*rr2)*7.5+8.0);                                    // projection of k on l 0-15
01929                                                 fp->set_value_at(r1*2,r2,dot,p.real()+fp->get_value_at(r1*2,r2,dot));           // We keep only the real component in anticipation of zero phase sum
01930 //                                              fp->set_value_at(r1*2,rmax*2-r2-1,  fp->get_value_at(r1*2,r2));         // We keep only the real component in anticipation of zero phase sum
01931 //                                              fp->set_value_at(r1*2+1,r2,p.real()+fp->get_value_at(r1*2+1,r2));               // We keep only the real component in anticipation of zero phase sum
01932                                                 fp->set_value_at(r1*2+1,r2,dot,fp->get_value_at(r1*2+1,r2,dot)+1);                      // a normalization counter
01933                                         }
01934                                 }
01935                         }
01936                 }
01937 
01938                 // Normalizes the pixels based on the accumulated counts then sets the imaginary components back to zero
01939                 for (i=0; i<rmax*2; i+=2) {
01940                         for (j=0; j<rmax; j++) {
01941                                 for (h=0; h<16; h++) {
01942                                         float norm=fp->get_value_at(i+1,j,h);
01943 //                                      fp->set_value_at(i,rmax*2-j-1,h,cbrt(fp->get_value_at(i,j,h)/(norm==0?1.0:norm)));
01944 //                                      fp->set_value_at(i,j,h,cbrt(fp->get_value_at(i,j,h)/(norm==0?1.0:norm)));
01945                                         fp->set_value_at(i,rmax*2-j-1,h,(fp->get_value_at(i,j,h)/(norm==0.0f?1.0f:norm)));
01946                                         fp->set_value_at(i,j,h,(fp->get_value_at(i,j,h)/(norm==0.0f?1.0f:norm)));
01947         //                              fp->set_value_at(i,rmax*2-j-1,fp->get_value_at(i,j)/(norm==0?1.0:norm));
01948         //                              fp->set_value_at(i,j,fp->get_value_at(i,j)/(norm==0?1.0:norm));
01949                                         fp->set_value_at(i+1,j,h,0.0);
01950                                 }
01951                         }
01952                 }
01953 
01954                 free(rmap);
01955                 if (type==4) {
01956                         EMData *f2=fp->do_ift();
01957                         if (f2->get_value_at(0,0,0)<0) f2->mult(-1.0f);
01958                         f2->process_inplace("xform.phaseorigin.tocorner");
01959                         delete fp;
01960                         return f2;
01961                 }
01962                 return fp;
01963         }
01964         throw UnexpectedBehaviorException("There is not implementation for the parameters you specified");
01965 }

EMData * EMData::make_rotational_footprint_cmc ( bool  unwrap = true  ) 

Definition at line 1574 of file emdata.cpp.

References calc_mutual_correlation(), EMData(), ENTERFUNC, EXITFUNC, get_edge_mean(), get_xsize(), get_ysize(), get_zsize(), nx, ny, nz, process_inplace(), rot_fp, set_complex(), set_size(), sub(), to_one(), unwrap(), and update_stat().

Referenced by EMAN::RotationalAligner::align_180_ambiguous().

01574                                                           {
01575         ENTERFUNC;
01576         update_stat();
01577         // Note that rotational_footprint caching saves a large amount of time
01578         // but this is at the expense of memory. Note that a policy is hardcoded here,
01579         // that is that caching is only employed when premasked is false and unwrap
01580         // is true - this is probably going to be what is used in most scenarios
01581         // as advised by Steve Ludtke - In terms of performance this caching doubles the metric
01582         // generated by e2speedtest.
01583         if ( rot_fp != 0 && unwrap == true) {
01584                 return new EMData(*rot_fp);
01585         }
01586 
01587         static EMData obj_filt;
01588         EMData* filt = &obj_filt;
01589         filt->set_complex(true);
01590 
01591 
01592         // The filter object is nothing more than a cached high pass filter
01593         // Ultimately it is used an argument to the EMData::mult(EMData,prevent_complex_multiplication (bool))
01594         // function in calc_mutual_correlation. Note that in the function the prevent_complex_multiplication
01595         // set to true, which is used for speed reasons.
01596         if (filt->get_xsize() != nx+2-(nx%2) || filt->get_ysize() != ny ||
01597                    filt->get_zsize() != nz ) {
01598                 filt->set_size(nx+2-(nx%2), ny, nz);
01599                 filt->to_one();
01600 
01601                 filt->process_inplace("eman1.filter.highpass.gaussian", Dict("highpass", 1.5f/nx));
01602         }
01603 
01604         EMData *ccf = this->calc_mutual_correlation(this, true,filt);
01605         ccf->sub(ccf->get_edge_mean());
01606         EMData *result = ccf->unwrap();
01607         delete ccf; ccf = 0;
01608 
01609         EXITFUNC;
01610         if ( unwrap == true)
01611         {
01612         // this if statement reflects a strict policy of caching in only one scenario see comments at beginning of function block
01613 
01614 // Note that the if statement at the beginning of this function ensures that rot_fp is not zero, so there is no need
01615 // to throw any exception
01616 // if ( rot_fp != 0 ) throw UnexpectedBehaviorException("The rotational foot print is only expected to be cached if it is not NULL");
01617 
01618 // Here is where the caching occurs - the rot_fp takes ownsherhip of the pointer, and a deep copied EMData object is returned.
01619 // The deep copy invokes a cost in terms of CPU cycles and memory, but prevents the need for complicated memory management (reference counting)
01620                 rot_fp = result;
01621                 return new EMData(*rot_fp);
01622         }
01623         else return result;
01624 }

EMData * EMData::make_rotational_footprint_e1 ( bool  unwrap = true  ) 

Definition at line 1661 of file emdata.cpp.

References calc_mutual_correlation(), EMData(), ENTERFUNC, EXITFUNC, get_edge_mean(), get_xsize(), get_ysize(), get_zsize(), insert_clip(), nx, ny, nz, process(), process_inplace(), rot_fp, set_complex(), set_size(), sub(), to_one(), to_value(), UnexpectedBehaviorException, unwrap(), and update_stat().

Referenced by EMAN::RotationalAligner::align_180_ambiguous(), and make_footprint().

01662 {
01663         ENTERFUNC;
01664 #ifdef EMAN2_USING_CUDA
01665         if (gpu_operation_preferred()) {
01666                 EXITFUNC;
01667                 return make_rotational_footprint_cuda(unwrap);
01668         }
01669 #endif
01670 
01671         update_stat();
01672         // Note that rotational_footprint caching saves a large amount of time
01673         // but this is at the expense of memory. Note that a policy is hardcoded here,
01674         // that is that caching is only employed when premasked is false and unwrap
01675         // is true - this is probably going to be what is used in most scenarios
01676         // as advised by Steve Ludtke - In terms of performance this caching doubles the metric
01677         // generated by e2speedtest.
01678         if ( rot_fp != 0 && unwrap == true) {
01679                 return new EMData(*rot_fp);
01680         }
01681 
01682         static EMData obj_filt;
01683         EMData* filt = &obj_filt;
01684         filt->set_complex(true);
01685 //      Region filt_region;
01686 
01687 //      if (nx & 1) {
01688 //              LOGERR("even image xsize only");                throw ImageFormatException("even image xsize only");
01689 //      }
01690 
01691         int cs = (((nx * 7 / 4) & 0xfffff8) - nx) / 2; // this pads the image to 1 3/4 * size with result divis. by 8
01692 
01693         static EMData big_clip;
01694         int big_x = nx+2*cs;
01695         int big_y = ny+2*cs;
01696         int big_z = 1;
01697         if ( nz != 1 ) {
01698                 big_z = nz+2*cs;
01699         }
01700 
01701 
01702         if ( big_clip.get_xsize() != big_x || big_clip.get_ysize() != big_y || big_clip.get_zsize() != big_z ) {
01703                 big_clip.set_size(big_x,big_y,big_z);
01704         }
01705         // It is important to set all newly established pixels around the boundaries to the mean
01706         // If this is not done then the associated rotational alignment routine breaks, in fact
01707         // everythin just goes foo.
01708         big_clip.to_value(get_edge_mean());
01709 
01710         if (nz != 1) {
01711                 big_clip.insert_clip(this,IntPoint(cs,cs,cs));
01712         } else  {
01713                 big_clip.insert_clip(this,IntPoint(cs,cs,0));
01714         }
01715 
01716 
01717         // The filter object is nothing more than a cached high pass filter
01718         // Ultimately it is used an argument to the EMData::mult(EMData,prevent_complex_multiplication (bool))
01719         // function in calc_mutual_correlation. Note that in the function the prevent_complex_multiplication
01720         // set to true, which is used for speed reasons.
01721         if (filt->get_xsize() != big_clip.get_xsize() +2-(big_clip.get_xsize()%2) || filt->get_ysize() != big_clip.get_ysize() ||
01722                    filt->get_zsize() != big_clip.get_zsize()) {
01723                 filt->set_size(big_clip.get_xsize() + 2-(big_clip.get_xsize()%2), big_clip.get_ysize(), big_clip.get_zsize());
01724         filt->to_one();
01725         filt->process_inplace("eman1.filter.highpass.gaussian", Dict("highpass", 1.5f/nx));
01726         }
01727         EMData *mc = big_clip.calc_mutual_correlation(&big_clip, true,filt);
01728         mc->sub(mc->get_edge_mean());
01729 
01730         static EMData sml_clip;
01731         int sml_x = nx * 3 / 2;
01732         int sml_y = ny * 3 / 2;
01733         int sml_z = 1;
01734         if ( nz != 1 ) {
01735                 sml_z = nz * 3 / 2;
01736         }
01737 
01738         if ( sml_clip.get_xsize() != sml_x || sml_clip.get_ysize() != sml_y || sml_clip.get_zsize() != sml_z ) {
01739                 sml_clip.set_size(sml_x,sml_y,sml_z);   }
01740         if (nz != 1) {
01741                 sml_clip.insert_clip(mc,IntPoint(-cs+nx/4,-cs+ny/4,-cs+nz/4));
01742         } else {
01743                 sml_clip.insert_clip(mc,IntPoint(-cs+nx/4,-cs+ny/4,0));
01744         }
01745 
01746         delete mc; mc = 0;
01747         EMData * result = NULL;
01748 
01749         if (nz == 1) {
01750                 if (!unwrap) {
01751                         result = sml_clip.process("mask.sharp", Dict("outer_radius", -1, "value", 0));
01752 
01753                 }
01754                 else {
01755                         result = sml_clip.unwrap();
01756                 }
01757         }
01758         else {
01759                 // I am not sure why there is any consideration of non 2D images, but it was here
01760                 // in the first port so I kept when I cleaned this function up (d.woolford)
01761 //              result = clipped_mc;
01762                 result = new EMData(sml_clip);
01763         }
01764 
01765         EXITFUNC;
01766         if ( unwrap == true)
01767         { // this if statement reflects a strict policy of caching in only one scenario see comments at beginning of function block
01768 
01769                 // Note that the if statement at the beginning of this function ensures that rot_fp is not zero, so there is no need
01770                 // to throw any exception
01771                 if ( rot_fp != 0 ) throw UnexpectedBehaviorException("The rotational foot print is only expected to be cached if it is not NULL");
01772 
01773                 // Here is where the caching occurs - the rot_fp takes ownsherhip of the pointer, and a deep copied EMData object is returned.
01774                 // The deep copy invokes a cost in terms of CPU cycles and memory, but prevents the need for complicated memory management (reference counting)
01775                 rot_fp = result;
01776                 return new EMData(*rot_fp);
01777         }
01778         else return result;
01779 }

vector< Vec3i > EMData::mask_contig_region ( const float &  val,
const Vec3i seed 
)

Definition at line 1230 of file emdata_metadata.cpp.

References find_region(), and v.

01230                                                                               {
01231         Vec3i coord(seed[0],seed[1],seed[2]);
01232         vector<Vec3i> region;
01233         region.push_back(coord);
01234         vector<Vec3i> find_region_input = region;
01235         while (true) {
01236                 vector<Vec3i> v = find_region(this,find_region_input, value, region);
01237                 if (v.size() == 0 ) break;
01238                 else find_region_input = v;
01239         }
01240         return region;
01241 }

float EMData::max_3D_pixel_error ( const Transform t1,
const Transform t2,
float  r 
)

Definition at line 913 of file emdata.cpp.

References EMAN::Transform::inverse(), sqrt(), t, and v.

00913                                                                                    {
00914         
00915         Transform t;
00916         int r0 = (int)r;
00917         float ddmax = 0.0f;
00918 
00919         t = t2*t1.inverse();
00920         for (int i=0; i<int(2*M_PI*r0+0.5); i++) {
00921                 Vec3f v = Vec3f(r0*cos((float)i), r0*sin((float)i), 0);
00922                 Vec3f d = t*v-v;
00923                 float dd = d[0]*d[0]+d[1]*d[1]+d[2]*d[2];
00924                 if (dd > ddmax) ddmax = dd; 
00925         }
00926         return std::sqrt(ddmax);
00927 }

vector< float > EMData::max_search (  ) 

Search specified number peaks in 1D, 2D, or 3D real images.

and output the peaks in descendent order: The numbers coming out are: image dimension, then 1D: pixel value, x coord, relative peak value, x coord( NX/2 center), ... 2D: pixel value, x coord, y coord, realative peak value, x coord(NX/2 center) y coord(NY/2 center) ... 3D pixel value, x coord, y coord, z coord, realative peak value, x coord(NX/2 center) y coord(NY/2 center) z coord(NZ/2 center) The function is supposed to return 0 dimension and first pixel value (0,0,0) when the image is constant. ...

Parameters:
[in] ml 
[in] invert 

Definition at line 3671 of file emdata_sparx.cpp.

References get_ndim(), get_xsize(), get_ysize(), get_zsize(), max, nx, ny, and nz.

03671                                  {
03672 
03673         EMData& buf = *this;
03674 
03675         int nx = buf.get_xsize();
03676         int ny = buf.get_ysize();
03677         int nz = buf.get_zsize();
03678 
03679         int dim = buf.get_ndim();
03680 
03681         vector<float> result;
03682 
03683         if (dim == 1) {
03684                 float max = -1e20f;
03685                 int index = -1;
03686                 for (int i=0; i<nx; i++) {
03687                         if (buf(i)>max) {
03688                                 max = buf(i);
03689                                 index = i;
03690                         }
03691                 }
03692                 result.push_back((float)index);
03693                 result.push_back(max);
03694         } else if (dim == 2) {
03695                 float max = -1e20f;
03696                 int index1 = -1;
03697                 int index2 = -1;
03698                 for (int i=0; i<nx; i++) {
03699                         for (int j=0; j<ny; j++) {
03700                                 if (buf(i, j)>max) {
03701                                         max = buf(i, j);
03702                                         index1 = i;
03703                                         index2 = j;
03704                                 }
03705                         }
03706                 }
03707                 result.push_back((float)index1);
03708                 result.push_back((float)index2);
03709                 result.push_back(max);
03710         } else {
03711                 float max = -1e20f;
03712                 int index1 = -1;
03713                 int index2 = -1;
03714                 int index3 = -1;
03715                 for (int i=0; i<nx; i++) {
03716                         for (int j=0; j<ny; j++) {
03717                                 for (int k=0; k<nz; k++) {
03718                                         if (buf(i, j, k)>max) {
03719                                                 max = buf(i, j, k);
03720                                                 index1 = i;
03721                                                 index2 = j;
03722                                                 index3 = k;
03723                                         }
03724                                 }
03725                         }
03726                 }
03727                 result.push_back((float)index1);
03728                 result.push_back((float)index2);
03729                 result.push_back((float)index3);
03730                 result.push_back(max);
03731         }
03732         return result;
03733 }

void EMData::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:
image The image multiplied to 'this' image.
prevent_complex_multiplication if the image is complex, this flag will override complex multiplication and just multiply each pixel by the other
Exceptions:
ImageFormatException If the 2 images are not same size.

Definition at line 500 of file emdata_core.cpp.

References data, ENTERFUNC, EXITFUNC, get_data(), get_xsize(), get_ysize(), get_zsize(), ImageFormatException, is_real(), nx, nxyz, ny, nz, and update().

00501 {
00502         ENTERFUNC;
00503 
00504         if (nx != em.get_xsize() || ny != em.get_ysize() || nz != em.get_zsize()) {
00505                 throw ImageFormatException( "can not multiply images that are not the same size");
00506         }
00507         else if( (is_real()^em.is_real()) == true )
00508         {
00509                 throw ImageFormatException( "can not multiply real and complex images.");
00510         }
00511         else
00512         {
00513                 const float *src_data = em.get_data();
00514                 size_t size = nxyz;
00515                 float* data = get_data();
00516                 if( is_real() || prevent_complex_multiplication )
00517                 {
00518                         for (size_t i = 0; i < size; i++) {
00519                                 data[i] *= src_data[i];
00520                         }
00521                 }
00522                 else
00523                 {
00524                         typedef std::complex<float> comp;
00525                         for( size_t i = 0; i < size; i+=2 )
00526                         {
00527                                 comp c_src( src_data[i], src_data[i+1] );
00528                                 comp c_rdat( data[i], data[i+1] );
00529                                 comp c_result = c_src * c_rdat;
00530                                 data[i] = c_result.real();
00531                                 data[i+1] = c_result.imag();
00532                         }
00533                 }
00534                 update();
00535         }
00536 
00537         EXITFUNC;
00538 }

void EMData::mult ( float  f  ) 

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

Parameters:
f The float multiplied to 'this' image.

Definition at line 471 of file emdata_core.cpp.

References ap2ri(), data, emdata_processor_mult(), ENTERFUNC, EXITFUNC, get_data(), is_complex(), nxyz, and update().

00472 {
00473         ENTERFUNC;
00474 
00475 
00476         if (is_complex()) {
00477                 ap2ri();
00478         }
00479         if (f != 1.0) {
00480 #ifdef EMAN2_USING_CUDA
00481                 if ( gpu_operation_preferred () ) {
00482                         EMDataForCuda tmp = get_data_struct_for_cuda();
00483                         emdata_processor_mult(&tmp,f);
00484                         gpu_update();
00485                         EXITFUNC;
00486                         return;
00487                 }
00488 #endif // EMAN2_USING_CUDA
00489                 float* data = get_data();
00490                 size_t size = nxyz;
00491                 for (size_t i = 0; i < size; i++) {
00492                         data[i] *= f;
00493                 }
00494                 update();
00495         }
00496         EXITFUNC;
00497 }

void EMAN::EMData::mult ( int  n  )  [inline]

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

Parameters:
n The integer multiplied to 'this' image.

Definition at line 1740 of file emdata.h.

Referenced by calc_fast_sigma_image(), calc_flcf(), calc_mutual_correlation(), div(), do_ift(), do_ift_inplace(), EMAN::BackProjectionReconstructor::finish(), EMAN::BackProjectionReconstructor::insert_slice(), make_footprint(), EMAN::Averager::mult(), EMAN::operator *(), operator *=(), EMAN::operator-(), EMAN::operator/(), EMAN::FourierReconstructor::preprocess_slice(), EMAN::Wiener2DFourierProcessor::process(), EMAN::TomoTiltAngleWeightProcessor::process_inplace(), EMAN::AutoMask3D2Processor::process_inplace(), EMAN::AutoMask3DProcessor::process_inplace(), EMAN::LocalNormProcessor::process_inplace(), EMAN::AutoMask2DProcessor::process_inplace(), EMAN::NormalizeByMassProcessor::process_inplace(), EMAN::NormalizeRampNormVar::process_inplace(), EMAN::FlattenBackgroundProcessor::process_inplace(), and EMAN::SNREvalProcessor::process_inplace().

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

Definition at line 540 of file emdata_core.cpp.

References data, ENTERFUNC, EXITFUNC, get_data(), get_ndim(), get_xsize(), get_ysize(), get_zsize(), ImageDimensionException, ImageFormatException, is_real(), nx, nxy, nxyz, and update().

Referenced by calc_mutual_correlation().

00541 {
00542         ENTERFUNC;
00543 
00544         if( is_real() || em.is_real() )throw ImageFormatException( "can call mult_complex_efficient unless both images are complex");
00545 
00546 
00547         const float *src_data = em.get_data();
00548 
00549         size_t i_radius = radius;
00550         size_t k_radius = 1;
00551         size_t j_radius = 1;
00552         int ndim = get_ndim();
00553 
00554         if (ndim != em.get_ndim()) throw ImageDimensionException("Can't do that");
00555 
00556         if ( ndim == 3 ) {
00557                 k_radius = radius;
00558                 j_radius = radius;
00559         } else if ( ndim == 2 ) {
00560                 j_radius = radius;
00561         }
00562 
00563 
00564         int s_nx = em.get_xsize();
00565         int s_nxy = s_nx*em.get_ysize();
00566 
00567         size_t r_size = nxyz;
00568         int s_size = s_nxy*em.get_zsize();
00569         float* data = get_data();
00570 
00571         for (size_t k = 0; k < k_radius; ++k ) {
00572                 for (size_t j = 0; j < j_radius; j++) {
00573                         for (size_t i = 0; i < i_radius; i++) {
00574                                 int r_idx = k*nxy + j*nx + i;
00575                                 int s_idx = k*s_nxy + j*s_nx + i;
00576                                 data[r_idx] *= src_data[s_idx];
00577                                 data[r_size-r_idx-1] *= src_data[s_size-s_idx-1];
00578                         }
00579                 }
00580         }
00581 
00582         update();
00583 
00584         EXITFUNC;
00585 }

EMData * EMData::mult_radial ( EMData radial  ) 

Multiply radially a 2-D or 3-D image by a 1-D image.

Parameters:
radial the 1-D image multiply to
Exceptions:
ImageDimensionException If 'this' image is 1D.
Returns:
2-D or 3-D radially multiplied image

Definition at line 638 of file emdata_sparx.cpp.

References copy_head(), ENTERFUNC, EXITFUNC, get_xsize(), ImageDimensionException, LOGERR, nx, ny, nz, set_array_offsets(), sqrt(), to_zero(), and update().

00638                                           {
00639 
00640         ENTERFUNC;
00641         if ( ny == 1 && nz == 1 ) {
00642                 LOGERR("Input image must be 2-D or 3-D!");
00643                 throw ImageDimensionException("Input image must be 2-D or 3-D!");
00644         }
00645 
00646         EMData* result = this->copy_head();
00647 
00648         result->to_zero();
00649         result->set_array_offsets(-nx/2, -ny/2, -nz/2);
00650         this->set_array_offsets(-nx/2, -ny/2, -nz/2);
00651         int rmax = radial->get_xsize();
00652         int i, j, k, ir;
00653         float r;
00654         for ( k = -nz/2; k < nz/2+nz%2; k++) {
00655                 for ( j = -ny/2; j < ny/2+ny%2; j++) {
00656                         for ( i = -nx/2; i < nx/2+nx%2; i++)  {
00657                                 r = std::sqrt(float(k*k) + float(j*j) + float(i*i));
00658                                 ir = int(r);
00659                                 if(ir < rmax-1)  (*result)(i,j,k) = (*this)(i,j,k) * ((*radial)(ir)+((*radial)(ir+1)-(*radial)(ir))*(r - float(ir)));
00660                         }
00661                 }
00662         }
00663         result->update();
00664         result->set_array_offsets(0,0,0);
00665         this->set_array_offsets(0,0,0);
00666         EXITFUNC;
00667         return result;
00668 }

void EMData::nn ( EMData wptr,
EMData myfft,
const Transform tf,
int  mult = 1 
)

Nearest Neighbor interpolation.

Modifies the current object.

Parameters:
wptr Normalization data.
myfft FFT data.
tf Transform reference
mult 

Definition at line 1115 of file emdata_sparx.cpp.

References attr_dict, ENTERFUNC, EXITFUNC, get_array_offsets(), ny, onelinenn(), onelinenn_mult(), set_array_offsets(), and tf().

Referenced by EMAN::nn4Reconstructor::insert_padfft_slice().

01116 {
01117         ENTERFUNC;
01118         int nxc = attr_dict["nxc"]; // # of complex elements along x
01119         // let's treat nr, bi, and local data as matrices
01120         vector<int> saved_offsets = get_array_offsets();
01121         vector<int> myfft_saved_offsets = myfft->get_array_offsets();
01122         set_array_offsets(0,1,1);
01123         myfft->set_array_offsets(0,1);
01124         // loop over frequencies in y
01125         if( mult == 1 ) {
01126                 for (int iy = -ny/2 + 1; iy <= ny/2; iy++) onelinenn(iy, ny, nxc, wptr, myfft, tf);
01127         } else {
01128                 for (int iy = -ny/2 + 1; iy <= ny/2; iy++) onelinenn_mult(iy, ny, nxc, wptr, myfft, tf, mult);
01129         }
01130 
01131         set_array_offsets(saved_offsets);
01132         myfft->set_array_offsets(myfft_saved_offsets);
01133         EXITFUNC;
01134 }

void EMData::nn_ctf ( EMData w,
EMData myfft,
const Transform tf,
int  mult 
)

Nearest Neighbor interpolation.

Modifies the current object.

Parameters:
w Normalization data.
myfft FFT data.
tf Transform3D reference
mult 

Definition at line 1515 of file emdata_sparx.cpp.

References attr_dict, ENTERFUNC, EXITFUNC, get_array_offsets(), get_attr(), ctf_store::init(), ny, onelinenn_ctf(), set_array_offsets(), and tf().

Referenced by EMAN::nn4_ctfReconstructor::insert_padfft_slice().

01515                                                                       {
01516         ENTERFUNC;
01517         int nxc = attr_dict["nxc"]; // # of complex elements along x
01518         // let's treat nr, bi, and local data as matrices
01519         vector<int> saved_offsets = get_array_offsets();
01520         vector<int> myfft_saved_offsets = myfft->get_array_offsets();
01521         set_array_offsets(0,1,1);
01522         myfft->set_array_offsets(0,1);
01523 
01524 
01525         Ctf* ctf = myfft->get_attr("ctf");
01526         ctf_store::init( ny, ctf );
01527         if(ctf) {delete ctf; ctf=0;}
01528 
01529         // loop over frequencies in y
01530         for (int iy = -ny/2 + 1; iy <= ny/2; iy++) onelinenn_ctf(iy, ny, nxc, w, myfft, tf, mult);
01531         set_array_offsets(saved_offsets);
01532         myfft->set_array_offsets(myfft_saved_offsets);
01533         EXITFUNC;
01534 }

void EMData::nn_ctf_applied ( EMData w,
EMData myfft,
const Transform tf,
int  mult 
)

Nearest Neighbor interpolation.

Modifies the current object. here it is assumed the projection data was already multiplied by the ctf...

Parameters:
w Normalization data.
myfft FFT data.
tf Transform3D reference
mult 

Definition at line 1537 of file emdata_sparx.cpp.

References attr_dict, ENTERFUNC, EXITFUNC, get_array_offsets(), get_attr(), ctf_store::init(), ny, onelinenn_ctf_applied(), set_array_offsets(), and tf().

Referenced by EMAN::nn4_ctfReconstructor::insert_padfft_slice().

01537                                                                               {
01538         ENTERFUNC;
01539         int nxc = attr_dict["nxc"]; // # of complex elements along x
01540         // let's treat nr, bi, and local data as matrices
01541         vector<int> saved_offsets = get_array_offsets();
01542         vector<int> myfft_saved_offsets = myfft->get_array_offsets();
01543         set_array_offsets(0,1,1);
01544         myfft->set_array_offsets(0,1);
01545 
01546         Ctf* ctf = myfft->get_attr( "ctf" );
01547         ctf_store::init( ny, ctf );
01548         if(ctf) {delete ctf; ctf=0;}
01549         //}
01550 
01551         // loop over frequencies in y
01552         for (int iy = -ny/2 + 1; iy <= ny/2; iy++) onelinenn_ctf_applied(iy, ny, nxc, w, myfft, tf, mult);
01553         set_array_offsets(saved_offsets);
01554         myfft->set_array_offsets(myfft_saved_offsets);
01555         EXITFUNC;
01556 }

void EMData::nn_SSNR ( EMData wptr,
EMData wptr2,
EMData myfft,
const Transform tf,
int  mult = 1 
)

Nearest Neighbor interpolation, meanwhile return necessary data such as Kn, sum_k(F_k^n) ans sum_k(|F_k^n|^2) Modifies the current object.

Parameters:
wptr Normalization data.
wptr2 
myfft FFT data.
tf Transform reference
mult 

Definition at line 1136 of file emdata_sparx.cpp.

References attr_dict, cmplx(), ENTERFUNC, EXITFUNC, get_array_offsets(), is_fftodd(), norm(), nx, ny, nz, set_array_offsets(), and tf().

Referenced by EMAN::nnSSNR_Reconstructor::insert_padfft_slice().

01137 {
01138         ENTERFUNC;
01139         int nxc = attr_dict["nxc"];
01140 
01141         vector<int> saved_offsets = get_array_offsets();
01142         vector<int> myfft_saved_offsets = myfft->get_array_offsets();
01143 
01144         set_array_offsets(0,1,1);
01145         myfft->set_array_offsets(0,1);
01146 
01147         int iymin = is_fftodd() ? -ny/2 : -ny/2 + 1 ;
01148         int iymax = ny/2;
01149         int izmin = is_fftodd() ? -nz/2 : -nz/2 + 1 ;
01150         int izmax = nz/2;
01151 
01152         for (int iy = iymin; iy <= iymax; iy++) {
01153                 int jp = iy >= 0 ? iy+1 : ny+iy+1; //checked, works for both odd and even
01154                 for (int ix = 0; ix <= nxc; ix++) {
01155                         if (( 4*(ix*ix+iy*iy) < ny*ny ) && !( ix == 0 && iy < 0 ) ) {
01156                                 float xnew = ix*tf[0][0] + iy*tf[1][0];
01157                                 float ynew = ix*tf[0][1] + iy*tf[1][1];
01158                                 float znew = ix*tf[0][2] + iy*tf[1][2];
01159                                 std::complex<float> btq;
01160                                 if (xnew < 0.0) {
01161                                         xnew = -xnew; // ensures xnew>=0.0
01162                                         ynew = -ynew;
01163                                         znew = -znew;
01164                                         btq = conj(myfft->cmplx(ix,jp));
01165                                 } else {
01166                                         btq = myfft->cmplx(ix,jp);
01167                                 }
01168                                 int ixn = int(xnew + 0.5 + nx) - nx; // ensures ixn >= 0
01169                                 int iyn = int(ynew + 0.5 + ny) - ny;
01170                                 int izn = int(znew + 0.5 + nz) - nz;
01171                                 if ((ixn <= nxc) && (iyn >= iymin) && (iyn <= iymax) && (izn >= izmin) && (izn <= izmax)) {
01172                                         if (ixn >= 0) {
01173                                                 int iza, iya;
01174                                                 if (izn >= 0)  iza = izn + 1;
01175                                                 else           iza = nz + izn + 1;
01176 
01177                                                 if (iyn >= 0) iya = iyn + 1;
01178                                                 else          iya = ny + iyn + 1;
01179 
01180                                                 cmplx(ixn,iya,iza) += btq;
01181                                                 (*wptr)(ixn,iya,iza)++;
01182                                                 (*wptr2)(ixn,iya,iza) += norm(btq);
01183                                         } else {
01184                                                 int izt, iyt;
01185                                                 if (izn > 0) izt = nz - izn + 1;
01186                                                 else         izt = -izn + 1;
01187 
01188                                                 if (iyn > 0) iyt = ny - iyn + 1;
01189                                                 else         iyt = -iyn + 1;
01190 
01191                                                 cmplx(-ixn,iyt,izt) += conj(btq);
01192                                                 (*wptr)(-ixn,iyt,izt)++;
01193                                                 (*wptr2)(-ixn,iyt,izt) += norm(btq);
01194                                         }
01195                                 }
01196                         }
01197                 }
01198         }
01199         set_array_offsets(saved_offsets);
01200         myfft->set_array_offsets(myfft_saved_offsets);
01201         EXITFUNC;
01202 }

void EMData::nn_SSNR_ctf ( EMData wptr,
EMData wptr2,
EMData wptr3,
EMData myfft,
const Transform tf,
int  mult = 1 
)

Nearest Neighbor interpolation, meanwhile return necessary data such as Kn, sum_k(F_k^n) ans sum_k(|F_k^n|^2) Modifies the current object.

Parameters:
wptr Normalization data.
wptr2 
wptr3 
myfft 
tf Transform reference
mult 

Definition at line 1560 of file emdata_sparx.cpp.

References attr_dict, cmplx(), ENTERFUNC, EXITFUNC, get_array_offsets(), get_attr(), ctf_store::get_ctf(), ctf_store::init(), is_fftodd(), norm(), nx, ny, nz, set_array_offsets(), and tf().

Referenced by EMAN::nnSSNR_ctfReconstructor::insert_padfft_slice().

01561 {
01562         /***   Preparing terms for SSNR
01563               m_wvolume F^3D Wiener volume
01564              wptr   ctf^2
01565             wptr5  ctf^2*|P^2D->3D(F^3D)|^2
01566            wptr4  2*Real(conj(F_k^2D)*ctf*P^2D->3D(F^3D))
01567           wptr2  F_k^2D*conj(F_k^2D) or |F_k^2D|^2
01568           Kn is counted in the previous routine, and won't be
01569          calculated any more.
01570                                                     ***/
01571         ENTERFUNC;
01572         int nxc = attr_dict["nxc"];
01573         vector<int> saved_offsets = get_array_offsets();
01574         vector<int> myfft_saved_offsets = myfft->get_array_offsets();
01575         set_array_offsets(0,1,1);
01576         myfft->set_array_offsets(0,1);
01577 
01578         Ctf* ctf = myfft->get_attr("ctf");
01579         ctf_store::init( ny, ctf );
01580         int iymin = is_fftodd() ? -ny/2 : -ny/2 + 1;
01581         int iymax = ny/2;
01582         int izmin = is_fftodd() ? -nz/2 : -nz/2 + 1;
01583         int izmax = nz/2;
01584 //      std::complex<float> tmpq, tmp2;
01585         for (int iy = iymin; iy <= iymax; iy++) {
01586                 int jp = iy >= 0 ? iy+1 : ny+iy+1; //checked, works for both odd and even
01587                 for (int ix = 0; ix <= nxc; ix++) {
01588                         int r2 = ix*ix+iy*iy;
01589                         if (( 4*r2 < ny*ny ) && !( ix == 0 && iy < 0 ) ) {
01590                                 float  ctf = ctf_store::get_ctf( r2 )*10.f;
01591                                 float xnew = ix*tf[0][0] + iy*tf[1][0];
01592                                 float ynew = ix*tf[0][1] + iy*tf[1][1];
01593                                 float znew = ix*tf[0][2] + iy*tf[1][2];
01594                                 std::complex<float> btq;
01595                                 if (xnew < 0.0) {
01596                                         xnew = -xnew; // ensures xnew>=0.0
01597                                         ynew = -ynew;
01598                                         znew = -znew;
01599                                         btq = conj(myfft->cmplx(ix,jp));
01600                                 } else  {
01601                                         btq = myfft->cmplx(ix,jp);
01602                                 }
01603                                 int ixn = int(xnew + 0.5 + nx) - nx; // ensures ixn >= 0
01604                                 int iyn = int(ynew + 0.5 + ny) - ny;
01605                                 int izn = int(znew + 0.5 + nz) - nz;
01606                                 if ((ixn <= nxc) && (iyn >= iymin) && (iyn <= iymax) && (izn >= izmin) && (izn <= izmax)) {
01607                                         if (ixn >= 0) {
01608                                                 int iza, iya;
01609                                                 if (izn >= 0) iza = izn + 1;
01610                                                 else          iza = nz + izn + 1;
01611 
01612                                                 if (iyn >= 0) iya = iyn + 1;
01613                                                 else          iya = ny + iyn + 1;
01614 
01615                                                 cmplx(ixn,iya,iza)    += btq*ctf;
01616                                                 (*wptr)(ixn,iya,iza)  += ctf*ctf;
01617                                                 (*wptr2)(ixn,iya,iza) += std::norm(btq);
01618                                                 (*wptr3)(ixn,iya,iza) += 1;
01619                                         } else {
01620                                                 int izt, iyt;
01621                                                 if (izn > 0)  izt = nz - izn + 1;
01622                                                 else          izt = -izn + 1;
01623 
01624                                                 if (iyn > 0) iyt = ny - iyn + 1;
01625                                                 else         iyt = -iyn + 1;
01626 
01627                                                 cmplx(-ixn,iyt,izt)    += std::conj(btq)*ctf;
01628                                                 (*wptr) (-ixn,iyt,izt) += ctf*ctf;
01629                                                 (*wptr2)(-ixn,iyt,izt) += std::norm(btq);
01630                                                 (*wptr3)(-ixn,iyt,izt) += 1;
01631                                         }
01632                                 }
01633                         }
01634                 }
01635         }
01636         set_array_offsets(saved_offsets);
01637         myfft->set_array_offsets(myfft_saved_offsets);
01638         if(ctf) {delete ctf; ctf=0;}
01639         EXITFUNC;
01640 }

EMData * EMData::norm_pad ( bool  do_norm,
int  npad = 1,
int  valtype = 0 
)

Normalize, pad, and Fourier extend convenience function.

Purpose: Create a new [normalized] [zero-padded] Fourier image.
Method: Normalize (if requested), pad with zeros (if
requested), extend along x for fft, and return the new image.
Parameters:
[in] do_norm If true then perform normalization.
[in] npad Amount of zero-padding to use (defaults to 2 if do_pad is true).
valtype 
Returns:
[normalized,] [zero-padded,] [ft-extended] input image.

Definition at line 5211 of file emdata_sparx.cpp.

References circumference(), copy_head(), data, get_array_offsets(), get_attr(), get_xsize(), get_ysize(), get_zsize(), ImageFormatException, nx, nxyz, ny, nz, and set_array_offsets().

Referenced by calc_fourier_shell_correlation(), EMAN::Processor::EMFourierFilterFunc(), filter_by_image(), EMAN::fourierproduct(), EMAN::padfft_slice(), EMAN::periodogram(), EMAN::FourierGriddingProjector::project3d(), and replace_amplitudes().

05211                                                            {
05212         if (this->is_complex())
05213                 throw ImageFormatException("Padding of complex images not supported");
05214         int nx = this->get_xsize();
05215         int ny = this->get_ysize();
05216         int nz = this->get_zsize();
05217         float mean = 0., stddev = 1.;
05218         if(donorm) { // Normalization requested
05219                 mean = this->get_attr("mean");
05220                 stddev = this->get_attr("sigma");
05221         }
05222         // sanity check
05223         if (npad < 1) npad = 1;
05224         int nxpad = npad*nx;
05225         int nypad = npad*ny;
05226         int nzpad = npad*nz;
05227         if (1 == ny) {
05228                 // 1-d image, don't want to pad along y or z
05229                 // Also, assuming that we can't have an image sized as nx=5, ny=1, nz=5.
05230                 nypad = ny;
05231                 nzpad = nz;
05232         } else if (nz == 1) {
05233                 // 2-d image, don't want to pad along z
05234                 nzpad = nz;
05235         }
05236         size_t bytes;
05237         size_t offset;
05238         // Not currently fft-extended, so we want to extend for ffts
05239         offset = 2 - nxpad%2;
05240         bytes = nx*sizeof(float);
05241         EMData* fpimage = copy_head();
05242         fpimage->set_size(nxpad+offset, nypad, nzpad);
05243         if( npad > 1) {
05244                 if( valtype==0 ) {
05245                     fpimage->to_zero();
05246                 } else {
05247                     float val = circumference(this, 1);
05248                     float* data = fpimage->get_data();
05249                     int nxyz = (nxpad+offset)*nypad*nzpad;
05250                     for( int i=0; i < nxyz; ++i )  data[i] = val;
05251                 }
05252         }
05253 
05254 
05255 
05256         int xstart = 0, ystart = 0, zstart = 0;
05257         if (npad > 1) {
05258                 xstart = (nxpad - nx)/2 + nx%2;
05259                 if(ny > 1) {
05260                         ystart = (nypad - ny)/2 + ny%2;
05261                         if(nz > 1) {
05262                                 zstart = (nzpad - nz)/2 + nz%2;
05263                         }
05264                 }
05265         }
05266 
05267 
05268         vector<int> saved_offsets = this->get_array_offsets();
05269         this->set_array_offsets( 0, 0, 0 );
05270         for (int iz = 0; iz < nz; iz++) {
05271                 for (int iy = 0; iy < ny; iy++) {
05272                         memcpy(&(*fpimage)(xstart,iy+ystart,iz+zstart), &(*this)(0,iy,iz), bytes);
05273                 }
05274         }
05275         this->set_array_offsets( saved_offsets );
05276 
05277 
05278         //  Perform the actual normalization (only on the
05279         //  non-zero section of the image)
05280         if (donorm) { // Normalization requested
05281                 for (int iz = zstart; iz < nz+zstart; iz++)
05282                         for (int iy = ystart; iy < ny+ystart; iy++)
05283                                 for (int ix = xstart; ix < nx+xstart; ix++)
05284                                         (*fpimage)(ix,iy,iz) = ((*fpimage)(ix,iy,iz)-mean)/stddev;
05285         }
05286 
05287         fpimage->set_fftpad(true);
05288         fpimage->set_attr("npad", npad);
05289         if (offset == 1) fpimage->set_fftodd(true);
05290         else             fpimage->set_fftodd(false);
05291         return fpimage;
05292 }

void EMData::onelinenn ( int  j,
int  n,
int  n2,
EMData wptr,
EMData bi,
const Transform tf 
)

Helper function for method nn.

Parameters:
j y fourier index (frequency)
n number of real elements.
n2 Number of complex elements.
wptr Normalization matrix [0:n2][1:n][1:n]
bi Fourier transform matrix [0:n2][1:n]
tf Transform3D reference

Definition at line 1010 of file emdata_sparx.cpp.

References bi, cmplx(), and tf().

Referenced by nn().

01011 {
01012         //std::cout<<"   onelinenn  "<<j<<"  "<<n<<"  "<<n2<<"  "<<std::endl;
01013         int jp = (j >= 0) ? j+1 : n+j+1;
01014         //for(int i = 0; i <= 1; i++){for(int l = 0; l <= 2; l++){std::cout<<"  "<<tf[i][l]<<"  "<<std::endl;}}
01015         // loop over x
01016         for (int i = 0; i <= n2; i++) {
01017         if (((i*i+j*j) < n*n/4) && !((0 == i) && (j < 0))) {
01018 //        if ( !((0 == i) && (j < 0))) {
01019                         float xnew = i*tf[0][0] + j*tf[1][0];
01020                         float ynew = i*tf[0][1] + j*tf[1][1];
01021                         float znew = i*tf[0][2] + j*tf[1][2];
01022                         std::complex<float> btq;
01023                         if (xnew < 0.) {
01024                                 xnew = -xnew;
01025                                 ynew = -ynew;
01026                                 znew = -znew;
01027                                 btq = conj(bi->cmplx(i,jp));
01028                         } else {
01029                                 btq = bi->cmplx(i,jp);
01030                         }
01031                         int ixn = int(xnew + 0.5 + n) - n;
01032                         int iyn = int(ynew + 0.5 + n) - n;
01033                         int izn = int(znew + 0.5 + n) - n;
01034                         if ((ixn <= n2) && (iyn >= -n2) && (iyn <= n2)  && (izn >= -n2) && (izn <= n2)) {
01035                                 if (ixn >= 0) {
01036                                         int iza, iya;
01037                                         if (izn >= 0)  iza = izn + 1;
01038                                         else           iza = n + izn + 1;
01039 
01040                                         if (iyn >= 0) iya = iyn + 1;
01041                                         else          iya = n + iyn + 1;
01042 
01043                                         cmplx(ixn,iya,iza) += btq;
01044                                         //std::cout<<"    "<<j<<"  "<<ixn<<"  "<<iya<<"  "<<iza<<"  "<<btq<<std::endl;
01045                                         (*wptr)(ixn,iya,iza)++;
01046                                 } else {
01047                                         int izt, iyt;
01048                                         if (izn > 0) izt = n - izn + 1;
01049                                         else         izt = -izn + 1;
01050 
01051                                         if (iyn > 0) iyt = n - iyn + 1;
01052                                         else         iyt = -iyn + 1;
01053 
01054                                         cmplx(-ixn,iyt,izt) += conj(btq);
01055                                         //std::cout<<" *  "<<j<<"  "<<ixn<<"  "<<iyt<<"  "<<izt<<"  "<<btq<<std::endl;
01056                                         (*wptr)(-ixn,iyt,izt)++;
01057                                 }
01058                         }
01059                 }
01060         }
01061 }

void EMData::onelinenn_ctf ( int  j,
int  n,
int  n2,
EMData w,
EMData bi,
const Transform tf,
int  mult 
)

Helper function for method nn4_ctf.

Parameters:
j y fourier index (frequency)
n number of real elements.
n2 Number of complex elements.
w Normalization matrix [0:n2][1:n][1:n]
bi Fourier transform matrix [0:n2][1:n]
tf Transform3D reference
mult 

Definition at line 1382 of file emdata_sparx.cpp.

References bi, cmplx(), ctf_store::get_ctf(), and tf().

Referenced by nn_ctf().

01383                                                                                 {//std::cout<<"   onelinenn_ctf  "<<j<<"  "<<n<<"  "<<n2<<"  "<<std::endl;
01384 
01385         int remove = bi->get_attr_default( "remove", 0 );
01386 
01387         int jp = (j >= 0) ? j+1 : n+j+1;
01388         // loop over x
01389         for (int i = 0; i <= n2; i++) {
01390                 int r2 = i*i+j*j;
01391                 if ( (r2<n*n/4) && !( (0==i) && (j<0) ) ) {
01392                         float  ctf = ctf_store::get_ctf( r2 );
01393                         float xnew = i*tf[0][0] + j*tf[1][0];
01394                         float ynew = i*tf[0][1] + j*tf[1][1];
01395                         float znew = i*tf[0][2] + j*tf[1][2];
01396                         std::complex<float> btq;
01397                         if (xnew < 0.) {
01398                                 xnew = -xnew;
01399                                 ynew = -ynew;
01400                                 znew = -znew;
01401                                 btq = conj(bi->cmplx(i,jp));
01402                         } else  btq = bi->cmplx(i,jp);
01403                         int ixn = int(xnew + 0.5 + n) - n;
01404                         int iyn = int(ynew + 0.5 + n) - n;
01405                         int izn = int(znew + 0.5 + n) - n;
01406                         if ((ixn <= n2) && (iyn >= -n2) && (iyn <= n2) && (izn >= -n2) && (izn <= n2)) {
01407                                 if (ixn >= 0) {
01408                                         int iza, iya;
01409                                         if (izn >= 0)  iza = izn + 1;
01410                                         else           iza = n + izn + 1;
01411 
01412                                         if (iyn >= 0) iya = iyn + 1;
01413                                         else          iya = n + iyn + 1;
01414 
01415                                         if(remove > 0 ) {
01416                                             cmplx(ixn,iya,iza) -= btq*ctf*float(mult);
01417                                             (*w)(ixn,iya,iza) -= ctf*ctf*mult;
01418                                         } else {
01419                                             cmplx(ixn,iya,iza) += btq*ctf*float(mult);
01420                                             (*w)(ixn,iya,iza) += ctf*ctf*mult;
01421                                         }
01422 
01423                                        //       std::cout<<"    "<<j<<"  "<<ixn<<"  "<<iya<<"  "<<iza<<"  "<<ctf<<std::endl;
01424                                 } else {
01425                                         int izt, iyt;
01426                                         if (izn > 0) izt = n - izn + 1;
01427                                         else         izt = -izn + 1;
01428 
01429                                         if (iyn > 0) iyt = n - iyn + 1;
01430                                         else         iyt = -iyn + 1;
01431 
01432                                         if( remove > 0 ) {
01433                                             cmplx(-ixn,iyt,izt) -= conj(btq)*ctf*float(mult);
01434                                             (*w)(-ixn,iyt,izt) -= ctf*ctf*float(mult);
01435                                         } else {
01436                                             cmplx(-ixn,iyt,izt) += conj(btq)*ctf*float(mult);
01437                                             (*w)(-ixn,iyt,izt) += ctf*ctf*float(mult);
01438                                         }
01439 
01440                                         //      std::cout<<" *  " << j << "  " <<-ixn << "  " << iyt << "  " << izt << "  " << ctf <<std::endl;
01441                                 }
01442                         }
01443                 }
01444         }
01445 }

void EMData::onelinenn_ctf_applied ( int  j,
int  n,
int  n2,
EMData w,
EMData bi,
const Transform tf,
int  mult 
)

Helper function for method nn4_ctf.

here it is assumed the projection data was already multiplied by the ctf...

Parameters:
j y fourier index (frequency)
n number of real elements.
n2 Number of complex elements.
w Normalization matrix [0:n2][1:n][1:n]
bi Fourier transform matrix [0:n2][1:n]
tf Transform reference
mult 

Definition at line 1447 of file emdata_sparx.cpp.

References bi, cmplx(), ctf_store::get_ctf(), and tf().

Referenced by nn_ctf_applied().

01448                                                                                 {//std::cout<<"   onelinenn_ctf  "<<j<<"  "<<n<<"  "<<n2<<"  "<<std::endl;
01449 
01450         int remove = bi->get_attr_default( "remove", 0 );
01451 
01452         int jp = (j >= 0) ? j+1 : n+j+1;
01453         // loop over x
01454         for (int i = 0; i <= n2; i++) {
01455                 int r2 = i*i + j*j;
01456                 if ( (r2< n*n/4) && !((0==i) && (j< 0)) ) {
01457                         float  ctf = ctf_store::get_ctf(r2);
01458 
01459                          //        if ( !((0 == i) && (j < 0))) {
01460                         float xnew = i*tf[0][0] + j*tf[1][0];
01461                         float ynew = i*tf[0][1] + j*tf[1][1];
01462                         float znew = i*tf[0][2] + j*tf[1][2];
01463                         std::complex<float> btq;
01464                         if (xnew < 0.) {
01465                                 xnew = -xnew;
01466                                 ynew = -ynew;
01467                                 znew = -znew;
01468                                 btq = conj(bi->cmplx(i,jp));
01469                         } else  btq = bi->cmplx(i,jp);
01470                         int ixn = int(xnew + 0.5 + n) - n;
01471                         int iyn = int(ynew + 0.5 + n) - n;
01472                         int izn = int(znew + 0.5 + n) - n;
01473 
01474                         if ((ixn <= n2) && (iyn >= -n2) && (iyn <= n2) && (izn >= -n2) && (izn <= n2)) {
01475                                 if (ixn >= 0) {
01476                                         int iza, iya;
01477                                         if (izn >= 0)  iza = izn + 1;
01478                                         else           iza = n + izn + 1;
01479 
01480                                         if (iyn >= 0) iya = iyn + 1;
01481                                         else          iya = n + iyn + 1;
01482 
01483                                         if( remove > 0 ) {
01484                                                 cmplx(ixn,iya,iza) -= btq*float(mult);
01485                                                 (*w)(ixn,iya,iza) -= mult*ctf*ctf;
01486                                         } else {
01487                                                 cmplx(ixn,iya,iza) += btq*float(mult);
01488                                                 (*w)(ixn,iya,iza) += mult*ctf*ctf;
01489                                         }
01490 
01491                                 } else {
01492                                         int izt, iyt;
01493                                         if (izn > 0) izt = n - izn + 1;
01494                                         else         izt = -izn + 1;
01495 
01496                                         if (iyn > 0) iyt = n - iyn + 1;
01497                                         else         iyt = -iyn + 1;
01498 
01499 
01500                                         if( remove > 0 ) {
01501                                                 cmplx(-ixn,iyt,izt) -= conj(btq)*float(mult);
01502                                                 (*w)(-ixn,iyt,izt) -= mult*ctf*ctf;
01503                                         } else {
01504                                                 cmplx(-ixn,iyt,izt) += conj(btq)*float(mult);
01505                                                 (*w)(-ixn,iyt,izt) += mult*ctf*ctf;
01506                                         }
01507                                         //std::cout<<" *  "<<j<<"  "<<ixn<<"  "<<iyt<<"  "<<izt<<"  "<<btq<<std::endl;
01508                                 }
01509                         }
01510                 }
01511         }
01512 }

void EMData::onelinenn_mult ( int  j,
int  n,
int  n2,
EMData wptr,
EMData bi,
const Transform tf,
int  mult 
)

Definition at line 1064 of file emdata_sparx.cpp.

References bi, cmplx(), and tf().

Referenced by nn().

01065 {
01066         //std::cout<<"   onelinenn  "<<j<<"  "<<n<<"  "<<n2<<"  "<<std::endl;
01067         int jp = (j >= 0) ? j+1 : n+j+1;
01068         //for(int i = 0; i <= 1; i++){for(int l = 0; l <= 2; l++){std::cout<<"  "<<tf[i][l]<<"  "<<std::endl;}}
01069         // loop over x
01070         for (int i = 0; i <= n2; i++) {
01071         if (((i*i+j*j) < n*n/4) && !((0 == i) && (j < 0))) {
01072 //        if ( !((0 == i) && (j < 0))) {
01073                         float xnew = i*tf[0][0] + j*tf[1][0];
01074                         float ynew = i*tf[0][1] + j*tf[1][1];
01075                         float znew = i*tf[0][2] + j*tf[1][2];
01076                         std::complex<float> btq;
01077                         if (xnew < 0.) {
01078                                 xnew = -xnew;
01079                                 ynew = -ynew;
01080                                 znew = -znew;
01081                                 btq = conj(bi->cmplx(i,jp));
01082                         } else {
01083                                 btq = bi->cmplx(i,jp);
01084                         }
01085                         int ixn = int(xnew + 0.5 + n) - n;
01086                         int iyn = int(ynew + 0.5 + n) - n;
01087                         int izn = int(znew + 0.5 + n) - n;
01088                         if ((ixn <= n2) && (iyn >= -n2) && (iyn <= n2)  && (izn >= -n2) && (izn <= n2)) {
01089                                 if (ixn >= 0) {
01090                                         int iza, iya;
01091                                         if (izn >= 0)  iza = izn + 1;
01092                                         else           iza = n + izn + 1;
01093 
01094                                         if (iyn >= 0) iya = iyn + 1;
01095                                         else          iya = n + iyn + 1;
01096 
01097                                         cmplx(ixn,iya,iza) += btq*float(mult);
01098                                         (*wptr)(ixn,iya,iza)+=float(mult);
01099                                 } else {
01100                                         int izt, iyt;
01101                                         if (izn > 0) izt = n - izn + 1;
01102                                         else         izt = -izn + 1;
01103 
01104                                         if (iyn > 0) iyt = n - iyn + 1;
01105                                         else         iyt = -iyn + 1;
01106 
01107                                         cmplx(-ixn,iyt,izt) += conj(btq)*float(mult);
01108                                         (*wptr)(-ixn,iyt,izt)+=float(mult);
01109                                 }
01110                         }
01111                 }
01112         }
01113 }

EMData & EMData::operator *= ( const EMData em  ) 

Definition at line 909 of file emdata_core.cpp.

References mult(), and update().

00910 {
00911         mult(em);
00912         update();
00913         return *this;
00914 }

EMData & EMData::operator *= ( float  n  ) 

Definition at line 874 of file emdata_core.cpp.

References mult(), and update().

00875 {
00876         mult(n);
00877         update();
00878         return *this;
00879 }

float& EMAN::EMData::operator() ( const int  ix  )  const [inline]

Definition at line 2254 of file emdata.h.

float& EMAN::EMData::operator() ( const int  ix,
const int  iy 
) const [inline]

Definition at line 2242 of file emdata.h.

float& EMAN::EMData::operator() ( const int  ix,
const int  iy,
const int  iz 
) const [inline]

Overload operator() for array indexing.

Definition at line 2232 of file emdata.h.

EMData & EMData::operator+= ( const EMData em  ) 

Definition at line 893 of file emdata_core.cpp.

References add(), and update().

00894 {
00895         add(em);
00896         update();
00897         return *this;
00898 }

EMData & EMData::operator+= ( float  n  ) 

Definition at line 859 of file emdata_core.cpp.

References add(), and update().

00860 {
00861         add(n);
00862         update();
00863         return *this;
00864 }

EMData & EMData::operator-= ( const EMData em  ) 

Definition at line 901 of file emdata_core.cpp.

References sub(), and update().

00902 {
00903         sub(em);
00904         update();
00905         return *this;
00906 }

EMData & EMData::operator-= ( float  n  ) 

Definition at line 867 of file emdata_core.cpp.

00868 {
00869         *this += (-n);
00870         return *this;
00871 }

EMData & EMData::operator/= ( const EMData em  ) 

Definition at line 917 of file emdata_core.cpp.

References div(), and update().

00918 {
00919         div(em);
00920         update();
00921         return *this;
00922 }

EMData & EMData::operator/= ( float  n  ) 

Definition at line 882 of file emdata_core.cpp.

References LOGERR.

00883 {
00884         if (n == 0) {
00885                 LOGERR("divided by zero");
00886                 return *this;
00887         }
00888         *this *= (1.0f / n);
00889         return *this;
00890 }

bool EMData::operator== ( const EMData that  )  const

Definition at line 2754 of file emdata.cpp.

References get_const_data(), get_data(), get_size(), get_xsize(), get_ysize(), get_zsize(), nx, ny, and nz.

02754                                                 {
02755         if (that.get_xsize() != nx || that.get_ysize() != ny || that.get_zsize() != nz ) return false;
02756 
02757         const float*  d1 = that.get_const_data();
02758         float* d2 = get_data();
02759 
02760         for(size_t i =0; i < get_size(); ++i,++d1,++d2) {
02761                 if ((*d1) != (*d2)) return false;
02762         }
02763         return true;
02764 
02765 }

void EMData::pad_corner ( float *  pad_image  ) 

Definition at line 3256 of file emdata_sparx.cpp.

References nx, and ny.

03256                                         {
03257         int nbytes = nx*sizeof(float);
03258         for (int iy=0; iy<ny; iy++)
03259                 memcpy(&(*this)(0,iy), pad_image+3+(iy+3)*nx, nbytes);
03260 }

vector< float > EMData::peak_ccf ( float  hf_p  ) 

Peak (with a radius of hf_p) search for particle picking:.

Parameters:
hf_p 

Definition at line 4738 of file emdata_sparx.cpp.

References get_xsize(), get_ysize(), nx, ny, and peakcmp().

04739 {
04740 
04741   // cout << "peak ccf starting up" << endl;
04742 
04743   EMData & buf = *this;
04744   vector<Pixel> peaks;
04745   int half=int(hf_p);
04746   float hf_p2 = hf_p*hf_p;
04747   int i,j;
04748   int i__1,i__2;
04749   int j__1,j__2;
04750   vector<float>res;
04751   int nx = buf.get_xsize()-half;
04752   int ny = buf.get_ysize()-half;
04753   // iterate over image
04754   for(i=half; i<=nx; ++i) {
04755     // static assignment so we don't have to re-evaluate
04756     i__1 = i-1;
04757     i__2 = i+1;
04758     for (j=half;j<=ny;++j) {
04759       j__1 = j-1;
04760       j__2 = j+1;
04761 
04762       if((buf(i,j)>0.0f)&&buf(i,j)>buf(i,j__1)) {
04763         if(buf(i,j)>buf(i,j__2)) {
04764           if(buf(i,j)>buf(i__1,j)) {
04765             if(buf(i,j)>buf(i__2,j)) {
04766               if(buf(i,j)>buf(i__1,j__1)) {
04767                 if((buf(i,j))> buf(i__1,j__2)) {
04768                   if(buf(i,j)>buf(i__2,j__1)) {
04769                     if(buf(i,j)> buf(i__2,j__2)) {
04770 
04771                       // found a peak
04772                       // empty list?
04773                       if (peaks.size()==0) {
04774                         // yes, so just push the peak onto the list
04775                         peaks.push_back(Pixel(i,j,0,buf(i,j)));
04776 
04777                       } else {
04778                         // not empty list. check neighbourhood for peaks
04779                         // logical not in the name is awkward. renamed to overlap
04780                         bool overlap = false;
04781                         //int  size = peaks.size();
04782 
04783                         // list of peaks to be deleted, if the current peak is the largest (see below).
04784                         //    list contains iterators to the original list, which will have to be processed
04785                         //    back to front (i.e. LIFO: stl::stack)
04786                         std::stack <vector<Pixel>::iterator> delete_stack;
04787 
04788                         // loop over all peaks found so far. this would be nicer with iterators
04789                         for (vector<Pixel>::iterator it=peaks.begin();it!=peaks.end();++it) {
04790                         // for ( int kk= 0; kk< size; kk++) {
04791                         //  vector<Pixel>::iterator it = peaks.begin()+kk;
04792 
04793                           // calc L2 distance
04794                           float radius=((*it).x-float(i))*((*it).x-float(i))+((*it).y-float(j))*((*it).y-float(j));
04795                           if (radius <= hf_p2 ) {
04796                             // peaks overlap
04797                             if( buf(i,j) > (*it).value) {
04798                               // this peak (indexed by (i,j)) is larger, mark the old for deletion
04799                               //    however, we have to be careful. if there is a larger peak within the vicinity of
04800                               //    the new one, this new peak is not marked as such, and the deletion of prior low
04801                               //    peaks should not continued. to make sure this deletion does not happen, we have
04802                               //    to make sure we cycle through all peaks within the vicinity, and only delete smaller
04803                               //    peaks if this new one is the largest in the vicinity.
04804                               delete_stack.push(it);
04805 
04806                               //(*it).x = -half; // this marks entry to be deleted, since it's smaller than the new one
04807 
04808 
04809                             } else {
04810                               overlap = true;
04811                               // old peak is larger, ignore this one. since it's enough to know there is some peak larger
04812                               //    than this one, we can break out of the peak list loop, instead of continuing.
04813                               break;
04814                             }
04815                           }
04816                         }
04817 
04818                         // check whether we need to delete anything. this is marked by the flag overlap == false
04819                         // loop over all peaks and clean out redundant ones
04820                         if (false == overlap) {
04821                           vector<Pixel>::iterator delete_iterator;
04822                           while (!delete_stack.empty()) {
04823                             // pop empties the stack from the back. since we are dealing with iterators, we need to delete
04824                             //    from the back, so as to keep the rest stack intact upon deletion.
04825                             delete_iterator = delete_stack.top();
04826                             peaks.erase(delete_iterator);
04827                             delete_stack.pop();
04828                           }
04829                           // before pushing the peak, we need to check whether max queue length is exceeded and delete
04830                           //     peaks if necessary.
04831                           // XXX: remove hardcoded value!
04832                           if (! (peaks.size() < 2000 )) {
04833 
04834                             //cout << ".";
04835                             // we need to delete a peak first.
04836                             // - resort list to get lowest peak at the back
04837                             sort(peaks.begin(), peaks.end(), peakcmp);
04838 
04839                             // - remove lowest peak
04840                             peaks.pop_back();
04841                           }
04842 
04843                           // push the new peak onto the list of peaks
04844                           peaks.push_back(Pixel(i,j,0,buf(i,j)));
04845                           //cout << "done." << endl;
04846 
04847                         } else {
04848                           // this peak too small and is ignored, so delete_list is ignored as well. make sure delete_list
04849                           //    is empty. probably redundant because of scope, but better safe than sorry.....
04850                           while (!delete_stack.empty()) delete_stack.pop();
04851                         }
04852                       }
04853                     }
04854                   }}}}}}}
04855     }
04856   }
04857 
04858   // we have peaks, so build a results vector.
04859   if(peaks.size()>0) {
04860     // sort peaks by size
04861     sort(peaks.begin(),peaks.end(), peakcmp);
04862     // and push all peaks to the results vector
04863     for (vector<Pixel>::iterator it = peaks.begin(); it != peaks.end(); it++) {
04864       // XXX: this format is necessary for Boost to work???
04865       res.push_back((*it).value);
04866       res.push_back(static_cast<float>((*it).x));
04867       res.push_back(static_cast<float>((*it).y));
04868     }
04869   } else {
04870     // only one or zero (?) entries
04871     res.push_back(buf(0,0,0));
04872     res.insert(res.begin(),1,0.0);
04873   }
04874   return res;
04875 }

vector< float > EMData::peak_search ( int  ml,
float  invert 
)

Definition at line 3735 of file emdata_sparx.cpp.

References get_ndim(), get_xsize(), get_ysize(), get_zsize(), nx, ny, nz, and peakcmp().

03735                                                       {
03736 
03737         EMData& buf = *this;
03738         vector<Pixel> peaks;
03739         int img_dim;
03740         int i, j, k;
03741         int i__1, i__2;
03742         int j__1, j__2;
03743         //int k__1, k__2;
03744         bool peak_check;
03745         img_dim=buf.get_ndim();
03746         vector<int> ix, jy, kz;
03747         vector<float>res;
03748         int nx = buf.get_xsize();
03749         int ny = buf.get_ysize();
03750         int nz = buf.get_zsize();
03751         if(invert <= 0.0f)  invert=-1.0f;
03752         else                invert=1.0f ;
03753         int count = 0;
03754         switch (img_dim)  {
03755         case(1):
03756                 for(i=0;i<=nx-1;++i)  {
03757                         i__1 = (i-1+nx)%nx;
03758                         i__2 = (i+1)%nx;
03759                         // Commented by Yang on 05/14/07
03760                         // I changed the following line from > to >=, or in some rare cases (the peak happens to be flat), it will fail to find the peak.
03761                         //  03/07/08  I undid the change.  If you change the comparison, it changes the meaning of peak definition.
03762                         float qbf = buf(i)*invert;
03763                         peak_check = qbf > buf(i__1)*invert && qbf > buf(i__2)*invert;
03764                         if(peak_check) {
03765                                 if(count < ml) {
03766                                         count++;
03767                                         peaks.push_back( Pixel(i, 0, 0, qbf) );
03768                                         if(count == ml-1) sort(peaks.begin(), peaks.end(), peakcmp);
03769                                 } else {
03770                                         if( qbf > (peaks.back()).value ) {
03771                                                 //  do the switch and sort again
03772                                                 peaks.pop_back();
03773                                                 peaks.push_back( Pixel(i, 0, 0, qbf) );
03774                                                 if(ml > 1) sort(peaks.begin(), peaks.end(), peakcmp);
03775                                         }
03776                                 }
03777                         }
03778                 }
03779         break;
03780         case(2):
03781         /*  Removed boundary conditions, PAP 03/10/08
03782                 for(j=0;j<=ny-1;++j)  {
03783                         j__1 = (j-1+ny)%ny;
03784                         j__2 = (j+1)%ny;
03785                         for(i=0;i<=nx-1;++i) {
03786                                 i__1 = (i-1+nx)%nx;
03787                                 i__2 = (i+1)%nx;
03788         */
03789                 for(j=1;j<=ny-2;++j)  {
03790                         j__1 = j-1;
03791                         j__2 = j+1;
03792                         for(i=1;i<=nx-2;++i) {
03793                                 i__1 = i-1;
03794                                 i__2 = i+1;
03795                                 float qbf = buf(i,j)*invert;
03796                                 peak_check = (qbf > buf(i,j__1)*invert) && (qbf > buf(i,j__2)*invert);
03797                                 if(peak_check) {
03798                                         peak_check = (qbf > buf(i__1,j)*invert) && (qbf > buf(i__2,j)*invert);
03799                                         if(peak_check) {
03800                                                 peak_check = (qbf > buf(i__1,j__1)*invert) && (qbf > buf(i__1,j__2)*invert);
03801                                                 if(peak_check) {
03802                                                         peak_check = (qbf > buf(i__2,j__1)*invert) && (qbf > buf(i__2,j__2)*invert);
03803                                                         if(peak_check) {
03804                                                                 if(count < ml) {
03805                                                                         count++;
03806                                                                         peaks.push_back( Pixel(i, j, 0, qbf) );
03807                                                                         if(count == ml-1) sort(peaks.begin(), peaks.end(), peakcmp);
03808                                                                 } else {
03809                                                                         if( qbf > (peaks.back()).value ) {
03810                                                                                 //  do the switch and sort again
03811                                                                                 peaks.pop_back();
03812                                                                                 peaks.push_back( Pixel(i, j, 0, qbf) );
03813                                                                                 if(ml > 1) sort(peaks.begin(), peaks.end(), peakcmp);
03814                                                                         }
03815                                                                 }
03816                                                         }
03817                                                 }
03818                                         }
03819                                 }
03820                         }
03821                 }
03822         break;
03823         case(3):  //looks ugly, but it is the best I can do,  PAP 03/07/08
03824         /*  Removed boundary conditions, PAP 03/10/08
03825                 for(k=0;k<=nz-1;++k) {
03826                         kz.clear();
03827                         k__1 = (k-1+nz)%nz;
03828                         k__2 = (k+1)%nz;
03829                         kz.push_back(k__1);
03830                         kz.push_back(k);
03831                         kz.push_back(k__2);
03832                         for(j=0;j<=ny-1;++j) {
03833                                 jy.clear();
03834                                 j__1 = (j-1+ny)%ny;
03835                                 j__2 = (j+1)%ny;
03836                                 jy.push_back(j__1);
03837                                 jy.push_back(j);
03838                                 jy.push_back(j__2);
03839                                 for(i=0;i<=nx-1;++i) {
03840                                         ix.clear();
03841                                         i__1 = (i-1+nx)%nx;
03842                                         i__2 = (i+1)%nx;
03843         */
03844                 for(k=1; k<=nz-2; ++k) {
03845                         kz.clear();
03846                         kz.push_back(k-1);
03847                         kz.push_back(k);
03848                         kz.push_back(k+1);
03849                         for(j=1; j<=ny-2; ++j) {
03850                                 jy.clear();
03851                                 jy.push_back(j-1);
03852                                 jy.push_back(j);
03853                                 jy.push_back(j+1);
03854                                 for(i=1; i<=nx-2; ++i) {
03855                                         ix.clear();
03856                                         ix.push_back(i-1);
03857                                         ix.push_back(i);
03858                                         ix.push_back(i+1);
03859                                         float qbf = buf(i,j,k)*invert;
03860                                         peak_check = qbf > buf(ix[0],jy[0],kz[0])*invert;
03861                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[0])*invert;
03862                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[0])*invert;
03863                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[0])*invert;
03864                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[0])*invert;
03865                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[0])*invert;
03866                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[0])*invert;
03867                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[0])*invert;
03868                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[0])*invert;
03869                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[1])*invert;
03870                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[1])*invert;
03871                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[1])*invert;
03872                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[1])*invert;
03873                                         //if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[1])*invert;
03874                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[1])*invert;
03875                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[1])*invert;
03876                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[1])*invert;
03877                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[1])*invert;
03878                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[2])*invert;
03879                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[2])*invert;
03880                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[2])*invert;
03881                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[2])*invert;
03882                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[2])*invert;
03883                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[2])*invert;
03884                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[2])*invert;
03885                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[2])*invert;
03886                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[2])*invert;
03887                                         if(peak_check) {
03888                                                 if(count < ml) {
03889                                                         count++;
03890                                                         peaks.push_back( Pixel(i, j, k, qbf) );
03891                                                         if(count == ml-1) sort(peaks.begin(), peaks.end(), peakcmp);
03892                                                 } else {
03893                                                         if( qbf > (peaks.back()).value ) {
03894                                                                 //  do the switch and sort again
03895                                                                 //cout << qbf<<"   "<< (peaks.back()).value <<"   "<< (*peaks.begin()).value <<endl;
03896                                                                 peaks.pop_back();
03897                                                                 peaks.push_back( Pixel(i, j, k, qbf) );
03898                                                                 if(ml > 1) sort(peaks.begin(), peaks.end(), peakcmp);
03899                                                         }
03900                                                 }
03901                                         }
03902                                         }}}}}}}}}}}}}}}}}}}}}}}}}
03903                                 }
03904                         }
03905                 }
03906                 //  Add circular closure for x direction: needed for circular ccf,
03907                 //  should not have adverse impact on other code.  PAP -7/22/08
03908                 for(k=1; k<=nz-2; ++k) {
03909                         kz.clear();
03910                         kz.push_back(k-1);
03911                         kz.push_back(k);
03912                         kz.push_back(k+1);
03913                         for(j=1; j<=ny-2; ++j) {
03914                                 jy.clear();
03915                                 jy.push_back(j-1);
03916                                 jy.push_back(j);
03917                                 jy.push_back(j+1);
03918                                 for(i=0; i<=0; ++i) {
03919                                         ix.clear();
03920                                         ix.push_back(nx-1);
03921                                         ix.push_back(i);
03922                                         ix.push_back(i+1);
03923                                         float qbf = buf(i,j,k)*invert;
03924                                         peak_check = qbf > buf(ix[0],jy[0],kz[0])*invert;
03925                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[0])*invert;
03926                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[0])*invert;
03927                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[0])*invert;
03928                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[0])*invert;
03929                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[0])*invert;
03930                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[0])*invert;
03931                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[0])*invert;
03932                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[0])*invert;
03933                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[1])*invert;
03934                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[1])*invert;
03935                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[1])*invert;
03936                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[1])*invert;
03937                                         //if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[1])*invert;
03938                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[1])*invert;
03939                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[1])*invert;
03940                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[1])*invert;
03941                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[1])*invert;
03942                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[2])*invert;
03943                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[2])*invert;
03944                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[2])*invert;
03945                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[2])*invert;
03946                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[2])*invert;
03947                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[2])*invert;
03948                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[2])*invert;
03949                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[2])*invert;
03950                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[2])*invert;
03951                                         if(peak_check) {
03952                                                 if(count < ml) {
03953                                                         count++;
03954                                                         peaks.push_back( Pixel(i, j, k, qbf) );
03955                                                         if(count == ml-1) sort(peaks.begin(), peaks.end(), peakcmp);
03956                                                 } else {
03957                                                         if( qbf > (peaks.back()).value ) {
03958                                                                 //  do the switch and sort again
03959                                                                 //cout << qbf<<"   "<< (peaks.back()).value <<"   "<< (*peaks.begin()).value <<endl;
03960                                                                 peaks.pop_back();
03961                                                                 peaks.push_back( Pixel(i, j, k, qbf) );
03962                                                                 if(ml > 1) sort(peaks.begin(), peaks.end(), peakcmp);
03963                                                         }
03964                                                 }
03965                                         }
03966                                         }}}}}}}}}}}}}}}}}}}}}}}}}
03967                                 }
03968                                 for(i=nx-1; i<=nx-1; ++i) {
03969                                         ix.clear();
03970                                         ix.push_back(i-1);
03971                                         ix.push_back(i);
03972                                         ix.push_back(0);
03973                                         float qbf = buf(i,j,k)*invert;
03974                                         peak_check = qbf > buf(ix[0],jy[0],kz[0])*invert;
03975                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[0])*invert;
03976                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[0])*invert;
03977                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[0])*invert;
03978                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[0])*invert;
03979                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[0])*invert;
03980                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[0])*invert;
03981                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[0])*invert;
03982                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[0])*invert;
03983                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[1])*invert;
03984                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[1])*invert;
03985                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[1])*invert;
03986                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[1])*invert;
03987                                         //if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[1])*invert;
03988                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[1])*invert;
03989                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[1])*invert;
03990                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[1])*invert;
03991                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[1])*invert;
03992                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[2])*invert;
03993                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[2])*invert;
03994                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[2])*invert;
03995                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[2])*invert;
03996                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[2])*invert;
03997                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[2])*invert;
03998                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[2])*invert;
03999                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[2])*invert;
04000                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[2])*invert;
04001                                         if(peak_check) {
04002                                                 if(count < ml) {
04003                                                         count++;
04004                                                         peaks.push_back( Pixel(i, j, k, qbf) );
04005                                                         if(count == ml-1) sort(peaks.begin(), peaks.end(), peakcmp);
04006                                                 } else {
04007                                                         if( qbf > (peaks.back()).value ) {
04008                                                                 //  do the switch and sort again
04009                                                                 //cout << qbf<<"   "<< (peaks.back()).value <<"   "<< (*peaks.begin()).value <<endl;
04010                                                                 peaks.pop_back();
04011                                                                 peaks.push_back( Pixel(i, j, k, qbf) );
04012                                                                 if(ml > 1) sort(peaks.begin(), peaks.end(), peakcmp);
04013                                                         }
04014                                                 }
04015                                         }
04016                                         }}}}}}}}}}}}}}}}}}}}}}}}}
04017                                 }
04018                         }
04019                 }
04020         break;
04021 /*      case(5):  //looks ugly, but it is the best I can do,  PAP 03/07/08
04022         int nu = buf.get_usize();
04023         int nv = buf.get_vsize();
04024         vector<int> lu, mv;
04025                 for(m=1; m<=nv-2; ++m) {
04026                         mv.clear();
04027                         mv.push_back(m-1);
04028                         mv.push_back(m);
04029                         mv.push_back(m+1);
04030                 for(l=1; l<=nu-2; ++l) {
04031                         lu.clear();
04032                         lu.push_back(l-1);
04033                         lu.push_back(l);
04034                         lu.push_back(l+1);
04035                 for(k=1; k<=nz-2; ++k) {
04036                         kz.clear();
04037                         kz.push_back(k-1);
04038                         kz.push_back(k);
04039                         kz.push_back(k+1);
04040                         for(j=1; j<=ny-2; ++j) {
04041                                 jy.clear();
04042                                 jy.push_back(j-1);
04043                                 jy.push_back(j);
04044                                 jy.push_back(j+1);
04045                                 for(i=1; i<=nx-2; ++i) {
04046                                         ix.clear();
04047                                         ix.push_back(i-1);
04048                                         ix.push_back(i);
04049                                         ix.push_back(i+1);
04050                                         float qbf = buf(i,j,k,l,m)*invert;
04051                                         peak_check = qbf > buf(ix[0],jy[0],kz[0],lu[0],mv[0])*invert;
04052                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[0],lu[0],mv[0])*invert;
04053                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[0],lu[0],mv[0])*invert;
04054                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[0],lu[0],mv[0])*invert;
04055                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[0],lu[0],mv[0])*invert;
04056                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[0],lu[0],mv[0])*invert;
04057                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[0],lu[0],mv[0])*invert;
04058                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[0],lu[0],mv[0])*invert;
04059                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[0],lu[0],mv[0])*invert;
04060                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[1],lu[0],mv[0])*invert;
04061                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[1],lu[0],mv[0])*invert;
04062                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[1],lu[0],mv[0])*invert;
04063                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[1],lu[0],mv[0])*invert;
04064                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[1],lu[0],mv[0])*invert;
04065                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[1],lu[0],mv[0])*invert;
04066                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[1],lu[0],mv[0])*invert;
04067                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[1],lu[0],mv[0])*invert;
04068                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[1],lu[0],mv[0])*invert;
04069                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[2],lu[0],mv[0])*invert;
04070                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[2],lu[0],mv[0])*invert;
04071                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[2],lu[0],mv[0])*invert;
04072                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[2],lu[0],mv[0])*invert;
04073                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[2],lu[0],mv[0])*invert;
04074                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[2],lu[0],mv[0])*invert;
04075                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[2],lu[0],mv[0])*invert;
04076                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[2],lu[0],mv[0])*invert;
04077                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[2],lu[0],mv[0])*invert;
04078 
04079                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[0],lu[1],mv[0])*invert;
04080                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[0],lu[1],mv[0])*invert;
04081                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[0],lu[1],mv[0])*invert;
04082                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[0],lu[1],mv[0])*invert;
04083                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[0],lu[1],mv[0])*invert;
04084                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[0],lu[1],mv[0])*invert;
04085                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[0],lu[1],mv[0])*invert;
04086                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[0],lu[1],mv[0])*invert;
04087                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[0],lu[1],mv[0])*invert;
04088                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[1],lu[1],mv[0])*invert;
04089                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[1],lu[1],mv[0])*invert;
04090                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[1],lu[1],mv[0])*invert;
04091                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[1],lu[1],mv[0])*invert;
04092                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[1],lu[1],mv[0])*invert;
04093                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[1],lu[1],mv[0])*invert;
04094                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[1],lu[1],mv[0])*invert;
04095                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[1],lu[1],mv[0])*invert;
04096                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[1],lu[1],mv[0])*invert;
04097                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[2],lu[1],mv[0])*invert;
04098                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[2],lu[1],mv[0])*invert;
04099                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[2],lu[1],mv[0])*invert;
04100                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[2],lu[1],mv[0])*invert;
04101                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[2],lu[1],mv[0])*invert;
04102                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[2],lu[1],mv[0])*invert;
04103                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[2],lu[1],mv[0])*invert;
04104                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[2],lu[1],mv[0])*invert;
04105                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[2],lu[1],mv[0])*invert;
04106 
04107                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[0],lu[2],mv[0])*invert;
04108                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[0],lu[2],mv[0])*invert;
04109                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[0],lu[2],mv[0])*invert;
04110                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[0],lu[2],mv[0])*invert;
04111                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[0],lu[2],mv[0])*invert;
04112                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[0],lu[2],mv[0])*invert;
04113                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[0],lu[2],mv[0])*invert;
04114                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[0],lu[2],mv[0])*invert;
04115                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[0],lu[2],mv[0])*invert;
04116                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[1],lu[2],mv[0])*invert;
04117                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[1],lu[2],mv[0])*invert;
04118                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[1],lu[2],mv[0])*invert;
04119                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[1],lu[2],mv[0])*invert;
04120                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[1],lu[2],mv[0])*invert;
04121                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[1],lu[2],mv[0])*invert;
04122                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[1],lu[2],mv[0])*invert;
04123                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[1],lu[2],mv[0])*invert;
04124                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[1],lu[2],mv[0])*invert;
04125                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[2],lu[2],mv[0])*invert;
04126                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[2],lu[2],mv[0])*invert;
04127                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[2],lu[2],mv[0])*invert;
04128                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[2],lu[2],mv[0])*invert;
04129                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[2],lu[2],mv[0])*invert;
04130                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[2],lu[2],mv[0])*invert;
04131                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[2],lu[2],mv[0])*invert;
04132                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[2],lu[2],mv[0])*invert;
04133                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[2],lu[2],mv[0])*invert;
04134 
04135 
04136                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[0],lu[0],mv[1])*invert;
04137                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[0],lu[0],mv[1])*invert;
04138                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[0],lu[0],mv[1])*invert;
04139                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[0],lu[0],mv[1])*invert;
04140                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[0],lu[0],mv[1])*invert;
04141                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[0],lu[0],mv[1])*invert;
04142                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[0],lu[0],mv[1])*invert;
04143                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[0],lu[0],mv[1])*invert;
04144                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[0],lu[0],mv[1])*invert;
04145                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[1],lu[0],mv[1])*invert;
04146                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[1],lu[0],mv[1])*invert;
04147                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[1],lu[0],mv[1])*invert;
04148                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[1],lu[0],mv[1])*invert;
04149                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[1],lu[0],mv[1])*invert;
04150                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[1],lu[0],mv[1])*invert;
04151                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[1],lu[0],mv[1])*invert;
04152                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[1],lu[0],mv[1])*invert;
04153                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[1],lu[0],mv[1])*invert;
04154                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[2],lu[0],mv[1])*invert;
04155                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[2],lu[0],mv[1])*invert;
04156                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[2],lu[0],mv[1])*invert;
04157                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[2],lu[0],mv[1])*invert;
04158                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[2],lu[0],mv[1])*invert;
04159                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[2],lu[0],mv[1])*invert;
04160                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[2],lu[0],mv[1])*invert;
04161                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[2],lu[0],mv[1])*invert;
04162                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[2],lu[0],mv[1])*invert;
04163 
04164                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[0],lu[1],mv[1])*invert;
04165                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[0],lu[1],mv[1])*invert;
04166                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[0],lu[1],mv[1])*invert;
04167                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[0],lu[1],mv[1])*invert;
04168                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[0],lu[1],mv[1])*invert;
04169                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[0],lu[1],mv[1])*invert;
04170                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[0],lu[1],mv[1])*invert;
04171                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[0],lu[1],mv[1])*invert;
04172                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[0],lu[1],mv[1])*invert;
04173                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[1],lu[1],mv[1])*invert;
04174                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[1],lu[1],mv[1])*invert;
04175                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[1],lu[1],mv[1])*invert;
04176                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[1],lu[1],mv[1])*invert;
04177                                         //if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[1],lu[1],mv[1])*invert;
04178                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[1],lu[1],mv[1])*invert;
04179                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[1],lu[1],mv[1])*invert;
04180                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[1],lu[1],mv[1])*invert;
04181                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[1],lu[1],mv[1])*invert;
04182                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[2],lu[1],mv[1])*invert;
04183                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[2],lu[1],mv[1])*invert;
04184                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[2],lu[1],mv[1])*invert;
04185                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[2],lu[1],mv[1])*invert;
04186                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[2],lu[1],mv[1])*invert;
04187                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[2],lu[1],mv[1])*invert;
04188                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[2],lu[1],mv[1])*invert;
04189                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[2],lu[1],mv[1])*invert;
04190                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[2],lu[1],mv[1])*invert;
04191 
04192                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[0],lu[2],mv[1])*invert;
04193                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[0],lu[2],mv[1])*invert;
04194                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[0],lu[2],mv[1])*invert;
04195                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[0],lu[2],mv[1])*invert;
04196                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[0],lu[2],mv[1])*invert;
04197                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[0],lu[2],mv[1])*invert;
04198                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[0],lu[2],mv[1])*invert;
04199                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[0],lu[2],mv[1])*invert;
04200                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[0],lu[2],mv[1])*invert;
04201                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[1],lu[2],mv[1])*invert;
04202                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[1],lu[2],mv[1])*invert;
04203                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[1],lu[2],mv[1])*invert;
04204                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[1],lu[2],mv[1])*invert;
04205                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[1],lu[2],mv[1])*invert;
04206                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[1],lu[2],mv[1])*invert;
04207                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[1],lu[2],mv[1])*invert;
04208                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[1],lu[2],mv[1])*invert;
04209                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[1],lu[2],mv[1])*invert;
04210                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[2],lu[2],mv[1])*invert;
04211                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[2],lu[2],mv[1])*invert;
04212                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[2],lu[2],mv[1])*invert;
04213                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[2],lu[2],mv[1])*invert;
04214                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[2],lu[2],mv[1])*invert;
04215                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[2],lu[2],mv[1])*invert;
04216                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[2],lu[2],mv[1])*invert;
04217                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[2],lu[2],mv[1])*invert;
04218                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[2],lu[2],mv[1])*invert;
04219 
04220 
04221                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[0],lu[0],mv[2])*invert;
04222                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[0],lu[0],mv[2])*invert;
04223                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[0],lu[0],mv[2])*invert;
04224                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[0],lu[0],mv[2])*invert;
04225                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[0],lu[0],mv[2])*invert;
04226                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[0],lu[0],mv[2])*invert;
04227                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[0],lu[0],mv[2])*invert;
04228                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[0],lu[0],mv[2])*invert;
04229                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[0],lu[0],mv[2])*invert;
04230                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[1],lu[0],mv[2])*invert;
04231                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[1],lu[0],mv[2])*invert;
04232                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[1],lu[0],mv[2])*invert;
04233                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[1],lu[0],mv[2])*invert;
04234                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[1],lu[0],mv[2])*invert;
04235                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[1],lu[0],mv[2])*invert;
04236                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[1],lu[0],mv[2])*invert;
04237                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[1],lu[0],mv[2])*invert;
04238                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[1],lu[0],mv[2])*invert;
04239                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[2],lu[0],mv[2])*invert;
04240                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[2],lu[0],mv[2])*invert;
04241                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[2],lu[0],mv[2])*invert;
04242                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[2],lu[0],mv[2])*invert;
04243                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[2],lu[0],mv[2])*invert;
04244                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[2],lu[0],mv[2])*invert;
04245                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[2],lu[0],mv[2])*invert;
04246                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[2],lu[0],mv[2])*invert;
04247                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[2],lu[0],mv[2])*invert;
04248 
04249                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[0],lu[1],mv[2])*invert;
04250                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[0],lu[1],mv[2])*invert;
04251                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[0],lu[1],mv[2])*invert;
04252                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[0],lu[1],mv[2])*invert;
04253                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[0],lu[1],mv[2])*invert;
04254                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[0],lu[1],mv[2])*invert;
04255                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[0],lu[1],mv[2])*invert;
04256                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[0],lu[1],mv[2])*invert;
04257                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[0],lu[1],mv[2])*invert;
04258                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[1],lu[1],mv[2])*invert;
04259                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[1],lu[1],mv[2])*invert;
04260                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[1],lu[1],mv[2])*invert;
04261                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[1],lu[1],mv[2])*invert;
04262                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[1],lu[1],mv[2])*invert;
04263                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[1],lu[1],mv[2])*invert;
04264                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[1],lu[1],mv[2])*invert;
04265                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[1],lu[1],mv[2])*invert;
04266                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[1],lu[1],mv[2])*invert;
04267                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[2],lu[1],mv[2])*invert;
04268                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[2],lu[1],mv[2])*invert;
04269                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[2],lu[1],mv[2])*invert;
04270                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[2],lu[1],mv[2])*invert;
04271                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[2],lu[1],mv[2])*invert;
04272                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[2],lu[1],mv[2])*invert;
04273                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[2],lu[1],mv[2])*invert;
04274                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[2],lu[1],mv[2])*invert;
04275                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[2],lu[1],mv[2])*invert;
04276 
04277                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[0],lu[2],mv[2])*invert;
04278                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[0],lu[2],mv[2])*invert;
04279                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[0],lu[2],mv[2])*invert;
04280                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[0],lu[2],mv[2])*invert;
04281                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[0],lu[2],mv[2])*invert;
04282                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[0],lu[2],mv[2])*invert;
04283                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[0],lu[2],mv[2])*invert;
04284                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[0],lu[2],mv[2])*invert;
04285                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[0],lu[2],mv[2])*invert;
04286                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[1],lu[2],mv[2])*invert;
04287                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[1],lu[2],mv[2])*invert;
04288                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[1],lu[2],mv[2])*invert;
04289                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[1],lu[2],mv[2])*invert;
04290                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[1],lu[2],mv[2])*invert;
04291                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[1],lu[2],mv[2])*invert;
04292                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[1],lu[2],mv[2])*invert;
04293                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[1],lu[2],mv[2])*invert;
04294                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[1],lu[2],mv[2])*invert;
04295                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[2],lu[2],mv[2])*invert;
04296                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[2],lu[2],mv[2])*invert;
04297                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[2],lu[2],mv[2])*invert;
04298                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[2],lu[2],mv[2])*invert;
04299                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[2],lu[2],mv[2])*invert;
04300                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[2],lu[2],mv[2])*invert;
04301                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[2],lu[2],mv[2])*invert;
04302                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[2],lu[2],mv[2])*invert;
04303                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[2],lu[2],mv[2])*invert;
04304                                         if(peak_check) {
04305                                                 if(count < ml) {
04306                                                         count++;
04307                                                         //peaks.push_back( Pixel(i, j, k, l, m, qbf) );
04308                                                         if(count == ml-1) sort(peaks.begin(), peaks.end(), peakcmp);
04309                                                 } else {
04310                                                         if( qbf > (peaks.back()).value ) {
04311                                                                 //  do the switch and sort again
04312                                                                 //cout << qbf<<"   "<< (peaks.back()).value <<"   "<< (*peaks.begin()).value <<endl;
04313                                                                 peaks.pop_back();
04314                                                                 //peaks.push_back( Pixel(i, j, k, l, m, qbf) );
04315                                                                 if(ml > 1) sort(peaks.begin(), peaks.end(), peakcmp);
04316                                                         }
04317                                                 }
04318                                         }
04319                                         }}}}}}}}}}}}}}}}}}}}}}}}}}
04320                                         }}}}}}}}}}}}}}}}}}}}}}}}}}}
04321                                         }}}}}}}}}}}}}}}}}}}}}}}}}}}
04322                                         }}}}}}}}}}}}}}}}}}}}}}}}}}}
04323                                         }}}}}}}}}}}}}}}}}}}}}}}}}}
04324                                         }}}}}}}}}}}}}}}}}}}}}}}}}}}
04325                                         }}}}}}}}}}}}}}}}}}}}}}}}}}}
04326                                         }}}}}}}}}}}}}}}}}}}}}}}}}}}
04327                                         }}}}}}}}}}}}}}}}}}}}}}}}}}}
04328                                 }
04329                         }
04330                 }
04331                 }
04332                 }
04333                 //  Add circular closure for x, y, and z directions: needed for circular ccf,
04334                 //  should not have adverse impact on other code.  PAP 11/7/08
04335                 for(m=1; m<=nv-2; ++m) {
04336                         mv.clear();
04337                         mv.push_back(m-1);
04338                         mv.push_back(m);
04339                         mv.push_back(m+1);
04340                 for(l=1; l<=nu-2; ++l) {
04341                         lu.clear();
04342                         lu.push_back(l-1);
04343                         lu.push_back(l);
04344                         lu.push_back(l+1);
04345                 for(k=1; k<=nz-2; ++k) {
04346                         kz.clear();
04347                         kz.push_back(k-1);
04348                         kz.push_back(k);
04349                         kz.push_back(k+1);
04350                         for(j=1; j<=ny-2; ++j) {
04351                                 jy.clear();
04352                                 jy.push_back(j-1);
04353                                 jy.push_back(j);
04354                                 jy.push_back(j+1);
04355                                 for(i=0; i<=0; ++i) {
04356                                         ix.clear();
04357                                         ix.push_back(nx-1);
04358                                         ix.push_back(i);
04359                                         ix.push_back(i+1);
04360                                         float qbf = buf(i,j,k)*invert;
04361                                         peak_check = qbf > buf(ix[0],jy[0],kz[0])*invert;
04362                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[0])*invert;
04363                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[0])*invert;
04364                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[0])*invert;
04365                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[0])*invert;
04366                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[0])*invert;
04367                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[0])*invert;
04368                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[0])*invert;
04369                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[0])*invert;
04370                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[1])*invert;
04371                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[1])*invert;
04372                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[1])*invert;
04373                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[1])*invert;
04374                                         //if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[1])*invert;
04375                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[1])*invert;
04376                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[1])*invert;
04377                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[1])*invert;
04378                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[1])*invert;
04379                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[2])*invert;
04380                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[2])*invert;
04381                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[2])*invert;
04382                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[2])*invert;
04383                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[2])*invert;
04384                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[2])*invert;
04385                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[2])*invert;
04386                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[2])*invert;
04387                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[2])*invert;
04388                                         if(peak_check) {
04389                                                 if(count < ml) {
04390                                                         count++;
04391                                                         peaks.push_back( Pixel(i, j, k, qbf) );
04392                                                         if(count == ml-1) sort(peaks.begin(), peaks.end(), peakcmp);
04393                                                 } else {
04394                                                         if( qbf > (peaks.back()).value ) {
04395                                                                 //  do the switch and sort again
04396                                                                 //cout << qbf<<"   "<< (peaks.back()).value <<"   "<< (*peaks.begin()).value <<endl;
04397                                                                 peaks.pop_back();
04398                                                                 peaks.push_back( Pixel(i, j, k, qbf) );
04399                                                                 if(ml > 1) sort(peaks.begin(), peaks.end(), peakcmp);
04400                                                         }
04401                                                 }
04402                                         }
04403                                         }}}}}}}}}}}}}}}}}}}}}}}}}
04404                                 }
04405                                 for(i=nx-1; i<=nx-1; ++i) {
04406                                         ix.clear();
04407                                         ix.push_back(i-1);
04408                                         ix.push_back(i);
04409                                         ix.push_back(0);
04410                                         float qbf = buf(i,j,k)*invert;
04411                                         peak_check = qbf > buf(ix[0],jy[0],kz[0])*invert;
04412                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[0])*invert;
04413                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[0])*invert;
04414                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[0])*invert;
04415                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[0])*invert;
04416                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[0])*invert;
04417                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[0])*invert;
04418                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[0])*invert;
04419                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[0])*invert;
04420                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[1])*invert;
04421                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[1])*invert;
04422                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[1])*invert;
04423                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[1])*invert;
04424                                         //if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[1])*invert;
04425                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[1])*invert;
04426                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[1])*invert;
04427                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[1])*invert;
04428                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[1])*invert;
04429                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[0],kz[2])*invert;
04430                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[0],kz[2])*invert;
04431                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[0],kz[2])*invert;
04432                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[1],kz[2])*invert;
04433                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[1],kz[2])*invert;
04434                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[1],kz[2])*invert;
04435                                         if( peak_check ) {peak_check = qbf > buf(ix[0],jy[2],kz[2])*invert;
04436                                         if( peak_check ) {peak_check = qbf > buf(ix[1],jy[2],kz[2])*invert;
04437                                         if( peak_check ) {peak_check = qbf > buf(ix[2],jy[2],kz[2],3,3)*invert;
04438                                         if(peak_check) {
04439                                                 if(count < ml) {
04440                                                         count++;
04441                                                         peaks.push_back( Pixel(i, j, k, qbf) );
04442                                                         if(count == ml-1) sort(peaks.begin(), peaks.end(), peakcmp);
04443                                                 } else {
04444                                                         if( qbf > (peaks.back()).value ) {
04445                                                                 //  do the switch and sort again
04446                                                                 //cout << qbf<<"   "<< (peaks.back()).value <<"   "<< (*peaks.begin()).value <<endl;
04447                                                                 peaks.pop_back();
04448                                                                 peaks.push_back( Pixel(i, j, k, qbf) );
04449                                                                 if(ml > 1) sort(peaks.begin(), peaks.end(), peakcmp);
04450                                                         }
04451                                                 }
04452                                         }
04453                                         }}}}}}}}}}}}}}}}}}}}}}}}}
04454                                 }
04455                         }
04456                 }
04457                 }
04458                 }
04459         break;*/
04460         }
04461         // do we have a peak list yet?
04462         if (peaks.begin() != peaks.end()) {
04463           // yes. sort it
04464           sort(peaks.begin(), peaks.end(), peakcmp);
04465 
04466           int count = 0;
04467 
04468           float xval = (*peaks.begin()).value;
04469           // loop over all peaks
04470           for (vector<Pixel>::iterator it = peaks.begin(); it != peaks.end(); it++)  {
04471             // current peak count
04472             count++;
04473             // is current peak count below max?
04474             if(count <= ml) {
04475               // yes, so append it
04476               res.push_back((*it).value);
04477               res.push_back(static_cast<float>((*it).x));
04478 
04479               if(img_dim > 1) {
04480                 res.push_back(static_cast<float>((*it).y));
04481                 if(nz > 1) res.push_back(static_cast<float>((*it).z));
04482               }
04483 
04484               if(xval != 0.0) res.push_back((*it).value/xval);
04485               else            res.push_back((*it).value);
04486               res.push_back((*it).x-float(int(nx/2)));
04487               if(img_dim >1) {
04488                 res.push_back((*it).y-float(int(ny/2)));
04489                 if(nz>1)   res.push_back((*it).z-float(nz/2));
04490               }
04491             }
04492           }
04493           res.insert(res.begin(),1,img_dim);
04494         } else {
04495           // no peak list. build empty list
04496           res.push_back(buf(0,0,0));
04497           res.insert(res.begin(),1,0.0);
04498         }
04499 
04500         // return results list
04501         return res;
04502 }

bool EMData::peakcmp ( const Pixel p1,
const Pixel p2 
) [static, private]

Definition at line 3662 of file emdata_sparx.cpp.

References EMAN::Pixel::value.

Referenced by peak_ccf(), and peak_search().

03662                                                      {
03663     return (p1.value > p2.value);
03664 }

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:
InvalidCallException if this image is a real image or is in real/imaginary format

Definition at line 1250 of file emdata_core.cpp.

References data, EMData(), ENTERFUNC, EXITFUNC, get_data(), get_xsize(), get_ysize(), get_zsize(), InvalidCallException, is_real(), is_ri(), nx, ny, nz, set_complex(), set_complex_x(), set_size(), and update().

01251 {
01252         ENTERFUNC;
01253 
01254         EMData * e = new EMData();
01255 
01256         if( is_real() ) {
01257                 delete e;
01258                 throw InvalidCallException("No imaginary part for a real image, this function call require a complex image.");
01259         }
01260         else {
01261                 if(is_ri()) {
01262                         delete e;
01263                         throw InvalidCallException("This image is in real/imaginary format, this function call require a complex image in amplitude/phase format.");
01264                 }
01265 
01266                 int nx = get_xsize();
01267                 int ny = get_ysize();
01268                 int nz = get_zsize();
01269                 e->set_size(nx/2, ny, nz);
01270                 float * edata = e->get_data();
01271                 float * data = get_data();
01272                 size_t idx1, idx2;
01273                 for( int i=0; i<nx; ++i ) {
01274                         for( int j=0; j<ny; ++j ) {
01275                                 for( int k=0; k<nz; ++k ) {
01276                                         if( i%2 == 1 ) {
01277                                                 idx1 = i/2+j*(nx/2)+k*(nx/2)*ny;
01278                                                 idx2 = i+j*nx+k*nx*ny;
01279                                                 //complex data in format [real, complex, real, complex...]
01280                                                 edata[idx1] = data[idx2];
01281                                         }
01282                                 }
01283                         }
01284                 }
01285         }
01286 
01287         e->set_complex(false);
01288         if(e->get_ysize()==1 && e->get_zsize()==1) {
01289                 e->set_complex_x(false);
01290         }
01291         e->update();
01292         return e;
01293 
01294         EXITFUNC;
01295 }

vector< float > EMData::phase_cog (  ) 

Calculate the Phase approximation to center of gravity This operations works for 1-2-3-d images.

Returns:
both the center of gravity and the phase approximated center of gravity values.

Definition at line 4508 of file emdata_sparx.cpp.

References C, get_ndim(), nx, ny, nz, rdata, EMAN::Util::round(), X, Y, and Z.

Referenced by ali3d_d(), and EMAN::PhaseToMassCenterProcessor::process_inplace().

04509 {
04510         vector<float> ph_cntog;
04511         int i=1,j=1,k=1;
04512         float C=0.f,S=0.f,P=0.f,F1=0.f,SNX;
04513         if (get_ndim()==1) {
04514                 P = 8*atan(1.0f)/nx;
04515                 for (i=1;i<=nx;i++) {
04516                         C += cos(P * (i-1)) * rdata(i,j,k);
04517                         S += sin(P * (i-1)) * rdata(i,j,k);
04518                 }
04519                 F1 = atan2(S,C);
04520                 if (F1 < 0.0)  F1 += 8*atan(1.0f);
04521                 SNX = F1/P +1.0f;
04522                 SNX = SNX - ((nx/2)+1);
04523                 ph_cntog.push_back(SNX);
04524 #ifdef _WIN32
04525                 ph_cntog.push_back((float)Util::round(SNX));
04526 #else
04527                 ph_cntog.push_back(round(SNX));
04528 #endif //_WIN32
04529         } else if (get_ndim()==2)  {
04530 #ifdef _WIN32
04531                 float SNY;
04532                 float T=0.0f;
04533                 vector<float> X;
04534                 X.resize(nx);
04535 #else
04536                 float SNY,X[nx],T=0.f;
04537 #endif  //_WIN32
04538                 for ( i=1;i<=nx;i++) X(i)=0.0;
04539                 P = 8*atan(1.0f)/ny;
04540                 for(j=1;j<=ny;j++) {
04541                         T=0.f;
04542                         for(i=1;i<=nx;i++) {
04543                                 T += rdata(i,j,k);
04544                                 X(i)+=rdata(i,j,k);
04545                         }
04546                         C += cos(P*(j-1))*T;
04547                         S += sin(P*(j-1))*T;
04548                 }
04549                 F1=atan2(S,C);
04550                 if(F1<0.0)  F1 += 8*atan(1.0f);
04551                 SNY = F1/P +1.0f;
04552                 C=0.f;  S=0.f;
04553                 P = 8*atan(1.0f)/nx;
04554                 for(i=1;i<=nx;i++) {
04555                         C += cos(P*(i-1))*X(i);
04556                         S += sin(P*(i-1))*X(i);
04557                 }
04558                 F1=atan2(S,C);
04559                 if(F1<0.0) F1 += 8*atan(1.0f);
04560                 SNX = F1/P +1.0f;
04561                 SNX = SNX - ((nx/2)+1);
04562                 SNY = SNY - ((ny/2)+1);
04563                 ph_cntog.push_back(SNX); ph_cntog.push_back(SNY);
04564 #ifdef _WIN32
04565                  ph_cntog.push_back((float)Util::round(SNX)); ph_cntog.push_back((float)Util::round(SNY));
04566 #else
04567                  ph_cntog.push_back(round(SNX)); ph_cntog.push_back(round(SNY));
04568 #endif  //_WIN32
04569         } else {
04570 #ifdef _WIN32
04571                 float val=0.f,sum1=0.f, SNY,SNZ;
04572                 vector<float> X;
04573                 X.resize(nx);
04574                 vector<float> Y;
04575                 Y.resize(ny);
04576                 vector<float> Z;
04577                 Z.resize(nz);
04578 #else
04579                 float val=0.f, sum1=0.f, X[nx], Y[ny], Z[nz], SNY, SNZ;
04580 #endif  //_WIN32
04581                  for (i=1;i<=nx;i++)  X(i)=0.0;
04582                  for (j=1;j<=ny;j++)  Y(j)=0.0;
04583                  for (k=1;k<=nz;k++)  Z(k)=0.0;
04584                  for(k=1;k<=nz;k++)  {
04585                         for(j=1;j<=ny;j++) {
04586                                 sum1=0.f;
04587                                 for(i=1;i<=nx;i++)  {
04588                                         val = rdata(i,j,k);
04589                                         sum1 += val;
04590                                         X(i) += val;
04591                                 }
04592                                 Y(j) += sum1;
04593                                 Z(k) += sum1;
04594                         }
04595                 }
04596                 P = 8*atan(1.0f)/nx;
04597                 for (i=1;i<=nx;i++) {
04598                         C += cos(P*(i-1))*X(i);
04599                         S += sin(P*(i-1))*X(i);
04600                 }
04601                 F1=atan2(S,C);
04602                 if(F1<0.0) F1 += 8*atan(1.0f);
04603                 SNX = F1/P +1.0f;
04604                 C=0.f;  S=0.f;
04605                 P = 8*atan(1.0f)/ny;
04606                 for(j=1;j<=ny;j++) {
04607                         C += cos(P*(j-1))*Y(j);
04608                         S += sin(P*(j-1))*Y(j);
04609                 }
04610                 F1=atan2(S,C);
04611                 if(F1<0.0)  F1 += 8*atan(1.0f);
04612                 SNY = F1/P +1.0f;
04613                 C=0.f;  S=0.f;
04614                 P = 8*atan(1.0f)/nz;
04615                 for(k=1;k<=nz;k++) {
04616                         C += cos(P*(k-1))*Z(k);
04617                         S += sin(P*(k-1))*Z(k);
04618                 }
04619                 F1=atan2(S,C);
04620                 if(F1<0.0)  F1 += 8*atan(1.0f);
04621                 SNZ = F1/P +1.0f;
04622                 SNX = SNX - ((nx/2)+1);
04623                 SNY = SNY - ((ny/2)+1);
04624                 SNZ = SNZ - ((nz/2)+1);
04625                 ph_cntog.push_back(SNX); ph_cntog.push_back(SNY); ph_cntog.push_back(SNZ);
04626 #ifdef _WIN32
04627                 ph_cntog.push_back((float)Util::round(SNX)); ph_cntog.push_back((float)Util::round(SNY)); ph_cntog.push_back((float)Util::round(SNZ));
04628 #else
04629                 ph_cntog.push_back(round(SNX)); ph_cntog.push_back(round(SNY));ph_cntog.push_back(round(SNZ));
04630 #endif
04631         }
04632         return ph_cntog;
04633 }

EMData * EMData::power ( int  n  )  const

return a image to the power of n

Parameters:
n the power of this image
Returns:
a image which is the nth power of this image
Exceptions:
InvalidValueException n must be >= 0

Definition at line 925 of file emdata_core.cpp.

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

00926 {
00927         ENTERFUNC;
00928 
00929         if( n<0 ) {
00930                 throw InvalidValueException(n, "the power of negative integer not supported.");
00931         }
00932 
00933         EMData * r = this->copy();
00934         if( n == 0 ) {
00935                 r->to_one();
00936         }
00937         else if( n>1 ) {
00938                 for( int i=1; i<n; i++ ) {
00939                         *r *= *this;
00940                 }
00941         }
00942 
00943         r->update();
00944         return r;
00945 
00946         EXITFUNC;
00947 }

void EMData::print_image ( const string  str = string(""),
ostream &  out = std::cout 
)

Print the image data to a file stream (standard out by default).

Parameters:
out Output stream; cout by default.
str Message string to be printed.

Definition at line 299 of file emdata_io.cpp.

References get_xsize(), get_ysize(), get_zsize(), nx, ny, and nz.

00299                                                        {
00300         out << "Printing EMData object: " << str << std::endl;
00301         int nx = get_xsize();
00302         int ny = get_ysize();
00303         int nz = get_zsize();
00304         for (int iz = 0; iz < nz; iz++) {
00305                 out << "(z = " << iz << " slice)" << std::endl;
00306                 for (int ix = 0; ix < nx; ix++) {
00307                         for (int iy = 0; iy < ny; iy++) {
00308                                 out << setiosflags(std::ios::fixed)
00309                                         << setiosflags(std::ios_base::scientific)
00310                                         << std::setw(12)
00311                                          << std::setprecision(5) << (*this)(ix,iy,iz) << "  ";
00312                                 if (((iy+1) % 6) == 0) {
00313                                         out << std::endl << "   ";
00314                                 }
00315                         }
00316                         out << std::endl;
00317                 }
00318         }
00319 }

EMData * EMData::process ( Processor p  )  const

Call the process with an instance od Processor, usually this instance can be get by (in Python) Processors.get("name", {'k':v, 'k':v}).

Parameters:
p the processor pointer

Definition at line 86 of file emdata_modular.cpp.

References ENTERFUNC, EXITFUNC, and EMAN::Processor::process().

00087 {
00088         ENTERFUNC;
00089         EMData * result = 0;
00090         if(p) {
00091                 result = p->process(this);
00092         }
00093         return result;
00094         EXITFUNC;
00095 }

EMData * EMData::process ( const string &  processorname,
const Dict params = Dict() 
) const

Apply a processor with its parameters on a copy of this image, return result as a a new image.

The returned image may or may not be the same size as this image.

Parameters:
processorname Processor Name.
params Processor parameters in a keyed dictionary.
Returns:
the processed result, a new image
Exceptions:
NotExistingObjectError If the processor doesn't exist.

Definition at line 69 of file emdata_modular.cpp.

References ENTERFUNC, EXITFUNC, and EMAN::Processor::process().

Referenced by EMAN::RT3DSphereAligner::align(), EMAN::RT3DGridAligner::align(), EMAN::Refine3DAligner::align(), EMAN::RefineAligner::align(), EMAN::RTFSlowExhaustiveAligner::align(), EMAN::RTFExhaustiveAligner::align(), EMAN::RotateFlipAligner::align(), EMAN::RotateTranslateFlipAligner::align(), EMAN::RotatePrecenterAligner::align(), EMAN::RotationalAligner::align(), EMAN::TranslationalAligner::align(), EMAN::RotationalAligner::align_180_ambiguous(), EMAN::MarchingCubes::calculate_min_max_vals(), EMAN::SqEuclideanCmp::cmp(), EMAN::FourierReconstructorSimple2D::insert_slice(), make_rotational_footprint_e1(), EMAN::BackProjectionReconstructor::preprocess_slice(), EMAN::FourierReconstructor::preprocess_slice(), EMAN::ScaleTransformProcessor::process(), refalifn(), refalifn3d(), EMAN::RT3DSphereAligner::xform_align_nbest(), and EMAN::RT3DGridAligner::xform_align_nbest().

00070 {
00071         ENTERFUNC;
00072         Processor *f = Factory < Processor >::get(processorname, params);
00073         EMData * result = 0;
00074         if (f) {
00075                 result = f->process(this);
00076                 if( f )
00077                 {
00078                         delete f;
00079                         f = 0;
00080                 }
00081         }
00082         return result;
00083         EXITFUNC;
00084 }

void EMData::process_inplace ( Processor p  ) 

Call the process_inplace with an instance od Processor, usually this instancecan be get by (in Python) Processors.get("name", {'k':v, 'k':v}).

Parameters:
p the processor pointer

Definition at line 60 of file emdata_modular.cpp.

References ENTERFUNC, EXITFUNC, and EMAN::Processor::process_inplace().

00061 {
00062         ENTERFUNC;
00063         if(p) {
00064                 p->process_inplace(this);
00065         }
00066         EXITFUNC;
00067 }

void EMData::process_inplace ( const string &  processorname,
const Dict params = Dict() 
)

Apply a processor with its parameters on this image.

Parameters:
processorname Processor Name.
params Processor parameters in a keyed dictionary.
Exceptions:
NotExistingObjectError If the processor doesn't exist.

Definition at line 45 of file emdata_modular.cpp.

References ENTERFUNC, EXITFUNC, and EMAN::Processor::process_inplace().

Referenced by ali3d_d(), EMAN::RotateFlipAligner::align(), EMAN::RotateTranslateFlipAligner::align(), EMAN::RotateTranslateAligner::align(), EMAN::TranslationalAligner::align(), bispecRotTransInvDirect(), bispecRotTransInvN(), calc_fast_sigma_image(), calc_flcf(), calc_mutual_correlation(), EMAN::TomoDotCmp::cmp(), EMAN::FFTResampleProcessor::fft_resample(), FH2Real(), EMAN::FourierReconstructor::finish(), EMAN::FourierReconstructorSimple2D::finish(), get_circle_mean(), get_const_data(), main(), make_footprint(), make_rotational_footprint_cmc(), make_rotational_footprint_e1(), EMAN::multi_processors(), EMAN::padfft_slice(), EMAN::BackProjectionReconstructor::preprocess_slice(), EMAN::FourierReconstructor::preprocess_slice(), EMAN::ScaleTransformProcessor::process(), EMAN::ZGradientProcessor::process_inplace(), EMAN::YGradientProcessor::process_inplace(), EMAN::TomoTiltEdgeMaskProcessor::process_inplace(), EMAN::XGradientProcessor::process_inplace(), EMAN::TestTomoImage::process_inplace(), EMAN::ScaleTransformProcessor::process_inplace(), EMAN::TestImageFourierNoiseProfile::process_inplace(), EMAN::CTFSNRWeightProcessor::process_inplace(), EMAN::TestImageFourierNoiseGaussian::process_inplace(), EMAN::AutoMask3D2Processor::process_inplace(), EMAN::IndexMaskFileProcessor::process_inplace(), EMAN::LocalNormProcessor::process_inplace(), EMAN::SNRProcessor::process_inplace(), EMAN::AutoMask2DProcessor::process_inplace(), EMAN::FlipProcessor::process_inplace(), EMAN::NormalizeRampNormVar::process_inplace(), EMAN::FlattenBackgroundProcessor::process_inplace(), EMAN::SNREvalProcessor::process_inplace(), EMAN::GaussFFTProjector::project3d(), and translate().

00046 {
00047         ENTERFUNC;
00048         Processor *f = Factory < Processor >::get(processorname, params);
00049         if (f) {
00050                 f->process_inplace(this);
00051                 if( f )
00052                 {
00053                         delete f;
00054                         f = 0;
00055                 }
00056         }
00057         EXITFUNC;
00058 }

EMData * EMData::project ( const string &  projector_name,
const Transform t3d 
)

Calculate the projection of this image and return the result.

Parameters:
projector_name Projection algorithm name.
t3d Transform object used to do projection.
Exceptions:
NotExistingObjectError If the projection algorithm doesn't exist.
Returns:
The result image.

Definition at line 173 of file emdata_modular.cpp.

References ENTERFUNC, EXITFUNC, and EMAN::Projector::project3d().

00174 {
00175         ENTERFUNC;
00176         EMData *result = 0;
00177         Dict params;
00178         params["transform"] = (Transform*) &t3d;
00179         Projector *p = Factory < Projector >::get(projector_name, params);
00180         if (p) {
00181                 result = p->project3d(this);
00182                 if( p )
00183                 {
00184                         delete p;
00185                         p = 0;
00186                 }
00187         }
00188 
00189         EXITFUNC;
00190         return result;
00191 }

EMData * EMData::project ( const string &  projector_name,
const Dict params = Dict() 
)

Calculate the projection of this image and return the result.

Parameters:
projector_name Projection algorithm name.
params Projection Algorithm parameters.
Exceptions:
NotExistingObjectError If the projection algorithm doesn't exist.
Returns:
The result image.

Definition at line 154 of file emdata_modular.cpp.

References ENTERFUNC, EXITFUNC, and EMAN::Projector::project3d().

Referenced by ali3d_d(), and main().

00155 {
00156         ENTERFUNC;
00157         EMData *result = 0;
00158         Projector *p = Factory < Projector >::get(projector_name, params);
00159         if (p) {
00160                 result = p->project3d(this);
00161                 if( p )
00162                 {
00163                         delete p;
00164                         p = 0;
00165                 }
00166         }
00167 
00168         EXITFUNC;
00169         return result;
00170 }

void EMData::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.

The image should already have the correct dimensions.

Parameters:
fsp The filename to read the image data from
loc Location to seek to in the file before writing (size_t)
area The image region you want to read, default 0 means read the whole image
file_nx Image x size.
file_ny Image y size.
file_nz Image z size.
Author:
Steve Ludtke
Date:
Mon Jun 23, 2008

Definition at line 268 of file emdata_metadata.cpp.

References FileAccessException, get_data(), nx, ny, nz, portable_fseek(), EMAN::EMUtil::process_region_io(), and EMAN::ImageIO::READ_ONLY.

00268                                                                                                                         {
00269         FILE *f = 0;
00270         f=fopen(fsp.c_str(), "rb");
00271         if (!f) throw FileAccessException(fsp);
00272         int fnx = nx;
00273         if (file_nx != 0) fnx = file_nx;
00274         int fny = ny;
00275         if (file_ny != 0) fny = file_ny;
00276         int fnz = nz;
00277         if (file_nz != 0) fnz = file_nz;
00278 
00279         portable_fseek(f,loc,SEEK_SET);
00280         EMUtil::process_region_io(get_data(), f, ImageIO::READ_ONLY,
00281                                                           0, 4,fnx,fny,fnz,area);
00282 //      portable_fseek(f,loc,SEEK_SET);
00283 //      if (fread(get_data(),nx*ny,nz*4,f)!=(size_t)(nz*4)) throw FileAccessException(fsp);
00284         fclose(f);
00285 }

void EMData::read_image ( const string &  filename,
int  img_index = 0,
bool  header_only = false,
const Region region = 0,
bool  is_3d = false 
)

read an image file and stores its information to this EMData object.

If a region is given, then only read a region of the image file. The region will be this EMData object. The given region must be inside the given image file. Otherwise, an error will be created.

Parameters:
filename The image file name.
img_index The nth image you want to read.
header_only To read only the header or both header and data.
region To read only a region of the image.
is_3d Whether to treat the image as a single 3D or a set of 2Ds. This is a hint for certain image formats which has no difference between 3D image and set of 2Ds.
Exceptions:
ImageFormatException 
ImageReadException 

Definition at line 48 of file emdata_io.cpp.

References attr_dict, ENTERFUNC, EXITFUNC, get_data(), EMAN::EMUtil::get_imageio(), EMAN::Dict::has_key(), ImageFormatException, ImageReadException, EMAN::ImageIO::is_complex_mode(), nx, ny, nz, EMAN::ImageIO::read_data(), EMAN::ImageIO::read_header(), EMAN::ImageIO::READ_ONLY, save_byteorder_to_dict(), set_complex(), set_fftodd(), set_fftpad(), set_ri(), set_size(), to_zero(), and update().

Referenced by EMAN::PCA::dopca_ooc(), EMAN::TestUtil::dump_image_from_file(), EMData(), EMAN::Util::eval(), EMAN::PCA::Lanczos_ooc(), main(), ParseAlignOptions(), EMAN::CoordinateMaskFileProcessor::process_inplace(), EMAN::IndexMaskFileProcessor::process_inplace(), ReadVandBcast(), and EMAN::TestUtil::verify_image_file_by_mode().

00050 {
00051         ENTERFUNC;
00052 
00053         ImageIO *imageio = EMUtil::get_imageio(filename, ImageIO::READ_ONLY);
00054 
00055         if (!imageio) {
00056                 throw ImageFormatException("cannot create an image io");
00057         }
00058         else {
00059                 int err = imageio->read_header(attr_dict, img_index, region, is_3d);
00060                 if (err) {
00061                         throw ImageReadException(filename, "imageio read header failed");
00062                 }
00063                 else {
00064                         if (imageio->is_complex_mode()) {
00065                                 set_complex(true);
00066                                 set_fftpad(true);
00067                         }
00068                         if (attr_dict.has_key("is_fftodd") && (int)attr_dict["is_fftodd"] == 1) {
00069                                 set_fftodd(true);
00070                         }
00071                         if ((int) attr_dict["is_complex_ri"] == 1) {
00072                                 set_ri(true);
00073                         }
00074                         save_byteorder_to_dict(imageio);
00075 
00076                         nx = attr_dict["nx"];
00077                         ny = attr_dict["ny"];
00078                         nz = attr_dict["nz"];
00079 
00080 //                      if(attr_dict.has_key("ctf")) {
00081 //                              flags |= EMDATA_HASCTFF;
00082 //                      }
00083 //                      else {
00084 //                              flags &= ~EMDATA_HASCTFF;
00085 //                      }
00086 
00087                         if (!nodata) {
00088 
00089                                 if (region) {
00090                                         nx = (int)region->get_width();
00091                                         if (nx <= 0) nx = 1;
00092                                         ny = (int)region->get_height();
00093                                         if (ny <= 0) ny = 1;
00094                                         nz = (int)region->get_depth();
00095                                         if (nz <= 0) nz = 1;
00096                                         set_size(nx,ny,nz);
00097                                         to_zero(); // This could be avoided in favor of setting only the regions that were not read to to zero... but tedious
00098                                 } // else the dimensions of the file being read match those of this
00099                                 else {
00100                                         set_size(nx, ny, nz);
00101                                 }
00102 
00103                                 // If GPU features are enabled there is  danger that rdata will
00104                                 // not be allocated, but set_size takes care of this, so this
00105                                 // should be safe.
00106                                 int err = imageio->read_data(get_data(), img_index, region, is_3d);
00107                                 if (err) {
00108                                         throw ImageReadException(filename, "imageio read data failed");
00109                                 }
00110                                 else {
00111                                         update();
00112                                 }
00113                         }
00114                 }
00115         }
00116 
00117 #ifndef IMAGEIO_CACHE
00118         if( imageio )
00119         {
00120                 delete imageio;
00121                 imageio = 0;
00122         }
00123 #endif
00124         EXITFUNC;
00125 }

vector< EMData * > EMData::read_images ( const string &  filename,
vector< int >  img_indices = vector< int >(),
bool  header_only = false 
) [static]

Read a set of images from file specified by 'filename'.

Which images are read is set by 'img_indices'.

Parameters:
filename The image file name.
img_indices Which images are read. If it is empty, all images are read. If it is not empty, only those in this array are read.
header_only If true, only read image header. If false, read both data and header.
Returns:
The set of images read from filename.

Definition at line 321 of file emdata_io.cpp.

References EMData(), ENTERFUNC, EXITFUNC, EMAN::EMUtil::get_image_count(), ImageReadException, OutofRangeException, and v.

00323 {
00324         ENTERFUNC;
00325 
00326         int total_img = EMUtil::get_image_count(filename);
00327         size_t num_img = img_indices.size();
00328 
00329         for (size_t i = 0; i < num_img; i++) {
00330                 if (img_indices[i] < 0 && img_indices[i] >= total_img) {
00331                         throw OutofRangeException(0, total_img, img_indices[i], "image index");
00332                 }
00333         }
00334 
00335         size_t n = (num_img == 0 ? total_img : num_img);
00336 
00337         vector<EMData* > v;
00338         for (size_t j = 0; j < n; j++) {
00339                 EMData *d = new EMData();
00340                 size_t k = (num_img == 0 ? j : img_indices[j]);
00341                 try {
00342                         d->read_image(filename, (int)k, header_only);
00343                 }
00344                 catch(E2Exception &e) {
00345                         if( d )
00346                         {
00347                                 delete d;
00348                                 d = 0;
00349                         }
00350                         throw(e);
00351                 }
00352                 if ( d != 0 )
00353                 {
00354                         v.push_back(d);
00355                 }
00356                 else
00357                         throw ImageReadException(filename, "imageio read data failed");
00358         }
00359 
00360         EXITFUNC;
00361         return v;
00362 }

vector< EMData * > EMData::read_images_ext ( const string &  filename,
int  img_index_start,
int  img_index_end,
bool  header_only = false,
const string &  ext = "" 
) [static]

Read a set of images from file specified by 'filename'.

If the given 'ext' is not empty, replace 'filename's extension it. Images with index from img_index_start to img_index_end are read.

Parameters:
filename The image file name.
img_index_start Starting image index.
img_index_end Ending image index.
header_only If true, only read image header. If false, read both data and header.
ext The new image filename extension.
Returns:
The set of images read from filename.

Definition at line 365 of file emdata_io.cpp.

References EMData(), ENTERFUNC, EXITFUNC, EMAN::EMUtil::get_image_count(), InvalidValueException, OutofRangeException, and v.

00368 {
00369         ENTERFUNC;
00370 
00371         if (img_index_end < img_index_start) {
00372                 throw InvalidValueException(img_index_end, "image index end < image index start");
00373         }
00374         string new_filename = filename;
00375         new_filename = new_filename.insert(new_filename.rfind("."), ext);
00376         int num_img = EMUtil::get_image_count(new_filename);
00377 
00378         if (img_index_start < 0 || img_index_start >= num_img) {
00379                 throw OutofRangeException(0, num_img-1, img_index_start, "image index start");
00380         }
00381 
00382         if (img_index_end >= num_img) {
00383                 img_index_end = num_img - 1;
00384         }
00385 
00386         vector < EMData * >v;
00387 
00388         for (int i = img_index_start; i < img_index_end; i++) {
00389                 EMData *d = new EMData();
00390                 try {
00391                         d->read_image(new_filename, i, header_only);
00392                 }
00393                 catch(E2Exception &e) {
00394                         if( d )
00395                         {
00396                                 delete d;
00397                                 d = 0;
00398                         }
00399                         throw(e);
00400                 }
00401                 v.push_back(d);
00402         }
00403         EXITFUNC;
00404         return v;
00405 }

EMData * 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.

Definition at line 1040 of file emdata_core.cpp.

References copy(), data, EMData(), ENTERFUNC, EXITFUNC, get_data(), get_xsize(), get_ysize(), get_zsize(), InvalidCallException, is_real(), is_ri(), nx, ny, nz, set_complex(), set_complex_x(), set_size(), and update().

Referenced by real2FH().

01041 {
01042         ENTERFUNC;
01043 
01044         EMData * e = new EMData();
01045 
01046         if( is_real() ) // a real image, return a copy of itself
01047         {
01048                 e = this->copy();
01049         }
01050         else //for a complex image
01051         {
01052                 if( !is_ri() )
01053                 {
01054                         delete e;
01055                         throw InvalidCallException("This image is in amplitude/phase format, this function call require a complex image in real/imaginary format.");
01056                 }
01057                 int nx = get_xsize();
01058                 int ny = get_ysize();
01059                 int nz = get_zsize();
01060                 e->set_size(nx/2, ny, nz);
01061                 float * edata = e->get_data();
01062                 float * data = get_data();
01063                 size_t idx1, idx2;
01064                 for( int i=0; i<nx; ++i )
01065                 {
01066                         for( int j=0; j<ny; ++j )
01067                         {
01068                                 for( int k=0; k<nz; ++k )
01069                                 {
01070                                         if( i%2 == 0 )
01071                                         {
01072                                                 //complex data in format [real, complex, real, complex...]
01073                                                 idx1 = i/2+j*(nx/2)+k*(nx/2)*ny;
01074                                                 idx2 = i+j*nx+k*nx*ny;
01075                                                 edata[idx1] = data[idx2];
01076                                         }
01077                                 }
01078                         }
01079                 }
01080         }
01081 
01082         e->set_complex(false);
01083         if(e->get_ysize()==1 && e->get_zsize()==1) {
01084                 e->set_complex_x(false);
01085         }
01086         e->update();
01087         return e;
01088 
01089         EXITFUNC;
01090 }

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:
img give an artificial imaginary part
Returns:
a complex image which is generated from a real image
Exceptions:
InvalidCallException this function can not be called by complex image

Definition at line 1297 of file emdata_core.cpp.

References EMData(), ENTERFUNC, EXITFUNC, get_xsize(), get_ysize(), get_zsize(), InvalidCallException, is_complex(), nx, ny, nz, set_complex(), set_complex_x(), set_ri(), set_size(), and update().

01298 {
01299         ENTERFUNC;
01300 
01301         if( is_complex() ) {
01302                 throw InvalidCallException("This function call only apply to real image");
01303         }
01304 
01305         EMData * e = new EMData();
01306         int nx = get_xsize();
01307         int ny = get_ysize();
01308         int nz = get_zsize();
01309         e->set_size(nx*2, ny, nz);
01310 
01311         for( int k=0; k<nz; ++k ) {
01312                 for( int j=0; j<ny; ++j ) {
01313                         for( int i=0; i<nx; ++i ) {
01314                                 (*e)(i*2,j,k) = (*this)(i,j,k);
01315                                 (*e)(i*2+1,j,k) = img;
01316                         }
01317                 }
01318         }
01319 
01320         e->set_complex(true);
01321         if(e->get_ysize()==1 && e->get_zsize()==1) {
01322                 e->set_complex_x(true);
01323         }
01324         e->set_ri(true);
01325         e->update();
01326         return e;
01327 
01328         EXITFUNC;
01329 }

EMData * EMData::real2FH ( float  OverSamplekB  ) 

returns the fourier harmonic transform (FH) image of the current image (in real space).

The current image is not changed. The result is in real/imaginary format. The FH switch is set on.

Parameters:
OverSamplekB is a parameter controlling the fineness of the Fourier sampling
Returns:
the Fourier Harmonic image

Definition at line 54 of file emdata_sparx.cpp.

References copy(), get_xsize(), get_ysize(), get_zsize(), imag(), ImageFormatException, is_complex(), LOGERR, nx, ny, nz, Radialize(), real(), set_complex(), set_complex_x(), set_fftodd(), set_FH(), set_ri(), set_size(), spline_mat(), to_zero(), and update().

00055 {
00056         int nx        = get_xsize();
00057         int ny        = get_ysize();
00058         int nz        = get_zsize();
00059         int Center  = (int) floor( (nx+1.0)/2.0 +.01);
00060 #ifdef DEBUG
00061         printf("nx=%d, ny=%d, nz=%d Center=%d\n", nx,ny,nz, Center);
00062 #endif  //DEBUG
00063         float ScalFactor=4.1f;
00064         gsl_set_error_handler_off();
00065 
00066         if ( (nz==1) && (nx==ny) && (!is_complex())  && (Center*2)==(nx+1)){
00067 #ifdef DEBUG
00068                 printf("entered if \n");fflush(stdout);
00069 #endif  //DEBUG
00070 //              MArray2D ImBW = this ->get_2dview();
00071                 EMData*  ImBW = this ;
00072                 int Size=nx;
00073                 int iMax = (int) floor( (Size-1.0)/2 +.01);
00074                 int CountMax = (iMax+2)*(iMax+1)/2;
00075                 int *PermMatTr  = new int[CountMax];
00076                 float *RValsSorted  = new float[CountMax];
00077                 float *weightofkValsSorted = new float[CountMax];
00078                 int *SizeReturned = new int[1];
00079                 Util::Radialize(PermMatTr, RValsSorted,weightofkValsSorted,Size, SizeReturned);
00080                 int RIntMax= SizeReturned[0];
00081 
00082                 int mMax = (int) floor( ScalFactor*RValsSorted[RIntMax-1]+10.0);
00083 
00084                 int kIntMax=2+ (int) floor( RValsSorted[RIntMax-1]*OverSamplekB);
00085                 float *kVec2Use= new float[kIntMax];
00086                 for (int kk=0; kk<kIntMax; kk++){
00087                         kVec2Use[kk]= ((float) kk)/OverSamplekB;}
00088 
00089                 float *krVec= new float[kIntMax*RIntMax];
00090                 int Count=0;
00091                 for (int jk=0; jk<kIntMax; jk++ ){
00092                         for (int jR=0; jR<RIntMax; jR++ ){
00093                                 krVec[Count]=2.0f*M_PI*RValsSorted[jR]
00094                                         *kVec2Use[jk]/( (float) Size);
00095                                 Count++;
00096 //                              printf("krVec[%d]=%f \n",Count,krVec[Count-1]);fflush(stdout);
00097                 }} // end building up krVec
00098                 float krVecMin= kVec2Use[1]*RValsSorted[1];
00099                 float krVecMax = krVec[kIntMax*RIntMax-1]+krVecMin;
00100                 int Number2Use = (int) floor(OverSamplekB*krVecMax+1.0);
00101                 float *krVec2Use      = new float[Number2Use+1];
00102                 float *sampledBesselJ = new float[Number2Use+1];
00103 #ifdef DEBUG
00104                 printf("Size=%d, iMax=%d, SizeReturned=%d, RIntMax=%d, \n"
00105                       "mMax=%d, kIntMax=%d, krVecMin=%f, krVecMax=%f,  Number2Use=%d  \n\n",
00106                         Size, iMax, SizeReturned[0], RIntMax, mMax, kIntMax,
00107                                krVecMin,krVecMax,Number2Use);fflush(stdout);
00108 #endif  //DEBUG
00109                 for (int jkr=0; jkr<= Number2Use; jkr++) {
00110                         krVec2Use[jkr] =((float)jkr)*krVecMax/
00111                                     ((float)Number2Use);
00112 //                      printf("krVec2Use[%d]=%f \n",jkr+1,krVec2Use[jkr]);fflush(stdout);
00113                 }
00114 
00115 
00116                 EMData* rhoOfkmB = copy(); // glibc detected ** malloc(); memory corruption
00117 //              printf("finished O \n");fflush(stdout);
00118                 rhoOfkmB->set_size(2*(mMax+1),kIntMax);
00119                 rhoOfkmB->to_zero();
00120 //              MArray2D rhoOfkmB = FH->get_2dview();
00121 
00122                 int CenterM= Center-1; // to convert from Matlab to C++
00123                 std::complex <float> *rhoOfRandmTemp = new std::complex <float>[RIntMax];
00124                 std::complex <float> rhoTemp;
00125 
00126                 int PCount=0;
00127 
00128                 for (int m=0; m <=mMax; m++){
00129                 //    if m==mMax, tic, end
00130                         std::complex <float> tempF(0.0f,-1.0f);
00131                         std::complex <float> overallFactor = pow(tempF,m);  //(-i)^m ;  % I dropped off the 2 pi
00132                         std::complex <float> mI(0.0f,static_cast<float>(m));
00133                         for (int ii=0; ii< RIntMax; ii++){ rhoOfRandmTemp[ii]=0;}
00134                         for (int jx=0; jx <Center ; jx++) {
00135                                 for (int jy=0; jy <=jx; jy++){
00136                                         float fjx=float(jx);
00137                                         float fjy= float(jy);
00138                                         Count = (jx*jx+jx)/2 +1 +jy;
00139                                         PCount = PermMatTr[Count-1];
00140 //                                      printf("PCount=%d, Count=%d \n", PCount, Count);
00141                                         rhoTemp =  std::complex <float> ((*ImBW)(CenterM+jx,CenterM+jy)) *exp(mI* std::complex <float> (atan2(+fjy,+fjx)))
00142                                          +   std::complex <float> ((*ImBW)(CenterM+jx,CenterM-jy)) * exp(mI*std::complex <float>(atan2(-fjy,+fjx)))
00143                                          +   std::complex <float> ((*ImBW)(CenterM-jx,CenterM+jy)) * exp(mI*std::complex <float>(atan2(+fjy,-fjx)))
00144                                          +   std::complex <float> ((*ImBW)(CenterM-jx,CenterM-jy)) * exp(mI*std::complex <float>(atan2(-fjy,-fjx)))
00145                                          +   std::complex <float> ((*ImBW)(CenterM+jy,CenterM+jx)) * exp(mI*std::complex <float>(atan2(+fjx,+fjy)))
00146                                          +   std::complex <float> ((*ImBW)(CenterM+jy,CenterM-jx)) * exp(mI*std::complex <float>(atan2(-fjx,+fjy)))
00147                                          +   std::complex <float> ((*ImBW)(CenterM-jy,CenterM+jx)) * exp(mI*std::complex <float>(atan2(+fjx,-fjy)))
00148                                          +   std::complex <float> ((*ImBW)(CenterM-jy,CenterM-jx)) * exp(mI*std::complex <float>(atan2(-fjx,-fjy)));
00149                                         if (((jx+jy)==0)&&(m>0) ){
00150                                                 rhoTemp=0;}
00151 //                      printf("m=%d, jx=%d, jy=%d, rhoTemp= %f+ %f i\n", m,jx,jy,(rhoTemp.real()), (rhoTemp.imag()) );fflush(stdout);
00152 //                      {" %f,%f %f,%f %f,%f %f,%f \n",
00153 //                             ImBW[CenterM+jx][CenterM+jy] ,ImBW[CenterM+jx][CenterM-jy]  , ImBW[CenterM-jx][CenterM+jy] ,ImBW[CenterM-jx][CenterM-jy],
00154 //                             ImBW[CenterM+jy][CenterM+jx] ,ImBW[CenterM+jy][CenterM-jx]  , ImBW[CenterM-jy][CenterM+jx] ,ImBW[CenterM-jy][CenterM-jx]);
00155                                         rhoOfRandmTemp[PCount-1] +=
00156                                             rhoTemp/((float)pow(2.,(int)( (jx==0)  +(jy==0)+ (jy==jx))));
00157 
00158                         }} // end walk through lattice
00159 //                      printf("\n m=%d rhoOfRandmTemp" ,m  );fflush(stdout);
00160 //                      for (int ss=0; ss< RIntMax; ss++){
00161 //                              printf(" %3.1f+ %3.1fi \t",(rhoOfRandmTemp[ss].real()), (rhoOfRandmTemp[ss].imag())   );fflush(stdout);}
00162 
00163 // calculate product
00164 
00165                         float tempp;
00166 //                      printf("\n m=%d sampledBesselJ" ,m  );fflush(stdout);
00167                         for (int st=0; st<= Number2Use; st++){
00168                                 tempp=krVec2Use[st];
00169                                 sampledBesselJ[st] = static_cast<float>(gsl_sf_bessel_Jn(m,tempp));
00170 //                              printf(" %3.2f  \t",sampledBesselJ[st]   );fflush(stdout);
00171                         } // good so far
00172 
00173 //                      sampledBesselJ  = BesselJ(m,krVec2Use);
00174                         float *tempMB = new float [kIntMax*RIntMax];
00175                         Util::spline_mat(krVec2Use, sampledBesselJ, Number2Use+1,krVec,tempMB,kIntMax*RIntMax );
00176 //                      printf("\n tempMB m=%d y2" ,m  );fflush(stdout);
00177                         std::complex <float> *rowV = new std::complex <float> [kIntMax];
00178 
00179 //                      for (int st=0; st< kIntMax*RIntMax; st++){printf(" %3.2f  \t",tempMB[st]   );fflush(stdout);} // good so far
00180 
00181 //   tempMB,krVec is in blocks of RIntMax
00182 //                      printf("\n rowV m=%d \t" ,m  );fflush(stdout);
00183                         for (int st=0; st < kIntMax; st++) {
00184                                         rowV[st]=0;
00185                                         for (int sv=0; sv < RIntMax; sv++) {
00186                                                 rowV[st]+=  rhoOfRandmTemp[sv] *tempMB[sv+st*RIntMax];
00187                                         }
00188                                          rowV[st] *= overallFactor;
00189 //                                      printf(" %1.3f +%1.3fi \t" , rowV[st].real(), rowV[st].imag() );fflush(stdout);
00190                         }
00191                         for (int st=0; st < kIntMax; st++) {
00192                                 (*rhoOfkmB)(2*m  ,st) = rowV[st].real();
00193                                 (*rhoOfkmB)(2*m+1,st) = rowV[st].imag();
00194                         }
00195 //                      rowV = overallFactor*rhoOfRandmTemp*tempMBB;
00196 //                      rhoOfkmB(m+1,1:kIntMax) = rowV ;
00197 
00198 //                      if m==mMax, toc, end
00199 
00200 // %'final interpolation'
00201 // %     rhoOfkm(m+1,:) = spline(kVec2Use,rowV,RValsSorted); ;
00202 
00203 
00204                 } // ends m loop
00205 
00206                 update();
00207                 rhoOfkmB-> update();
00208                 rhoOfkmB->set_complex(true);
00209                 if(rhoOfkmB->get_ysize()==1 && rhoOfkmB->get_zsize()==1) {
00210                         rhoOfkmB->set_complex_x(true);
00211                 }
00212         rhoOfkmB->set_ri(true);
00213         rhoOfkmB->set_FH(true);
00214         rhoOfkmB->set_fftodd(true);
00215                 return rhoOfkmB;
00216         } else {
00217                 LOGERR("2D real square odd image expected.");
00218                 throw ImageFormatException("2D real square odd image expected.");
00219         }
00220 }

void EMData::render_amp24 ( int  x,
int  y,
int  xsize,
int  ysize,
int  bpl,
float  scale,
int  min_gray,
int  max_gray,
float  min_render,
float  max_render,
void *  ref,
void   cmap(void *, int coord, unsigned char *tri) 
)

Render the image into a 24-bit image.

2D image only.

Parameters:
x 
y 
xsize 
ysize 
bpl 
scale 
min_gray 
max_gray 
min_render 
max_render 
ref 
cmap 
Exceptions:
ImageDimensionException If the image is not 2D.

Definition at line 624 of file emdata_transform.cpp.

References br, data, ENTERFUNC, EXITFUNC, get_data(), get_ndim(), ImageDimensionException, is_complex(), nx, ny, ri2ap(), and t.

00628 {
00629         ENTERFUNC;
00630 
00631         if (get_ndim() != 2) {
00632                 throw ImageDimensionException("2D only");
00633         }
00634 
00635         if (is_complex()) {
00636                 ri2ap();
00637         }
00638 
00639         if (render_max <= render_min) {
00640                 render_max = render_min + 0.01f;
00641         }
00642 
00643         std::string ret=std::string();
00644         ret.resize(iysize*bpl);
00645         unsigned char *data=(unsigned char *)ret.data();
00646 
00647         float rm = render_min;
00648         float inv_scale = 1.0f / scale;
00649         int ysize = iysize;
00650         int xsize = ixsize;
00651         const int scale_n = 100000;
00652 
00653         int ymin = 0;
00654         if ( iysize * inv_scale > ny) {
00655                 ymin = (int) (iysize - ny / inv_scale);
00656         }
00657         float gs = (maxgray - mingray) / (render_max - render_min);
00658         if (render_max < render_min) {
00659                 gs = 0;
00660                 rm = FLT_MAX;
00661         }
00662         int dsx = -1;
00663         int dsy = 0;
00664         if (inv_scale == floor(inv_scale)) {
00665                 dsx = (int) inv_scale;
00666                 dsy = (int) (inv_scale * nx);
00667         }
00668         int addi = 0;
00669         int addr = 0;
00670 
00671         if (dsx == -1) {
00672                 addi = (int) floor(inv_scale);
00673                 addr = (int) (scale_n * (inv_scale - floor(inv_scale)));
00674         }
00675 
00676         int remx = 0;
00677         int remy = 0;
00678         int xmin = 0;
00679         if (x0 < 0) {
00680                 xmin = (int) (-x0 / inv_scale);
00681                 xsize -= (int) floor(x0 / inv_scale);
00682                 x0 = 0;
00683         }
00684 
00685         if ((xsize - xmin) * inv_scale > (nx - x0)) {
00686                 xsize = (int) ((nx - x0) / inv_scale + xmin);
00687         }
00688         int ymax = ysize - 1;
00689         if (y0 < 0) {
00690                 ymax = (int) (ysize + y0 / inv_scale - 1);
00691                 ymin += (int) floor(y0 / inv_scale);
00692                 y0 = 0;
00693         }
00694 
00695 
00696         if (xmin < 0) {
00697                 xmin = 0;
00698         }
00699 
00700         if (ymin < 0) {
00701                 ymin = 0;
00702         }
00703         if (xsize > ixsize) {
00704                 xsize = ixsize;
00705         }
00706         if (ymax > iysize) {
00707                 ymax = iysize;
00708         }
00709 
00710         int lmax = nx * ny - 1;
00711         unsigned char tri[3];
00712         float* image_data = get_data();
00713         if (is_complex()) {
00714                 if (dsx != -1) {
00715                         int l = y0 * nx;
00716                         for (int j = ymax; j >= ymin; j--) {
00717                                 int ll = x0;
00718                                 for (int i = xmin; i < xsize; i++, ll += dsx) {
00719                                         if (l + ll > lmax || ll >= nx - 2) {
00720                                                 break;
00721                                         }
00722                                         int kk = 0;
00723                                         if (ll >= nx / 2) {
00724                                                 if (l >= (ny - inv_scale) * nx) {
00725                                                         kk = 2 * (ll - nx / 2) + 2;
00726                                                 }
00727                                                 else {
00728                                                         kk = 2 * (ll - nx / 2) + l + 2 + nx;
00729                                                 }
00730                                         }
00731                                         else {
00732                                                 kk = nx * ny - (l + 2 * ll) - 2;
00733                                         }
00734                                         int k = 0;
00735                                         float t = image_data[kk];
00736                                         if (t <= rm) {
00737                                                 k = mingray;
00738                                         }
00739                                         else if (t >= render_max) {
00740                                                 k = maxgray;
00741                                         }
00742                                         else {
00743                                                 k = (int) (gs * (t - render_min));
00744                                                 k += mingray;
00745                                         }
00746                                         tri[0] = static_cast < unsigned char >(k);
00747                                         cmap(ref, kk, tri);
00748                                         data[i * 3 + j * bpl] = tri[0];
00749                                         data[i * 3 + 1 + j * bpl] = tri[1];
00750                                         data[i * 3 + 2 + j * bpl] = tri[2];
00751                                 }
00752                                 l += dsy;
00753                         }
00754                 }
00755                 else {
00756                         remy = 10;
00757                         for (int j = ymax, l = y0 * nx; j >= ymin; j--) {
00758                                 int br = l;
00759                                 remx = 10;
00760                                 for (int i = xmin, ll = x0; i < xsize - 1; i++) {
00761                                         if (l + ll > lmax || ll >= nx - 2) {
00762                                                 break;
00763                                         }
00764                                         int kk = 0;
00765                                         if (ll >= nx / 2) {
00766                                                 if (l >= (ny * nx - nx)) {
00767                                                         kk = 2 * (ll - nx / 2) + 2;
00768                                                 }
00769                                                 else {
00770                                                         kk = 2 * (ll - nx / 2) + l + 2 + nx;
00771                                                 }
00772                                         }
00773                                         else {
00774                                                 kk = nx * ny - (l + 2 * ll) - 2;
00775                                         }
00776                                         int k = 0;
00777                                         float t = image_data[kk];
00778                                         if (t <= rm) {
00779                                                 k = mingray;
00780                                         }
00781                                         else if (t >= render_max) {
00782                                                 k = maxgray;
00783                                         }
00784                                         else {
00785                                                 k = (int) (gs * (t - render_min));
00786                                                 k += mingray;
00787                                         }
00788                                         tri[0] = static_cast < unsigned char >(k);
00789                                         cmap(ref, kk, tri);
00790                                         data[i * 3 + j * bpl] = tri[0];
00791                                         data[i * 3 + 1 + j * bpl] = tri[1];
00792                                         data[i * 3 + 2 + j * bpl] = tri[2];
00793                                         ll += addi;
00794                                         remx += addr;
00795                                         if (remx > scale_n) {
00796                                                 remx -= scale_n;
00797                                                 ll++;
00798                                         }
00799                                 }
00800                                 l = br + addi * nx;
00801                                 remy += addr;
00802                                 if (remy > scale_n) {
00803                                         remy -= scale_n;
00804                                         l += nx;
00805                                 }
00806                         }
00807                 }
00808         }
00809         else {
00810                 if (dsx != -1) {
00811                         for (int j = ymax, l = x0 + y0 * nx; j >= ymin; j--) {
00812                                 int br = l;
00813                                 for (int i = xmin; i < xsize; i++, l += dsx) {
00814                                         if (l > lmax) {
00815                                                 break;
00816                                         }
00817                                         float t = image_data[l];
00818                                         int k = 0;
00819                                         if (t <= rm) {
00820                                                 k = mingray;
00821                                         }
00822                                         else if (t >= render_max) {
00823                                                 k = maxgray;
00824                                         }
00825                                         else {
00826                                                 k = (int) (gs * (t - render_min));
00827                                                 k += mingray;
00828                                         }
00829                                         tri[0] = static_cast < unsigned char >(k);
00830                                         cmap(ref, l, tri);
00831                                         data[i * 3 + j * bpl] = tri[0];
00832                                         data[i * 3 + 1 + j * bpl] = tri[1];
00833                                         data[i * 3 + 2 + j * bpl] = tri[2];
00834                                 }
00835                                 l = br + dsy;
00836                         }
00837                 }
00838                 else {
00839                         remy = 10;
00840                         for (int j = ymax, l = x0 + y0 * nx; j >= ymin; j--) {
00841                                 int br = l;
00842                                 remx = 10;
00843                                 for (int i = xmin; i < xsize; i++) {
00844                                         if (l > lmax) {
00845                                                 break;
00846                                         }
00847                                         float t = image_data[l];
00848                                         int k = 0;
00849                                         if (t <= rm) {
00850                                                 k = mingray;
00851                                         }
00852                                         else if (t >= render_max) {
00853                                                 k = maxgray;
00854                                         }
00855                                         else {
00856                                                 k = (int) (gs * (t - render_min));
00857                                                 k += mingray;
00858                                         }
00859                                         tri[0] = static_cast < unsigned char >(k);
00860                                         cmap(ref, l, tri);
00861                                         data[i * 3 + j * bpl] = tri[0];
00862                                         data[i * 3 + 1 + j * bpl] = tri[1];
00863                                         data[i * 3 + 2 + j * bpl] = tri[2];
00864                                         l += addi;
00865                                         remx += addr;
00866                                         if (remx > scale_n) {
00867                                                 remx -= scale_n;
00868                                                 l++;
00869                                         }
00870                                 }
00871                                 l = br + addi * nx;
00872                                 remy += addr;
00873                                 if (remy > scale_n) {
00874                                         remy -= scale_n;
00875                                         l += nx;
00876                                 }
00877                         }
00878                 }
00879         }
00880 
00881         EXITFUNC;
00882 }

std::string EMAN::EMData::render_amp8 ( int  x,
int  y,
int  xsize,
int  ysize,
int  bpl,
float  scale,
int  min_gray,
int  max_gray,
float  min_render,
float  max_render,
float  gamma,
int  flags 
)

Render the image into an 8-bit image.

2D images only. flags provide a way to do unusual things with this function, such as calculating a histogram of the rendered area.

Parameters:
x origin of the area to render
y 
xsize size of the area to render in output pixels
ysize 
bpl bytes per line, if asrgb remember *3
scale scale factor for rendering
min_gray minimum gray value to render (0-255)
max_gray maximum gray value to render (0-255)
min_render float image density corresponding to min_gray
max_render float image density corresponding to max_gray
gamma 
flags 1-duplicate each output pixel 3x for RGB rendering,2-add a 256 int greyscale histogram to the end of the image array,4-invert y axis,8-render 32 bit 0xffRRGGBB
Exceptions:
ImageDimensionException If the image is not 2D.

std::string EMData::render_ap24 ( int  x,
int  y,
int  xsize,
int  ysize,
int  bpl,
float  scale,
int  min_gray,
int  max_gray,
float  min_render,
float  max_render,
float  gamma,
int  flags 
)

Render the image into an 8-bit image.

2D images only. flags provide a way to do unusual things with this function, such as calculating a histogram of the rendered area.

Parameters:
x origin of the area to render
y 
xsize size of the area to render in output pixels
ysize 
bpl bytes per line, if asrgb remember *3
scale scale factor for rendering
min_gray minimum gray value to render (0-255)
max_gray maximum gray value to render (0-255)
min_render float image density corresponding to min_gray
max_render float image density corresponding to max_gray
gamma 
flags 1-duplicate each output pixel 3x for RGB rendering,2-add a 256 int greyscale histogram to the end of the image array,4-invert y axis,8-render 32 bit 0xffRRGGBB
Exceptions:
ImageDimensionException If the image is not 2D.

Definition at line 352 of file emdata_transform.cpp.

References br, data, ENTERFUNC, EXITFUNC, get_data(), get_ndim(), ImageDimensionException, is_complex(), nx, ny, ri2ap(), t, x, and y.

00355 {
00356         ENTERFUNC;
00357 
00358         int asrgb;
00359         int hist=(flags&2)/2;
00360         int invy=(flags&4)?1:0;
00361 
00362         if (!is_complex()) throw ImageDimensionException("complex only");
00363 
00364         if (get_ndim() != 2) {
00365                 throw ImageDimensionException("2D only");
00366         }
00367 
00368         if (is_complex()) ri2ap();
00369 
00370         if (render_max <= render_min) {
00371                 render_max = render_min + 0.01f;
00372         }
00373 
00374         if (gamma<=0) gamma=1.0;
00375 
00376         // Calculating a full floating point gamma for
00377         // each pixel in the image slows rendering unacceptably
00378         // however, applying a gamma-mapping to an 8 bit colorspace
00379         // has unaccepable accuracy. So, we oversample the 8 bit colorspace
00380         // as a 12 bit colorspace and apply the gamma mapping to that
00381         // This should produce good accuracy for gamma values
00382         // larger than 0.5 (and a high upper limit)
00383         static int smg0=0,smg1=0;       // while this destroys threadsafety in the rendering process
00384         static float sgam=0;            // it is necessary for speed when rendering large numbers of small images
00385         static unsigned char gammamap[4096];
00386         if (gamma!=1.0 && (smg0!=mingray || smg1!=maxgray || sgam!=gamma)) {
00387                 for (int i=0; i<4096; i++) {
00388                         if (mingray<maxgray) gammamap[i]=(unsigned char)(mingray+(maxgray-mingray+0.999)*pow(((float)i/4096.0f),gamma));
00389                         else gammamap[4095-i]=(unsigned char)(mingray+(maxgray-mingray+0.999)*pow(((float)i/4096.0f),gamma));
00390                 }
00391         }
00392         smg0=mingray;   // so we don't recompute the map unless something changes
00393         smg1=maxgray;
00394         sgam=gamma;
00395 
00396         if (flags&8) asrgb=4;
00397         else if (flags&1) asrgb=3;
00398         else throw ImageDimensionException("must set flag 1 or 8");
00399 
00400         std::string ret=std::string();
00401 //      ret.resize(iysize*bpl);
00402         ret.assign(iysize*bpl+hist*1024,char(mingray));
00403         unsigned char *data=(unsigned char *)ret.data();
00404         unsigned int *histd=(unsigned int *)(data+iysize*bpl);
00405         if (hist) {
00406                 for (int i=0; i<256; i++) histd[i]=0;
00407         }
00408 
00409         float rm = render_min;
00410         float inv_scale = 1.0f / scale;
00411         int ysize = iysize;
00412         int xsize = ixsize;
00413 
00414         int ymin = 0;
00415         if (iysize * inv_scale > ny) {
00416                 ymin = (int) (iysize - ny / inv_scale);
00417         }
00418 
00419         float gs = (maxgray - mingray) / (render_max - render_min);
00420         float gs2 = 4095.999f / (render_max - render_min);
00421 //      float gs2 = 1.0 / (render_max - render_min);
00422         if (render_max < render_min) {
00423                 gs = 0;
00424                 rm = FLT_MAX;
00425         }
00426 
00427         int dsx = -1;
00428         int dsy = 0;
00429         int remx = 0;
00430         int remy = 0;
00431         const int scale_n = 100000;
00432 
00433         int addi = 0;
00434         int addr = 0;
00435         if (inv_scale == floor(inv_scale)) {
00436                 dsx = (int) inv_scale;
00437                 dsy = (int) (inv_scale * nx);
00438         }
00439         else {
00440                 addi = (int) floor(inv_scale);
00441                 addr = (int) (scale_n * (inv_scale - floor(inv_scale)));
00442         }
00443 
00444         int xmin = 0;
00445         if (x0 < 0) {
00446                 xmin = (int) (-x0 / inv_scale);
00447                 xsize -= (int) floor(x0 / inv_scale);
00448                 x0 = 0;
00449         }
00450 
00451         if ((xsize - xmin) * inv_scale > (nx - x0)) {
00452                 xsize = (int) ((nx - x0) / inv_scale + xmin);
00453         }
00454         int ymax = ysize - 1;
00455         if (y0 < 0) {
00456                 ymax = (int) (ysize + y0 / inv_scale - 1);
00457                 ymin += (int) floor(y0 / inv_scale);
00458                 y0 = 0;
00459         }
00460 
00461         if (xmin < 0) xmin = 0;
00462         if (ymin < 0) ymin = 0;
00463         if (xsize > ixsize) xsize = ixsize;
00464         if (ymax > iysize) ymax = iysize;
00465 
00466         int lmax = nx * ny - 1;
00467 
00468         int mid=nx*ny/2;
00469         float* image_data = get_data();
00470         if (dsx != -1) {
00471                 int l = y0 * nx;
00472                 for (int j = ymax; j >= ymin; j--) {
00473                         int ll = x0;
00474                         for (int i = xmin; i < xsize; i++) {
00475                                 if (l + ll > lmax || ll >= nx - 2) break;
00476 
00477                                 int k = 0;
00478                                 unsigned char p;
00479                                 int ph;
00480                                 if (ll >= nx / 2) {
00481                                         if (l >= (ny - inv_scale) * nx) k = 2 * (ll - nx / 2) + 2;
00482                                         else k = 2 * (ll - nx / 2) + l + 2 + nx;
00483                                         ph = (int)(image_data[k+1]*768/(2.0*M_PI))+384; // complex phase as integer 0-767
00484                                 }
00485                                 else {
00486                                         k = nx * ny - (l + 2 * ll) - 2;
00487                                         ph = (int)(-image_data[k+1]*768/(2.0*M_PI))+384;        // complex phase as integer 0-767
00488                                 }
00489                                 if (k>=mid) k-=mid;             // These 2 lines handle the Fourier origin being in the corner, not the middle
00490                                 else k+=mid;
00491                                 float t = image_data[k];
00492                                 if (t <= rm)  p = mingray;
00493                                 else if (t >= render_max) p = maxgray;
00494                                 else if (gamma!=1.0) {
00495                                         k=(int)(gs2 * (t-render_min));          // map float value to 0-4096 range
00496                                         p = gammamap[k];                                        // apply gamma using precomputed gamma map
00497                                 }
00498                                 else {
00499                                         p = (unsigned char) (gs * (t - render_min));
00500                                         p += mingray;
00501                                 }
00502                                 if (ph<256) {
00503                                         data[i * asrgb + j * bpl] = p*(255-ph)/256;
00504                                         data[i * asrgb + j * bpl+1] = p*ph/256;
00505                                         data[i * asrgb + j * bpl+2] = 0;
00506                                 }
00507                                 else if (ph<512) {
00508                                         data[i * asrgb + j * bpl+1] = p*(511-ph)/256;
00509                                         data[i * asrgb + j * bpl+2] = p*(ph-256)/256;
00510                                         data[i * asrgb + j * bpl] = 0;
00511                                 }
00512                                 else {
00513                                         data[i * asrgb + j * bpl+2] = p*(767-ph)/256;
00514                                         data[i * asrgb + j * bpl] = p*(ph-512)/256;
00515                                         data[i * asrgb + j * bpl+1] = 0;
00516                                 }
00517                                 if (hist) histd[p]++;
00518                                 ll += dsx;
00519                         }
00520                         l += dsy;
00521                 }
00522         }
00523         else {
00524                 remy = 10;
00525                 int l = y0 * nx;
00526                 for (int j = ymax; j >= ymin; j--) {
00527                         int br = l;
00528                         remx = 10;
00529                         int ll = x0;
00530                         for (int i = xmin; i < xsize - 1; i++) {
00531                                 if (l + ll > lmax || ll >= nx - 2) {
00532                                         break;
00533                                 }
00534                                 int k = 0;
00535                                 unsigned char p;
00536                                 int ph;
00537                                 if (ll >= nx / 2) {
00538                                         if (l >= (ny * nx - nx)) k = 2 * (ll - nx / 2) + 2;
00539                                         else k = 2 * (ll - nx / 2) + l + 2 + nx;
00540                                         ph = (int)(image_data[k+1]*768/(2.0*M_PI))+384; // complex phase as integer 0-767
00541                                 }
00542                                 else {
00543                                         k = nx * ny - (l + 2 * ll) - 2;
00544                                         ph = (int)(-image_data[k+1]*768/(2.0*M_PI))+384;        // complex phase as integer 0-767
00545                                 }
00546                                 if (k>=mid) k-=mid;             // These 2 lines handle the Fourier origin being in the corner, not the middle
00547                                 else k+=mid;
00548 
00549                                 float t = image_data[k];
00550                                 if (t <= rm)
00551                                         p = mingray;
00552                                 else if (t >= render_max) {
00553                                         p = maxgray;
00554                                 }
00555                                 else if (gamma!=1.0) {
00556                                         k=(int)(gs2 * (t-render_min));          // map float value to 0-4096 range
00557                                         p = gammamap[k];                                        // apply gamma using precomputed gamma map
00558                                 }
00559                                 else {
00560                                         p = (unsigned char) (gs * (t - render_min));
00561                                         p += mingray;
00562                                 }
00563                                 if (ph<256) {
00564                                         data[i * asrgb + j * bpl] = p*(255-ph)/256;
00565                                         data[i * asrgb + j * bpl+1] = p*ph/256;
00566                                         data[i * asrgb + j * bpl+2] = 0;
00567                                 }
00568                                 else if (ph<512) {
00569                                         data[i * asrgb + j * bpl+1] = p*(511-ph)/256;
00570                                         data[i * asrgb + j * bpl+2] = p*(ph-256)/256;
00571                                         data[i * asrgb + j * bpl] = 0;
00572                                 }
00573                                 else {
00574                                         data[i * asrgb + j * bpl+2] = p*(767-ph)/256;
00575                                         data[i * asrgb + j * bpl] = p*(ph-512)/256;
00576                                         data[i * asrgb + j * bpl+1] = 0;
00577                                 }
00578                                 if (hist) histd[p]++;
00579                                 ll += addi;
00580                                 remx += addr;
00581                                 if (remx > scale_n) {
00582                                         remx -= scale_n;
00583                                         ll++;
00584                                 }
00585                         }
00586                         l = br + addi * nx;
00587                         remy += addr;
00588                         if (remy > scale_n) {
00589                                 remy -= scale_n;
00590                                 l += nx;
00591                         }
00592                 }
00593         }
00594 
00595         // this replicates r -> g,b
00596         if (asrgb==4) {
00597                 for (int j=ymin*bpl; j<=ymax*bpl; j+=bpl) {
00598                         for (int i=xmin; i<xsize*4; i+=4) {
00599                                 data[i+j+3]=255;
00600                         }
00601                 }
00602         }
00603 
00604         EXITFUNC;
00605 
00606         // ok, ok, not the most efficient place to do this, but it works
00607         if (invy) {
00608                 int x,y;
00609                 char swp;
00610                 for (y=0; y<iysize/2; y++) {
00611                         for (x=0; x<ixsize; x++) {
00612                                 swp=ret[y*bpl+x];
00613                                 ret[y*bpl+x]=ret[(iysize-y-1)*bpl+x];
00614                                 ret[(iysize-y-1)*bpl+x]=swp;
00615                         }
00616                 }
00617         }
00618 
00619     //  return PyString_FromStringAndSize((const char*) data,iysize*bpl);
00620         return ret;
00621 }

EMData * EMData::replace_amplitudes ( EMData image,
bool  RetReal = true 
)

Definition at line 5900 of file emdata_sparx.cpp.

References copy(), depad(), do_fft_inplace(), do_ift_inplace(), fint, fout, get_data(), get_xsize(), get_ysize(), get_zsize(), is_complex(), is_fftodd(), norm_pad(), nx, ny, nz, set_array_offsets(), set_attr(), set_fftodd(), set_fftpad(), set_ri(), sqrt(), and update().

05900                                                               {
05901 
05902 
05903         bool   complex_input = this->is_complex();
05904         nx  = this->get_xsize();
05905         ny  = this->get_ysize();
05906         nz  = this->get_zsize();
05907         int nox;
05908         if (complex_input) nox = (nx - 2 + this->is_fftodd()); else nox = nx;
05909 
05910         EMData* fp = NULL; // output image
05911         if(complex_input) {
05912                 // fimage must remain pristine
05913                 fp = this->copy();
05914         } else {
05915                 fp = this->norm_pad( false, 1);
05916                 fp->do_fft_inplace();
05917         }
05918         float *fout = fp->get_data();
05919         float *fint = image->get_data();
05920         for ( int iz = 0; iz < nz; iz++) {
05921                 for ( int iy = 0; iy < ny; iy++) {
05922                         for ( int ix = 0; ix < nx; ix+=2) {
05923                                 float qt = fint(ix,iy,iz)*fint(ix,iy,iz)+fint(ix+1,iy,iz)*fint(ix+1,iy,iz);
05924                                 float rt = fout(ix,iy,iz)*fout(ix,iy,iz)+fout(ix+1,iy,iz)*fout(ix+1,iy,iz);
05925                                 if(rt > 1.0e-20) {
05926                                                 fout(ix,iy,iz) *= (qt/rt);
05927                                                 fout(ix+1,iy,iz) *= (qt/rt);
05928                                 } else {
05929                                                 qt = std::sqrt(qt/2.0f);
05930                                                 fout(ix,iy,iz) = qt;
05931                                                 fout(ix+1,iy,iz) = qt;
05932                                 }
05933                         }
05934                 }
05935         }
05936 
05937         fp->set_ri(1);
05938         fp->set_fftpad(true);
05939         fp->set_attr("npad", 1);
05940         if (nx%2 == 1) fp->set_fftodd(true);
05941         else fp->set_fftodd(false);
05942         if(RetReal) {
05943                 fp->do_ift_inplace();
05944                 fp->depad();
05945         }
05946         fp->set_array_offsets(0,0,0);
05947         fp->update();
05948 
05949         return fp;
05950 }

static float EMAN::EMData::restrict1 ( float  x,
int  nx 
) [inline, static]

Definition at line 2721 of file emdata.h.

Referenced by rot_scale_conv(), rot_scale_conv7(), and rot_scale_trans().

static float EMAN::EMData::restrict2 ( float  x,
int  nx 
) [inline, static]

Definition at line 2730 of file emdata.h.

Referenced by get_pixel_conv(), rot_scale_conv(), rot_scale_conv7(), rot_scale_conv_new(), rot_scale_conv_new_background(), rot_scale_trans(), rot_scale_trans2D(), rot_scale_trans2D_background(), and rot_scale_trans_background().

EMData * EMData::rot_scale_conv ( float  ang,
float  delx,
float  dely,
Util::KaiserBessel kb,
float  scale = 1.0 
)

Rotate-Shift-Scale-Circulantly image using convolution.

If the image is a volume, then all slices are rotated/translated/scaled.

Parameters:
[in] ang Rotation angle in degrees.
[in] delx Amount to shift rotation origin along x
[in] dely Amount to shift rotation origin along y
[in] kb convolution kernel
[in] scale Scaling factor (default=1.0)
Exceptions:
ImageDimensionException can not rotate 1 D image
ImageDimensionException can not rotate 3 D image
Returns:
New rotated/shifted/scaled image

Definition at line 2360 of file emdata_sparx.cpp.

References copy_head(), get_array_offsets(), EMAN::Util::KaiserBessel::get_window_size(), EMAN::Util::KaiserBessel::i0win_tab(), ImageDimensionException, max, nx, ny, nz, q, restrict1(), restrict2(), EMAN::Util::round(), scale(), set_array_offsets(), set_size(), t, x, and y.

02360                                                                                                          {
02361         int nxn, nyn, nzn;
02362         if(scale_input == 0.0f) scale_input = 1.0f;
02363         //const float scale=0.5;
02364         float  scale = 0.5f*scale_input;
02365         float  sum, w;
02366         if (1 >= ny)
02367                 throw ImageDimensionException("Can't rotate 1D image");
02368         if (1 < nz)
02369                 throw ImageDimensionException("Volume not currently supported");
02370         nxn=nx/2;nyn=ny/2;nzn=nz/2;
02371 
02372         int K = kb.get_window_size();
02373         int kbmin = -K/2;
02374         int kbmax = -kbmin;
02375         int kbc = kbmax+1;
02376         vector<int> saved_offsets = get_array_offsets();
02377         set_array_offsets(0,0,0);
02378         EMData* ret = this->copy_head();
02379 #ifdef _WIN32
02380         ret->set_size(nxn, _MAX(nyn,1), _MAX(nzn,1));
02381 #else
02382         ret->set_size(nxn, std::max(nyn,1), std::max(nzn,1));
02383 #endif  //_WIN32
02384         //ret->to_zero();  //we will leave margins zeroed.
02385         delx = restrict2(delx, nx);
02386         dely = restrict2(dely, ny);
02387         // center of big image,
02388         int xc = nxn;
02389         int ixs = nxn%2;  // extra shift on account of odd-sized images
02390         int yc = nyn;
02391         int iys = nyn%2;
02392         // center of small image
02393         int xcn = nxn/2;
02394         int ycn = nyn/2;
02395         // shifted center for rotation
02396         float shiftxc = xcn + delx;
02397         float shiftyc = ycn + dely;
02398         // bounds if origin at center
02399         float ymin = -ny/2.0f;
02400         float xmin = -nx/2.0f;
02401         float ymax = -ymin;
02402         float xmax = -xmin;
02403         if (0 == nx%2) xmax--;
02404         if (0 == ny%2) ymax--;
02405 
02406         float   *t = (float*)calloc(kbmax-kbmin+1, sizeof(float));
02407 
02408         // trig
02409         float cang = cos(ang);
02410         float sang = sin(ang);
02411         for (int iy = 0; iy < nyn; iy++) {
02412                 float y = float(iy) - shiftyc;
02413                 float ycang = y*cang/scale + yc;
02414                 float ysang = -y*sang/scale + xc;
02415                 for (int ix = 0; ix < nxn; ix++) {
02416                         float x = float(ix) - shiftxc;
02417                         float xold = x*cang/scale + ysang-ixs;// have to add the fraction on account on odd-sized images for which Fourier zero-padding changes the center location
02418                         float yold = x*sang/scale + ycang-iys;
02419 
02420                         xold = restrict1(xold, nx);
02421                         yold = restrict1(yold, ny);
02422 
02423                         int inxold = int(Util::round(xold)); int inyold = int(Util::round(yold));
02424                         sum=0.0f;    w=0.0f;
02425                         for (int m1 =kbmin; m1 <=kbmax; m1++) t[m1-kbmin] = kb.i0win_tab(xold - inxold-m1);
02426                         if(inxold <= kbc || inxold >=nx-kbc-2 || inyold <= kbc || inyold >=ny-kbc-2 )  {
02427                                 for (int m2 =kbmin; m2 <=kbmax; m2++) {
02428                                         float qt = kb.i0win_tab(yold - inyold-m2);
02429                                         for (int m1 =kbmin; m1 <=kbmax; m1++) {
02430                                                 float q = t[m1-kbmin]*qt;
02431                                                 sum += (*this)((inxold+m1+nx)%nx,(inyold+m2+ny)%ny)*q; w+=q;
02432                                         }
02433                                 }
02434                         } else {
02435                                 for (int m2 =kbmin; m2 <=kbmax; m2++) {
02436                                         float qt = kb.i0win_tab(yold - inyold-m2);
02437                                         for (int m1 =kbmin; m1 <=kbmax; m1++) {
02438                                                 float q = t[m1-kbmin]*qt;
02439                                                 sum += (*this)(inxold+m1,inyold+m2)*q; w+=q;}
02440                                         }
02441                         }
02442                         (*ret)(ix,iy)=sum/w;
02443                 }
02444         }
02445         if (t) free(t);
02446         set_array_offsets(saved_offsets);
02447         return ret;
02448 }

EMData * EMData::rot_scale_conv7 ( float  ang,
float  delx,
float  dely,
Util::KaiserBessel kb,
float  scale_input 
)

Definition at line 2452 of file emdata_sparx.cpp.

References copy_head(), get_array_offsets(), EMAN::Util::KaiserBessel::get_window_size(), EMAN::Util::KaiserBessel::i0win_tab(), ImageDimensionException, max, nx, ny, nz, restrict1(), restrict2(), EMAN::Util::round(), scale(), set_array_offsets(), set_size(), t, x, and y.

Referenced by EMAN::Util::ccc_images_G(), and EMAN::Util::twoD_fine_ali_G().

02452                                                                                                           {
02453         int nxn, nyn, nzn;
02454         float  scale = 0.5f*scale_input;
02455         float  sum, w;
02456         if (1 >= ny)
02457                 throw ImageDimensionException("Can't rotate 1D image");
02458         if (1 < nz)
02459                 throw ImageDimensionException("Volume not currently supported");
02460         nxn = nx/2; nyn=ny/2; nzn=nz/2;
02461 
02462         int K = kb.get_window_size();
02463         int kbmin = -K/2;
02464         int kbmax = -kbmin;
02465         int kbc = kbmax+1;
02466         vector<int> saved_offsets = get_array_offsets();
02467         set_array_offsets(0,0,0);
02468         EMData* ret = this->copy_head();
02469 #ifdef _WIN32
02470         ret->set_size(nxn, _MAX(nyn,1), _MAX(nzn,1));
02471 #else
02472         ret->set_size(nxn, std::max(nyn,1), std::max(nzn,1));
02473 #endif  //_WIN32
02474         //ret->to_zero();  //we will leave margins zeroed.
02475         delx = restrict2(delx, nx);
02476         dely = restrict2(dely, ny);
02477         // center of big image,
02478         int xc = nxn;
02479         int ixs = nxn%2;  // extra shift on account of odd-sized images
02480         int yc = nyn;
02481         int iys = nyn%2;
02482         // center of small image
02483         int xcn = nxn/2;
02484         int ycn = nyn/2;
02485         // shifted center for rotation
02486         float shiftxc = xcn + delx;
02487         float shiftyc = ycn + dely;
02488         // bounds if origin at center
02489         float ymin = -ny/2.0f;
02490         float xmin = -nx/2.0f;
02491         float ymax = -ymin;
02492         float xmax = -xmin;
02493         if (0 == nx%2) xmax--;
02494         if (0 == ny%2) ymax--;
02495 
02496         float   *t = (float*)calloc(kbmax-kbmin+1, sizeof(float));
02497 
02498         // trig
02499         float cang = cos(ang);
02500         float sang = sin(ang);
02501         for (int iy = 0; iy < nyn; iy++) {
02502                 float y = float(iy) - shiftyc;
02503                 float ycang = y*cang/scale + yc;
02504                 float ysang = -y*sang/scale + xc;
02505                 for (int ix = 0; ix < nxn; ix++) {
02506                         float x = float(ix) - shiftxc;
02507                         float xold = x*cang/scale + ysang-ixs;// have to add the fraction on account on odd-sized images for which Fourier zero-padding changes the center location
02508                         float yold = x*sang/scale + ycang-iys;
02509 
02510                         xold = restrict1(xold, nx);
02511                         yold = restrict1(yold, ny);
02512 
02513                         int inxold = int(Util::round(xold)); int inyold = int(Util::round(yold));
02514                         sum=0.0f;    w=0.0f;
02515 
02516                         float tablex1 = kb.i0win_tab(xold-inxold+3);
02517                         float tablex2 = kb.i0win_tab(xold-inxold+2);
02518                         float tablex3 = kb.i0win_tab(xold-inxold+1);
02519                         float tablex4 = kb.i0win_tab(xold-inxold);
02520                         float tablex5 = kb.i0win_tab(xold-inxold-1);
02521                         float tablex6 = kb.i0win_tab(xold-inxold-2);
02522                         float tablex7 = kb.i0win_tab(xold-inxold-3);
02523 
02524                         float tabley1 = kb.i0win_tab(yold-inyold+3);
02525                         float tabley2 = kb.i0win_tab(yold-inyold+2);
02526                         float tabley3 = kb.i0win_tab(yold-inyold+1);
02527                         float tabley4 = kb.i0win_tab(yold-inyold);
02528                         float tabley5 = kb.i0win_tab(yold-inyold-1);
02529                         float tabley6 = kb.i0win_tab(yold-inyold-2);
02530                         float tabley7 = kb.i0win_tab(yold-inyold-3);
02531 
02532                         int x1, x2, x3, x4, x5, x6, x7, y1, y2, y3, y4, y5, y6, y7;
02533 
02534                         if(inxold <= kbc || inxold >=nx-kbc-2 || inyold <= kbc || inyold >=ny-kbc-2 )  {
02535                                 x1 = (inxold-3+nx)%nx;
02536                                 x2 = (inxold-2+nx)%nx;
02537                                 x3 = (inxold-1+nx)%nx;
02538                                 x4 = (inxold  +nx)%nx;
02539                                 x5 = (inxold+1+nx)%nx;
02540                                 x6 = (inxold+2+nx)%nx;
02541                                 x7 = (inxold+3+nx)%nx;
02542 
02543                                 y1 = (inyold-3+ny)%ny;
02544                                 y2 = (inyold-2+ny)%ny;
02545                                 y3 = (inyold-1+ny)%ny;
02546                                 y4 = (inyold  +ny)%ny;
02547                                 y5 = (inyold+1+ny)%ny;
02548                                 y6 = (inyold+2+ny)%ny;
02549                                 y7 = (inyold+3+ny)%ny;
02550                         } else {
02551                                 x1 = inxold-3;
02552                                 x2 = inxold-2;
02553                                 x3 = inxold-1;
02554                                 x4 = inxold;
02555                                 x5 = inxold+1;
02556                                 x6 = inxold+2;
02557                                 x7 = inxold+3;
02558 
02559                                 y1 = inyold-3;
02560                                 y2 = inyold-2;
02561                                 y3 = inyold-1;
02562                                 y4 = inyold;
02563                                 y5 = inyold+1;
02564                                 y6 = inyold+2;
02565                                 y7 = inyold+3;
02566                         }
02567                         sum    =   ( (*this)(x1,y1)*tablex1 + (*this)(x2,y1)*tablex2 + (*this)(x3,y1)*tablex3 +
02568                                      (*this)(x4,y1)*tablex4 + (*this)(x5,y1)*tablex5 + (*this)(x6,y1)*tablex6 +
02569                                      (*this)(x7,y1)*tablex7 ) * tabley1 +
02570                                    ( (*this)(x1,y2)*tablex1 + (*this)(x2,y2)*tablex2 + (*this)(x3,y2)*tablex3 +
02571                                      (*this)(x4,y2)*tablex4 + (*this)(x5,y2)*tablex5 + (*this)(x6,y2)*tablex6 +
02572                                      (*this)(x7,y2)*tablex7 ) * tabley2 +
02573                                    ( (*this)(x1,y3)*tablex1 + (*this)(x2,y3)*tablex2 + (*this)(x3,y3)*tablex3 +
02574                                      (*this)(x4,y3)*tablex4 + (*this)(x5,y3)*tablex5 + (*this)(x6,y3)*tablex6 +
02575                                      (*this)(x7,y3)*tablex7 ) * tabley3 +
02576                                    ( (*this)(x1,y4)*tablex1 + (*this)(x2,y4)*tablex2 + (*this)(x3,y4)*tablex3 +
02577                                      (*this)(x4,y4)*tablex4 + (*this)(x5,y4)*tablex5 + (*this)(x6,y4)*tablex6 +
02578                                      (*this)(x7,y4)*tablex7 ) * tabley4 +
02579                                    ( (*this)(x1,y5)*tablex1 + (*this)(x2,y5)*tablex2 + (*this)(x3,y5)*tablex3 +
02580                                      (*this)(x4,y5)*tablex4 + (*this)(x5,y5)*tablex5 + (*this)(x6,y5)*tablex6 +
02581                                      (*this)(x7,y5)*tablex7 ) * tabley5 +
02582                                    ( (*this)(x1,y6)*tablex1 + (*this)(x2,y6)*tablex2 + (*this)(x3,y6)*tablex3 +
02583                                      (*this)(x4,y6)*tablex4 + (*this)(x5,y6)*tablex5 + (*this)(x6,y6)*tablex6 +
02584                                      (*this)(x7,y6)*tablex7 ) * tabley6 +
02585                                    ( (*this)(x1,y7)*tablex1 + (*this)(x2,y7)*tablex2 + (*this)(x3,y7)*tablex3 +
02586                                      (*this)(x4,y7)*tablex4 + (*this)(x5,y7)*tablex5 + (*this)(x6,y7)*tablex6 +
02587                                      (*this)(x7,y7)*tablex7 ) * tabley7;
02588 
02589                         w = (tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7) *
02590                             (tabley1+tabley2+tabley3+tabley4+tabley5+tabley6+tabley7);
02591 
02592                         (*ret)(ix,iy)=sum/w;
02593                 }
02594         }
02595         if (t) free(t);
02596         set_array_offsets(saved_offsets);
02597         return ret;
02598 }

EMData * EMData::rot_scale_conv_new ( float  ang,
float  delx,
float  dely,
Util::KaiserBessel kb,
float  scale = 1.0 
)

Definition at line 2632 of file emdata_sparx.cpp.

References copy_head(), data, get_array_offsets(), get_data(), EMAN::Util::get_pixel_conv_new(), EMAN::Util::KaiserBessel::get_window_size(), ImageDimensionException, max, nx, ny, nz, restrict2(), scale(), set_array_offsets(), set_size(), t, x, and y.

02632                                                                                                              {
02633 
02634         int nxn, nyn, nzn;
02635 
02636         if (scale_input == 0.0f) scale_input = 1.0f;
02637         float  scale = 0.5f*scale_input;
02638 
02639         if (1 >= ny)
02640                 throw ImageDimensionException("Can't rotate 1D image");
02641         if (1 < nz)
02642                 throw ImageDimensionException("Volume not currently supported");
02643         nxn = nx/2; nyn = ny/2; nzn = nz/2;
02644 
02645         int K = kb.get_window_size();
02646         int kbmin = -K/2;
02647         int kbmax = -kbmin;
02648 
02649         vector<int> saved_offsets = get_array_offsets();
02650         set_array_offsets(0,0,0);
02651         EMData* ret = this->copy_head();
02652 #ifdef _WIN32
02653         ret->set_size(nxn, _MAX(nyn,1), _MAX(nzn,1));
02654 #else
02655         ret->set_size(nxn, std::max(nyn,1), std::max(nzn,1));
02656 #endif  //_WIN32
02657         //ret->to_zero();  //we will leave margins zeroed.
02658         delx = restrict2(delx, nx);
02659         dely = restrict2(dely, ny);
02660         // center of big image,
02661         int xc = nxn;
02662         int ixs = nxn%2;  // extra shift on account of odd-sized images
02663         int yc = nyn;
02664         int iys = nyn%2;
02665         // center of small image
02666         int xcn = nxn/2;
02667         int ycn = nyn/2;
02668         // shifted center for rotation
02669         float shiftxc = xcn + delx;
02670         float shiftyc = ycn + dely;
02671         // bounds if origin at center
02672         float ymin = -ny/2.0f;
02673         float xmin = -nx/2.0f;
02674         float ymax = -ymin;
02675         float xmax = -xmin;
02676         if (0 == nx%2) xmax--;
02677         if (0 == ny%2) ymax--;
02678 
02679         float *t = (float*)calloc(kbmax-kbmin+1, sizeof(float));
02680 
02681         float* data = this->get_data();
02682 
02683         // trig
02684         float cang = cos(ang);
02685         float sang = sin(ang);
02686         for (int iy = 0; iy < nyn; iy++) {
02687                 float y = float(iy) - shiftyc;
02688                 float ycang = y*cang/scale + yc;
02689                 float ysang = -y*sang/scale + xc;
02690                 for (int ix = 0; ix < nxn; ix++) {
02691                         float x = float(ix) - shiftxc;
02692                         float xold = x*cang/scale + ysang-ixs;// have to add the fraction on account on odd-sized images for which Fourier zero-padding changes the center location
02693                         float yold = x*sang/scale + ycang-iys;
02694 
02695                         (*ret)(ix,iy) = Util::get_pixel_conv_new(nx, ny, 1, xold, yold, 1, data, kb);
02696                 }
02697         }
02698         if (t) free(t);
02699         set_array_offsets(saved_offsets);
02700         return ret;
02701 }

EMData * EMData::rot_scale_conv_new_background ( float  ang,
float  delx,
float  dely,
Util::KaiserBessel kb,
float  scale = 1.0 
)

Definition at line 2703 of file emdata_sparx.cpp.

References copy_head(), data, get_array_offsets(), get_data(), EMAN::Util::get_pixel_conv_new_background(), EMAN::Util::KaiserBessel::get_window_size(), ImageDimensionException, max, nx, ny, nz, restrict2(), scale(), set_array_offsets(), set_size(), t, x, and y.

02703                                                                                                                         {
02704 
02705         int nxn, nyn, nzn;
02706         
02707         if (scale_input == 0.0f) scale_input = 1.0f;
02708         float  scale = 0.5f*scale_input;
02709 
02710         if (1 >= ny)
02711                 throw ImageDimensionException("Can't rotate 1D image");
02712         if (1 < nz) 
02713                 throw ImageDimensionException("Volume not currently supported");
02714         nxn = nx/2; nyn = ny/2; nzn = nz/2;
02715 
02716         int K = kb.get_window_size();
02717         int kbmin = -K/2;
02718         int kbmax = -kbmin;
02719 
02720         vector<int> saved_offsets = get_array_offsets();
02721         set_array_offsets(0,0,0);
02722         EMData* ret = this->copy_head();
02723 #ifdef _WIN32
02724         ret->set_size(nxn, _MAX(nyn,1), _MAX(nzn,1));
02725 #else
02726         ret->set_size(nxn, std::max(nyn,1), std::max(nzn,1));
02727 #endif  //_WIN32 
02728         //ret->to_zero();  //we will leave margins zeroed.
02729         delx = restrict2(delx, nx);
02730         dely = restrict2(dely, ny);
02731         // center of big image,
02732         int xc = nxn;
02733         int ixs = nxn%2;  // extra shift on account of odd-sized images
02734         int yc = nyn;
02735         int iys = nyn%2;
02736         // center of small image
02737         int xcn = nxn/2;
02738         int ycn = nyn/2;
02739         // shifted center for rotation
02740         float shiftxc = xcn + delx;
02741         float shiftyc = ycn + dely;
02742         // bounds if origin at center
02743         float ymin = -ny/2.0f;
02744         float xmin = -nx/2.0f;
02745         float ymax = -ymin;
02746         float xmax = -xmin;
02747         if (0 == nx%2) xmax--;
02748         if (0 == ny%2) ymax--;
02749         
02750         float *t = (float*)calloc(kbmax-kbmin+1, sizeof(float));
02751         
02752         float* data = this->get_data();
02753 
02754         // trig
02755         float cang = cos(ang);
02756         float sang = sin(ang);
02757         for (int iy = 0; iy < nyn; iy++) {
02758                 float y = float(iy) - shiftyc;
02759                 float ycang = y*cang/scale + yc;
02760                 float ysang = -y*sang/scale + xc;
02761                 for (int ix = 0; ix < nxn; ix++) {
02762                         float x = float(ix) - shiftxc;
02763                         float xold = x*cang/scale + ysang-ixs;// have to add the fraction on account on odd-sized images for which Fourier zero-padding changes the center location 
02764                         float yold = x*sang/scale + ycang-iys;
02765                         
02766                         (*ret)(ix,iy) = Util::get_pixel_conv_new_background(nx, ny, 1, xold, yold, 1, data, kb, ix,iy);
02767                 }
02768         }
02769         if (t) free(t);
02770         set_array_offsets(saved_offsets);
02771         return ret;
02772 }

EMData * EMData::rot_scale_trans ( const Transform RA  ) 

Rotate-Shift-Scale-Circulantly image.

If the image is a volume, then all slices are rotated/translated/scaled.

Parameters:
[in] RA Transform3D object
Exceptions:
ImageDimensionException can not rotate 1 D image
Returns:
New rotated/shifted/scaled image

Definition at line 1856 of file emdata_sparx.cpp.

References EMAN::Vec3< Type >::at(), copy_head(), get_array_offsets(), get_data(), EMAN::Transform::get_trans(), ImageDimensionException, in, EMAN::Transform::inverse(), min, nx, ny, nz, restrict1(), restrict2(), set_array_offsets(), t, x, and y.

Referenced by symvol().

01856                                            {
01857 
01858         EMData* ret = copy_head();
01859         float *in = this->get_data();
01860         vector<int> saved_offsets = get_array_offsets();
01861         set_array_offsets(0,0,0);
01862         Vec3f translations = RA.get_trans();
01863         Transform RAinv = RA.inverse();
01864 
01865         if (1 >= ny)  throw ImageDimensionException("Can't rotate 1D image");
01866         if (nz < 2) {
01867         float  p1, p2, p3, p4;
01868         float delx = translations.at(0);
01869         float dely = translations.at(1);
01870         delx = restrict2(delx, nx);
01871         dely = restrict2(dely, ny);
01872         int xc = nx/2;
01873         int yc = ny/2;
01874 //         shifted center for rotation
01875         float shiftxc = xc + delx;
01876         float shiftyc = yc + dely;
01877                 for (int iy = 0; iy < ny; iy++) {
01878                         float y = float(iy) - shiftyc;
01879                         float ysang = y*RAinv[0][1]+xc;
01880                         float ycang = y*RAinv[1][1]+yc;
01881                         for (int ix = 0; ix < nx; ix++) {
01882                                 float x = float(ix) - shiftxc;
01883                                 float xold = x*RAinv[0][0] + ysang;
01884                                 float yold = x*RAinv[1][0] + ycang;
01885 
01886                                 xold = restrict1(xold, nx);
01887                                 yold = restrict1(yold, ny);
01888 
01889                                 int xfloor = int(xold);
01890                                 int yfloor = int(yold);
01891                                 float t = xold-xfloor;
01892                                 float u = yold-yfloor;
01893                                 if(xfloor == nx -1 && yfloor == ny -1) {
01894 
01895                                     p1 =in[xfloor   + yfloor*ny];
01896                                         p2 =in[ yfloor*ny];
01897                                         p3 =in[0];
01898                                         p4 =in[xfloor];
01899                                 } else if(xfloor == nx - 1) {
01900 
01901                                         p1 =in[xfloor   + yfloor*ny];
01902                                         p2 =in[           yfloor*ny];
01903                                         p3 =in[          (yfloor+1)*ny];
01904                                         p4 =in[xfloor   + (yfloor+1)*ny];
01905                                 } else if(yfloor == ny - 1) {
01906 
01907                                         p1 =in[xfloor   + yfloor*ny];
01908                                         p2 =in[xfloor+1 + yfloor*ny];
01909                                         p3 =in[xfloor+1 ];
01910                                         p4 =in[xfloor   ];
01911                                 } else {
01912                                         p1 =in[xfloor   + yfloor*ny];
01913                                         p2 =in[xfloor+1 + yfloor*ny];
01914                                         p3 =in[xfloor+1 + (yfloor+1)*ny];
01915                                         p4 =in[xfloor   + (yfloor+1)*ny];
01916                                 }
01917                                 (*ret)(ix,iy) = p1 + u * ( p4 - p1) + t * ( p2 - p1 + u *(p3-p2-p4+p1));
01918                         } //ends x loop
01919                 } // ends y loop
01920                 set_array_offsets(saved_offsets);
01921                 return ret;
01922         } else {
01923 //               This begins the 3D version trilinear interpolation.
01924 
01925         float delx = translations.at(0);
01926         float dely = translations.at(1);
01927         float delz = translations.at(2);
01928         delx = restrict2(delx, nx);
01929         dely = restrict2(dely, ny);
01930         delz = restrict2(delz, nz);
01931         int xc = nx/2;
01932         int yc = ny/2;
01933         int zc = nz/2;
01934 //         shifted center for rotation
01935         float shiftxc = xc + delx;
01936         float shiftyc = yc + dely;
01937         float shiftzc = zc + delz;
01938 
01939                 for (int iz = 0; iz < nz; iz++) {
01940                         float z = float(iz) - shiftzc;
01941                         float xoldz = z*RAinv[0][2]+xc;
01942                         float yoldz = z*RAinv[1][2]+yc;
01943                         float zoldz = z*RAinv[2][2]+zc;
01944                         for (int iy = 0; iy < ny; iy++) {
01945                                 float y = float(iy) - shiftyc;
01946                                 float xoldzy = xoldz + y*RAinv[0][1] ;
01947                                 float yoldzy = yoldz + y*RAinv[1][1] ;
01948                                 float zoldzy = zoldz + y*RAinv[2][1] ;
01949                                 for (int ix = 0; ix < nx; ix++) {
01950                                         float x = float(ix) - shiftxc;
01951                                         float xold = xoldzy + x*RAinv[0][0] ;
01952                                         float yold = yoldzy + x*RAinv[1][0] ;
01953                                         float zold = zoldzy + x*RAinv[2][0] ;
01954 
01955                                         xold = restrict1(xold, nx);
01956                                         yold = restrict1(yold, ny);
01957                                         zold = restrict1(zold, nz);
01958 
01959 
01960                                         int IOX = int(xold);
01961                                         int IOY = int(yold);
01962                                         int IOZ = int(zold);
01963 
01964                                         #ifdef _WIN32
01965                                         int IOXp1 = _MIN( nx-1 ,IOX+1);
01966                                         #else
01967                                         int IOXp1 = std::min( nx-1 ,IOX+1);
01968                                         #endif  //_WIN32
01969 
01970                                         #ifdef _WIN32
01971                                         int IOYp1 = _MIN( ny-1 ,IOY+1);
01972                                         #else
01973                                         int IOYp1 = std::min( ny-1 ,IOY+1);
01974                                         #endif  //_WIN32
01975 
01976                                         #ifdef _WIN32
01977                                         int IOZp1 = _MIN( nz-1 ,IOZ+1);
01978                                         #else
01979                                         int IOZp1 = std::min( nz-1 ,IOZ+1);
01980                                         #endif  //_WIN32
01981 
01982                                         float dx = xold-IOX;
01983                                         float dy = yold-IOY;
01984                                         float dz = zold-IOZ;
01985 
01986                                         float a1 = in(IOX,IOY,IOZ);
01987                                         float a2 = in(IOXp1,IOY,IOZ) - in(IOX,IOY,IOZ);
01988                                         float a3 = in(IOX,IOYp1,IOZ) - in(IOX,IOY,IOZ);
01989                                         float a4 = in(IOX,IOY,IOZp1) - in(IOX,IOY,IOZ);
01990                                         float a5 = in(IOX,IOY,IOZ) - in(IOXp1,IOY,IOZ) - in(IOX,IOYp1,IOZ) + in(IOXp1,IOYp1,IOZ);
01991                                         float a6 = in(IOX,IOY,IOZ) - in(IOXp1,IOY,IOZ) - in(IOX,IOY,IOZp1) + in(IOXp1,IOY,IOZp1);
01992                                         float a7 = in(IOX,IOY,IOZ) - in(IOX,IOYp1,IOZ) - in(IOX,IOY,IOZp1) + in(IOX,IOYp1,IOZp1);
01993                                         float a8 = in(IOXp1,IOY,IOZ) + in(IOX,IOYp1,IOZ)+ in(IOX,IOY,IOZp1)
01994                                                         - in(IOX,IOY,IOZ)- in(IOXp1,IOYp1,IOZ) - in(IOXp1,IOY,IOZp1)
01995                                                         - in(IOX,IOYp1,IOZp1) + in(IOXp1,IOYp1,IOZp1);
01996                                         (*ret)(ix,iy,iz) = a1 + dz*(a4 + a6*dx + (a7 + a8*dx)*dy) + a3*dy + dx*(a2 + a5*dy);
01997                                 } //ends x loop
01998                         } // ends y loop
01999                 } // ends z loop
02000 
02001                 set_array_offsets(saved_offsets);
02002                 return ret;
02003 
02004 /*     This entire section has to go somewhere for quadratic 3D interpolation PAP 12/29/07
02005 //               This begins the 3D version triquadratic interpolation.
02006 
02007         float delx = translations.at(0);
02008         float dely = translations.at(1);
02009         float delz = translations.at(2);
02010         if(delx >= 0.0f) { delx = fmod(delx, float(nx));} else {delx = -fmod(-delx, float(nx));}
02011         if(dely >= 0.0f) { dely = fmod(dely, float(ny));} else {dely = -fmod(-dely, float(ny));}
02012         if(dely >= 0.0f) { delz = fmod(delz, float(nz));} else {delz = -fmod(-delz, float(nz));}
02013         int xc = nx/2;
02014         int yc = ny/2;
02015         int zc = nz/2;
02016 //         shifted center for rotation
02017         float shiftxc = xc + delx;
02018         float shiftyc = yc + dely;
02019         float shiftzc = zc + delz;
02020 //                  set up array to use later
02021 //
02022                 int xArr[27];
02023                 int yArr[27];
02024                 int zArr[27];
02025                 float fdata[27];
02026 
02027                 for (int iL=0; iL<27 ; iL++){  // need this indexing array later
02028                         xArr[iL]  =  (int) (fmod((float)iL,3.0f) - 1.0f);
02029                         yArr[iL]  =  (int)( fmod( ((float) (iL/3) ),3.0f)- 1.0f);
02030                         zArr[iL]  = ((int) (iL/9)  ) -1;
02031 //                      printf("iL=%d, \t xArr=%d, \t yArr=%d, \t zArr=%d \n",iL, xArr[iL],yArr[iL],zArr[iL]);
02032                 }
02033 
02034 //              for (int iz = 0; iz < nz; iz++) {for (int iy = 0; iy < ny; iy++) {for (int ix = 0; ix < nx; ix++) {
02035 //                    (*ret)(ix,iy,iz) = 0;}}}   // initialize returned data
02036 
02037                 for (int iz = 0; iz < nz; iz++) {
02038                         float z = float(iz) - shiftzc;
02039                         float xoldz = z*RAinv[0][2]+xc;
02040                         float yoldz = z*RAinv[1][2]+yc;
02041                         float zoldz = z*RAinv[2][2]+zc;
02042                         for (int iy = 0; iy < ny; iy++) {
02043                                 float y = float(iy) - shiftyc;
02044                                 float xoldzy = xoldz + y*RAinv[0][1] ;
02045                                 float yoldzy = yoldz + y*RAinv[1][1] ;
02046                                 float zoldzy = zoldz + y*RAinv[2][1] ;
02047                                 for (int ix = 0; ix < nx; ix++) {
02048                                         float x = float(ix) - shiftxc;
02049                                         float xold = xoldzy + x*RAinv[0][0] ;
02050                                         float yold = yoldzy + x*RAinv[1][0] ;
02051                                         float zold = zoldzy + x*RAinv[2][0] ;
02052 
02053 
02054                                 if (xold < 0.0f) xold = fmod((int(xold/float(nx))+1)*nx-xold, float(nx));
02055                                 else if (xold > (float) (nx-1) ) xold = fmod(xold, float(nx));
02056                                 if (yold < 0.0f) yold =fmod((int(yold/float(ny))+1)*ny-yold, float(ny));
02057                                 else if (yold > (float) (ny-1) ) yold = fmod(yold, float(ny));
02058                                 if (zold < 0.0f) zold =fmod((int(zold/float(nz))+1)*nz-zold, float(nz));
02059                                 else if (zold > (float) (nz-1) ) zold = fmod(zold, float(nz));
02060 
02061                                 //  what follows does not accelerate the code; moreover, I doubt it is correct PAP 12/29/07
02062                                 //while ( xold >= (float)(nx) )  xold -= nx;
02063                                 //while ( xold < 0.0f )         xold += nx;
02064                                 //while ( yold >= (float)(ny) )  yold -= ny;
02065                                 //while ( yold < 0.0f )         yold += ny;
02066                                 //while ( zold >= (float)(nz) )  zold -= nz;
02067                                 //while ( zold < 0.0f )         zold += nz;
02068 
02069 //         This is currently coded the way  SPIDER coded it,
02070 //            changing floor to round  in the next 3 lines below may be better
02071 //                                      int IOX = (int) floor(xold); // This is the center of the array
02072 //                                      int IOY = (int) floor(yold ); // In the next loop we interpolate
02073 //                                      int IOZ = (int) floor(zold ); //  If floor is used dx is positive
02074                                         int IOX = int(xold);
02075                                         int IOY = int(yold);
02076                                         int IOZ = int(zold);
02077 
02078                                         float dx = xold-IOX; //remainder(xold,1);  //  now |dx| <= .5
02079                                         float dy = yold-IOY; //remainder(yold,1);
02080                                         float dz = zold-IOZ; //remainder(zold,1);
02081 
02082 //                                      printf(" IOX=%d \t IOY=%d \t IOZ=%d \n", IOX, IOY, IOZ);
02083 //                                      if (IOX>=0 && IOX<nx  && IOY>=0 && IOY < ny && IOZ >= 0 && IOZ < nz ) {
02084 //                                              ROTATED POSITION IS INSIDE OF VOLUME
02085 //                                              FIND INTENSITIES ON 3x3x3 COORDINATE GRID;
02086 //                                     Solution is wrapped
02087                                                 for  (int iL=0; iL<27 ; iL++){
02088                                                         int xCoor = (int) fmod(IOX+xArr[iL] + nx + .0001f, (float) nx);
02089                                                         int yCoor = (int) fmod(IOY+yArr[iL] + ny + .0001f, (float) ny);
02090                                                         int zCoor = (int) fmod(IOZ+zArr[iL] + nz + .0001f, (float) nz);
02091                                                         fdata[iL] = (*this)( xCoor, yCoor ,zCoor );
02092 //                                                      if (iy==iz && iz==0){printf(" fdata=%f \n", fdata[iL]);}
02093 //                                              }
02094                                         }
02095 
02096                                         (*ret)(ix,iy,iz) = Util::triquad(dx, dy, dz, fdata);
02097 //                                      (*ret)(ix,iy,iz) = Util:: trilinear_interpolate(fdata[13],fdata[14],fdata[16],
02098 //                                                                                      fdata[17],fdata[22],fdata[23],
02099 //                                                                                      fdata[25],fdata[26],dx, dy, dz);
02100 //      p1 iL=13,   xArr= 0,         yArr= 0,         zArr= 0
02101 //      p2 iL=14,   xArr= 1,         yArr= 0,         zArr= 0
02102 //      p3 iL=16,   xArr= 0,         yArr= 1,         zArr= 0
02103 //      p4 iL=17,   xArr= 1,         yArr= 1,         zArr= 0
02104 //      p5 iL=22,   xArr= 0,         yArr= 0,         zArr= 1
02105 //      p6 iL=23,   xArr= 1,         yArr= 0,         zArr= 1
02106 //      p7 iL=25,   xArr= 0,         yArr= 1,         zArr= 1
02107 //      p8 iL=26,   xArr= 1,         yArr= 1,         zArr= 1
02108 
02109 
02110 
02111                                 } //ends x loop
02112                         } // ends y loop
02113                 } // ends z loop
02114 
02115                 set_array_offsets(saved_offsets);
02116                 return ret;
02117 */
02118         }
02119 }

EMData * EMData::rot_scale_trans2D ( float  ang,
float  delx = 0.0f,
float  dely = 0.0f,
float  scale = 1.0f 
)

Rotate-Shift-Scale-Circulantly image.

If the image is a volume, then all slices are rotated/translated/scaled.

Parameters:
[in] ang Rotation angle in degrees.
[in] delx Amount to shift rotation origin along x
[in] dely Amount to shift rotation origin along y
[in] scale Scaling factor (default=1.0)
Exceptions:
ImageDimensionException can not rotate 1 D image
ImageDimensionException can not rotate 3 D image
Returns:
New rotated/shifted/scaled image

Definition at line 1774 of file emdata_sparx.cpp.

References copy_head(), get_array_offsets(), get_data(), ImageDimensionException, nx, ny, nz, EMAN::Util::quadri(), restrict2(), set_array_offsets(), x, and y.

Referenced by EMAN::Util::ccc_images(), main(), and EMAN::Util::twoD_fine_ali().

01774                                                                                    { // quadratic, no background, 2D
01775         float ang=angDeg*M_PI/180.0f;
01776         if (1 >= ny)
01777                 throw ImageDimensionException("Can't rotate 1D image");
01778         if (nz<2) {
01779                 vector<int> saved_offsets = get_array_offsets();
01780                 set_array_offsets(0,0,0);
01781                 if (0.0f == scale) scale = 1.0f; // silently fix common user error
01782                 EMData* ret = copy_head();
01783                 delx = restrict2(delx, nx);
01784                 dely = restrict2(dely, ny);
01785                 // center of image
01786                 int xc = nx/2;
01787                 int yc = ny/2;
01788                 // shifted center for rotation
01789                 float shiftxc = xc + delx;
01790                 float shiftyc = yc + dely;
01791                 // trig
01792                 float cang = cos(ang);
01793                 float sang = sin(ang);
01794                         for (int iy = 0; iy < ny; iy++) {
01795                                 float y = float(iy) - shiftyc;
01796                                 float ycang = y*cang/scale + yc;
01797                                 float ysang = -y*sang/scale + xc;
01798                                 for (int ix = 0; ix < nx; ix++) {
01799                                         float x = float(ix) - shiftxc;
01800                                         float xold = x*cang/scale + ysang ;
01801                                         float yold = x*sang/scale + ycang ;
01802                                         //  quadri is taking care of cyclic count
01803                                         (*ret)(ix,iy) = Util::quadri(xold+1.0f, yold+1.0f, nx, ny, get_data());
01804                                            //have to add one as quadri uses Fortran counting
01805                                 }
01806                         }
01807                 set_array_offsets(saved_offsets);
01808                 return ret;
01809         } else {
01810                 throw ImageDimensionException("Volume not currently supported");
01811         }
01812 }

EMData * EMData::rot_scale_trans2D_background ( float  ang,
float  delx = 0.0f,
float  dely = 0.0f,
float  scale = 1.0f 
)

Rotate-Shift-Scale image.

In contrast to rot_scale_trans2D, wrap aroud is not done circulantly so as to prevent artifacts from occurring.

If the image is a volume, then all slices are rotated/translated/scaled.

Parameters:
[in] ang Rotation angle in degrees.
[in] delx Amount to shift rotation origin along x (default=0.0)
[in] dely Amount to shift rotation origin along y (default=0.0)
[in] scale Scaling factor (default=1.0)
Exceptions:
ImageDimensionException can not rotate 1 D image
ImageDimensionException can not rotate 3 D image
Returns:
New rotated/shifted/scaled image

Definition at line 1814 of file emdata_sparx.cpp.

References copy_head(), get_array_offsets(), get_data(), ImageDimensionException, nx, ny, nz, EMAN::Util::quadri_background(), restrict2(), set_array_offsets(), x, and y.

01814                                                                                               { // quadratic, no background, 2D
01815     float ang=angDeg*M_PI/180.0f;
01816         if (1 >= ny)
01817                 throw ImageDimensionException("Can't rotate 1D image");
01818         if (nz<2) { 
01819                 vector<int> saved_offsets = get_array_offsets();
01820                 set_array_offsets(0,0,0);
01821                 if (0.0f == scale) scale = 1.0f; // silently fix common user error
01822                 EMData* ret = copy_head();
01823                 delx = restrict2(delx, nx);
01824                 dely = restrict2(dely, ny);
01825                 // center of image
01826                 int xc = nx/2;
01827                 int yc = ny/2;
01828                 // shifted center for rotation
01829                 float shiftxc = xc + delx;
01830                 float shiftyc = yc + dely;
01831                 // trig
01832                 float cang = cos(ang);
01833                 float sang = sin(ang);
01834                         for (int iy = 0; iy < ny; iy++) {
01835                                 float y = float(iy) - shiftyc;
01836                                 float ycang = y*cang/scale + yc;
01837                                 float ysang = -y*sang/scale + xc;
01838                                 for (int ix = 0; ix < nx; ix++) {
01839                                         float x = float(ix) - shiftxc;
01840                                         float xold = x*cang/scale + ysang ;
01841                                         float yold = x*sang/scale + ycang ;
01842                                         //  in quadri_background, wrap around is not done circulantly; if (xold,yold) is not in the image, then it's replaced by (ix,iy)
01843                                         (*ret)(ix,iy) = Util::quadri_background(xold+1.0f, yold+1.0f, nx, ny, get_data(),ix+1,iy+1);
01844                                            //have to add one as quadri uses Fortran counting
01845                                 }
01846                         }
01847                 set_array_offsets(saved_offsets);
01848                 return ret;
01849         } else {
01850                 throw ImageDimensionException("Volume not currently supported");
01851         }
01852 }

EMData * EMData::rot_scale_trans_background ( const Transform RA  ) 

Rotate-Shift-Scale image.

In contrast to rot_scale_trans, wrap around is not done circulantly so as to prevent artifacts occurring during rotation.

If the image is a volume, then all slices are rotated/translated/scaled.

Parameters:
[in] RA Transform3D object
Exceptions:
ImageDimensionException can not rotate 1 D image
Returns:
New rotated/shifted/scaled image

Definition at line 2125 of file emdata_sparx.cpp.

References EMAN::Vec3< Type >::at(), copy_head(), get_array_offsets(), get_data(), EMAN::Transform::get_trans(), ImageDimensionException, in, EMAN::Transform::inverse(), min, nx, ny, nz, restrict2(), set_array_offsets(), t, x, and y.

02125                                                       {
02126         EMData* ret = copy_head();
02127         float *in = this->get_data();
02128         vector<int> saved_offsets = get_array_offsets();
02129         set_array_offsets(0,0,0);
02130         Vec3f translations = RA.get_trans();
02131         Transform RAinv = RA.inverse();
02132                 
02133         if (1 >= ny)  throw ImageDimensionException("Can't rotate 1D image");
02134         if (nz < 2) { 
02135         float  p1, p2, p3, p4;
02136         float delx = translations.at(0);
02137         float dely = translations.at(1);
02138         delx = restrict2(delx, nx);
02139         dely = restrict2(dely, ny);
02140         int xc = nx/2;
02141         int yc = ny/2;
02142 //         shifted center for rotation
02143         float shiftxc = xc + delx;
02144         float shiftyc = yc + dely;
02145                 for (int iy = 0; iy < ny; iy++) {
02146                         float y = float(iy) - shiftyc;
02147                         float ysang = y*RAinv[0][1]+xc;                 
02148                         float ycang = y*RAinv[1][1]+yc;         
02149                         for (int ix = 0; ix < nx; ix++) {
02150                                 float x = float(ix) - shiftxc;
02151                                 float xold = x*RAinv[0][0] + ysang;
02152                                 float yold = x*RAinv[1][0] + ycang;
02153  
02154                                 // if (xold,yold) is outside the image, then let xold = ix and yold = iy
02155 
02156                 if ( (xold < 0.0f) || (xold >= (float)(nx)) || (yold < 0.0f) || (yold >= (float)(ny)) ){
02157                                     xold = (float)ix;
02158                                         yold = (float)iy;
02159                                 }       
02160 
02161                                 int xfloor = int(xold);
02162                                 int yfloor = int(yold);
02163                                 float t = xold-xfloor;
02164                                 float u = yold-yfloor;
02165                                 if(xfloor == nx -1 && yfloor == ny -1) {
02166                                 
02167                                     p1 =in[xfloor   + yfloor*ny];
02168                                         p2 =in[ yfloor*ny];
02169                                         p3 =in[0];
02170                                         p4 =in[xfloor];
02171                                 } else if(xfloor == nx - 1) {
02172                                 
02173                                         p1 =in[xfloor   + yfloor*ny];
02174                                         p2 =in[           yfloor*ny];
02175                                         p3 =in[          (yfloor+1)*ny];
02176                                         p4 =in[xfloor   + (yfloor+1)*ny];
02177                                 } else if(yfloor == ny - 1) {
02178                                 
02179                                         p1 =in[xfloor   + yfloor*ny];
02180                                         p2 =in[xfloor+1 + yfloor*ny];
02181                                         p3 =in[xfloor+1 ];
02182                                         p4 =in[xfloor   ];
02183                                 } else {
02184                                 
02185                                         p1 =in[xfloor   + yfloor*ny];
02186                                         p2 =in[xfloor+1 + yfloor*ny];
02187                                         p3 =in[xfloor+1 + (yfloor+1)*ny];
02188                                         p4 =in[xfloor   + (yfloor+1)*ny];
02189                                 }
02190                                 (*ret)(ix,iy) = p1 + u * ( p4 - p1) + t * ( p2 - p1 + u *(p3-p2-p4+p1));
02191                         } //ends x loop
02192                 } // ends y loop
02193                 set_array_offsets(saved_offsets);
02194                 return ret;
02195         } else {
02196 //               This begins the 3D version trilinear interpolation.
02197 
02198         float delx = translations.at(0);
02199         float dely = translations.at(1);
02200         float delz = translations.at(2);
02201         delx = restrict2(delx, nx);
02202         dely = restrict2(dely, ny);
02203         delz = restrict2(delz, nz);
02204         int xc = nx/2;
02205         int yc = ny/2;
02206         int zc = nz/2;
02207 //         shifted center for rotation
02208         float shiftxc = xc + delx;
02209         float shiftyc = yc + dely;
02210         float shiftzc = zc + delz;
02211                 
02212                 for (int iz = 0; iz < nz; iz++) {
02213                         float z = float(iz) - shiftzc;
02214                         float xoldz = z*RAinv[0][2]+xc;
02215                         float yoldz = z*RAinv[1][2]+yc;
02216                         float zoldz = z*RAinv[2][2]+zc;
02217                         for (int iy = 0; iy < ny; iy++) {
02218                                 float y = float(iy) - shiftyc;
02219                                 float xoldzy = xoldz + y*RAinv[0][1] ;
02220                                 float yoldzy = yoldz + y*RAinv[1][1] ;
02221                                 float zoldzy = zoldz + y*RAinv[2][1] ;
02222                                 for (int ix = 0; ix < nx; ix++) {
02223                                         float x = float(ix) - shiftxc;
02224                                         float xold = xoldzy + x*RAinv[0][0] ;
02225                                         float yold = yoldzy + x*RAinv[1][0] ;
02226                                         float zold = zoldzy + x*RAinv[2][0] ;
02227                                         
02228                                         // if (xold,yold,zold) is outside the image, then let xold = ix, yold = iy and zold=iz
02229 
02230                     if ( (xold < 0.0f) || (xold >= (float)(nx)) || (yold < 0.0f) || (yold >= (float)(ny))  || (zold < 0.0f) || (zold >= (float)(nz)) ){
02231                                          xold = (float)ix;
02232                                              yold = (float)iy;
02233                                                  zold = (float)iz;
02234                                         }       
02235                                         
02236                                         int IOX = int(xold);
02237                                         int IOY = int(yold);
02238                                         int IOZ = int(zold);
02239                 
02240                                         #ifdef _WIN32
02241                                         int IOXp1 = _MIN( nx-1 ,IOX+1);
02242                                         #else
02243                                         int IOXp1 = std::min( nx-1 ,IOX+1);
02244                                         #endif  //_WIN32
02245                 
02246                                         #ifdef _WIN32
02247                                         int IOYp1 = _MIN( ny-1 ,IOY+1);
02248                                         #else
02249                                         int IOYp1 = std::min( ny-1 ,IOY+1);
02250                                         #endif  //_WIN32
02251                 
02252                                         #ifdef _WIN32
02253                                         int IOZp1 = _MIN( nz-1 ,IOZ+1);
02254                                         #else
02255                                         int IOZp1 = std::min( nz-1 ,IOZ+1);
02256                                         #endif  //_WIN32
02257 
02258                                         float dx = xold-IOX;
02259                                         float dy = yold-IOY;
02260                                         float dz = zold-IOZ;
02261                                                                                                         
02262                                         float a1 = in(IOX,IOY,IOZ);
02263                                         float a2 = in(IOXp1,IOY,IOZ) - in(IOX,IOY,IOZ);
02264                                         float a3 = in(IOX,IOYp1,IOZ) - in(IOX,IOY,IOZ);
02265                                         float a4 = in(IOX,IOY,IOZp1) - in(IOX,IOY,IOZ);
02266                                         float a5 = in(IOX,IOY,IOZ) - in(IOXp1,IOY,IOZ) - in(IOX,IOYp1,IOZ) + in(IOXp1,IOYp1,IOZ);
02267                                         float a6 = in(IOX,IOY,IOZ) - in(IOXp1,IOY,IOZ) - in(IOX,IOY,IOZp1) + in(IOXp1,IOY,IOZp1);
02268                                         float a7 = in(IOX,IOY,IOZ) - in(IOX,IOYp1,IOZ) - in(IOX,IOY,IOZp1) + in(IOX,IOYp1,IOZp1);
02269                                         float a8 = in(IOXp1,IOY,IOZ) + in(IOX,IOYp1,IOZ)+ in(IOX,IOY,IOZp1) 
02270                                                         - in(IOX,IOY,IOZ)- in(IOXp1,IOYp1,IOZ) - in(IOXp1,IOY,IOZp1)
02271                                                         - in(IOX,IOYp1,IOZp1) + in(IOXp1,IOYp1,IOZp1);
02272                                         (*ret)(ix,iy,iz) = a1 + dz*(a4 + a6*dx + (a7 + a8*dx)*dy) + a3*dy + dx*(a2 + a5*dy);    
02273                                 } //ends x loop
02274                         } // ends y loop
02275                 } // ends z loop
02276 
02277                 set_array_offsets(saved_offsets);
02278                 return ret;
02279 
02280         }
02281 }

void EMData::rotate ( float  az,
float  alt,
float  phi 
)

Rotate this image.

DEPRECATED USE EMData::Transform

Parameters:
az Rotation euler angle az in EMAN convention.
alt Rotation euler angle alt in EMAN convention.
phi Rotation euler angle phi in EMAN convention.

Definition at line 895 of file emdata.cpp.

References t, and transform().

00896 {
00897         Dict d("type","eman");
00898         d["az"] = az;
00899         d["alt"] = alt;
00900         d["phi"] = phi;
00901         Transform t(d);
00902         transform(t);
00903 }

void EMData::rotate ( const Transform3D t  ) 

Rotate this image.

DEPRECATED USE EMData::Transform

Parameters:
t Transformation rotation.

Definition at line 907 of file emdata.cpp.

References rotate_translate(), and t.

Referenced by main().

00908 {
00909         cout << "Deprecation warning in EMData::rotate. Please consider using EMData::transform() instead " << endl;
00910         rotate_translate(t);
00911 }

void EMAN::EMData::rotate_180 (  )  [inline]

Fast rotation by 180 degrees.

Square 2D image only.

Exceptions:
ImageFormatException If the image is not square.
ImageDimensionException If the image is not 2D.

Definition at line 3315 of file emdata.h.

void EMData::rotate_translate ( float  az,
float  alt,
float  phi,
float  dx,
float  dy,
float  dz,
float  pdx,
float  pdy,
float  pdz 
)

Rotate then translate the image.

DEPRECATED USE EMData::Transform

Parameters:
az Rotation euler angle az in EMAN convention.
alt Rotation euler angle alt in EMAN convention.
phi Rotation euler angle phi in EMAN convention.
dx Translation distance in x direction.
dy Translation distance in y direction.
dz Translation distance in z direction.
pdx Pretranslation distance in x direction.
pdy Pretranslation distance in y direction.
pdz Pretranslation distance in z direction.

Definition at line 937 of file emdata.cpp.

References rotate_translate(), and t.

00939 {
00940         cout << "Deprecation warning in EMData::rotate_translate. Please consider using EMData::transform() instead " << endl;
00941         Transform3D t(Vec3f(dx, dy, dz), az, alt, phi, Vec3f(pdx,pdy,pdz));
00942         rotate_translate(t);
00943 }

void EMData::rotate_translate ( float  az,
float  alt,
float  phi,
float  dx,
float  dy,
float  dz 
)

Rotate then translate the image.

DEPRECATED USE EMData::Transform

Parameters:
az Rotation euler angle az in EMAN convention.
alt Rotation euler angle alt in EMAN convention.
phi Rotation euler angle phi in EMAN convention.
dx Translation distance in x direction.
dy Translation distance in y direction.
dz Translation distance in z direction.

Definition at line 929 of file emdata.cpp.

References rotate_translate(), and t.

00930 {
00931         cout << "Deprecation warning in EMData::rotate_translate. Please consider using EMData::transform() instead " << endl;
00932         Transform3D t( az, alt, phi,Vec3f(dx, dy, dz));
00933         rotate_translate(t);
00934 }

void EMAN::EMData::rotate_translate ( const Transform t  )  [inline]

Apply a transformation to the image.

DEPRECATED USE EMData::Transform

Parameters:
t transform object that describes the transformation to be applied to the image.

Definition at line 3271 of file emdata.h.

void EMData::rotate_translate ( const Transform3D t  ) 

Rotate then translate the image.

DEPRECATED USE EMData::Transform

Parameters:
t The rotation and translation transformation to be done.

Definition at line 945 of file emdata.cpp.

References all_translation, attr_dict, EMAN::Util::bilinear_interpolate(), EMAN::EMUtil::em_free(), EMAN::EMUtil::em_malloc(), EMAN::Transform3D::EMAN, ENTERFUNC, EXITFUNC, EMAN::EMObject::f, EMAN::Util::fast_floor(), EMAN::Dict::get(), EMAN::Transform3D::get_center(), get_data(), EMAN::Transform3D::get_posttrans(), EMAN::Transform3D::get_rotation(), EMAN::Transform3D::get_scale(), EMAN::Transform3D::inverse(), EMAN::Dict::keys(), nx, nxy, ny, nz, rdata, scale(), scale_pixel(), EMAN::Transform3D::set_scale(), t, EMAN::Util::trilinear_interpolate(), update(), x, and y.

Referenced by rotate(), and rotate_translate().

00946 {
00947         cout << "Deprecation warning in EMData::rotate_translate. Please consider using EMData::transform() instead " << endl;
00948         ENTERFUNC;
00949 
00950 #if EMDATA_EMAN2_DEBUG
00951         std::cout << "start rotate_translate..." << std::endl;
00952 #endif
00953 
00954         float scale       = RA.get_scale();
00955         Vec3f dcenter     = RA.get_center();
00956         Vec3f translation = RA.get_posttrans();
00957         Dict rotation      = RA.get_rotation(Transform3D::EMAN);
00958 //      Transform3D mx = RA;
00959         Transform3D RAInv = RA.inverse(); // We're rotating the coordinate system, not the data
00960 //      RAInv.printme();
00961 #if EMDATA_EMAN2_DEBUG
00962         vector<string> keys = rotation.keys();
00963         vector<string>::const_iterator it;
00964         for(it=keys.begin(); it!=keys.end(); ++it) {
00965 //              std::cout << *it << " : " << rotation[*it] << std::endl;
00966                 std::cout << *it << " : " << (float)rotation.get(*it) << std::endl;
00967         }
00968 #endif
00969         float inv_scale = 1.0f;
00970 
00971         if (scale != 0) {
00972                 inv_scale = 1.0f / scale;
00973         }
00974 
00975         float *src_data = 0;
00976         float *des_data = 0;
00977 
00978         src_data = get_data();
00979         des_data = (float *) EMUtil::em_malloc(nx * ny * nz * sizeof(float));
00980 
00981         if (nz == 1) {
00982                 float x2c =  nx / 2 - dcenter[0] + RAInv[0][3];
00983                 float y2c =  ny / 2 - dcenter[1] + RAInv[1][3];
00984                 float y   = -ny / 2 + dcenter[1]; // changed 0 to 1 in dcenter and below
00985                 for (int j = 0; j < ny; j++, y += 1.0f) {
00986                         float x = -nx / 2 + dcenter[0];
00987                         for (int i = 0; i < nx; i++, x += 1.0f) {
00988                                 float x2 = RAInv[0][0]*x + RAInv[0][1]*y + x2c;
00989                                 float y2 = RAInv[1][0]*x + RAInv[1][1]*y + y2c;
00990 
00991                                 if (x2 < 0 || x2 >= nx || y2 < 0 || y2 >= ny ) {
00992                                         des_data[i + j * nx] = 0; // It may be tempting to set this value to the
00993                                         // mean but in fact this is not a good thing to do. Talk to S.Ludtke about it.
00994                                 }
00995                                 else {
00996                                         int ii = Util::fast_floor(x2);
00997                                         int jj = Util::fast_floor(y2);
00998                                         int k0 = ii + jj * nx;
00999                                         int k1 = k0 + 1;
01000                                         int k2 = k0 + nx;
01001                                         int k3 = k0 + nx + 1;
01002 
01003                                         if (ii == nx - 1) {
01004                                                 k1--;
01005                                                 k3--;
01006                                         }
01007                                         if (jj == ny - 1) {
01008                                                 k2 -= nx;
01009                                                 k3 -= nx;
01010                                         }
01011 
01012                                         float t = x2 - ii;
01013                                         float u = y2 - jj;
01014 
01015                                         des_data[i + j * nx] = Util::bilinear_interpolate(src_data[k0],src_data[k1], src_data[k2], src_data[k3],t,u); // This is essentially basic interpolation
01016                                 }
01017                         }
01018                 }
01019         }
01020         else {
01021 #if EMDATA_EMAN2_DEBUG
01022                 std::cout << "This is the 3D case." << std::endl    ;
01023 #endif
01024 
01025                 Transform3D mx = RA;
01026                 mx.set_scale(inv_scale);
01027 
01028 #if EMDATA_EMAN2_DEBUG
01029 //              std::cout << v4[0] << " " << v4[1]<< " " << v4[2]<< " "
01030 //                      << dcenter2[0]<< " "<< dcenter2[1]<< " "<< dcenter2[2] << std::endl;
01031 #endif
01032 
01033                 int nxy = nx * ny;
01034                 int l = 0;
01035 
01036                 float x2c =  nx / 2 - dcenter[0] + RAInv[0][3];;
01037                 float y2c =  ny / 2 - dcenter[1] + RAInv[1][3];;
01038                 float z2c =  nz / 2 - dcenter[2] + RAInv[2][3];;
01039 
01040                 float z   = -nz / 2 + dcenter[2]; //
01041 
01042                 size_t ii, k0, k1, k2, k3, k4, k5, k6, k7;
01043                 for (int k = 0; k < nz; k++, z += 1.0f) {
01044                         float y   = -ny / 2 + dcenter[1]; //
01045                         for (int j = 0; j < ny; j++,   y += 1.0f) {
01046                                 float x = -nx / 2 + dcenter[0];
01047                                 for (int i = 0; i < nx; i++, l++ ,  x += 1.0f) {
01048                                         float x2 = RAInv[0][0] * x + RAInv[0][1] * y + RAInv[0][2] * z + x2c;
01049                                         float y2 = RAInv[1][0] * x + RAInv[1][1] * y + RAInv[1][2] * z + y2c;
01050                                         float z2 = RAInv[2][0] * x + RAInv[2][1] * y + RAInv[2][2] * z + z2c;
01051 
01052 
01053                                         if (x2 < 0 || y2 < 0 || z2 < 0 ||
01054                                                 x2 >= nx  || y2 >= ny  || z2>= nz ) {
01055                                                 des_data[l] = 0;
01056                                         }
01057                                         else {
01058                                                 int ix = Util::fast_floor(x2);
01059                                                 int iy = Util::fast_floor(y2);
01060                                                 int iz = Util::fast_floor(z2);
01061                                                 float tuvx = x2-ix;
01062                                                 float tuvy = y2-iy;
01063                                                 float tuvz = z2-iz;
01064                                                 ii = ix + iy * nx + iz * nxy;
01065 
01066                                                 k0 = ii;
01067                                                 k1 = k0 + 1;
01068                                                 k2 = k0 + nx;
01069                                                 k3 = k0 + nx+1;
01070                                                 k4 = k0 + nxy;
01071                                                 k5 = k1 + nxy;
01072                                                 k6 = k2 + nxy;
01073                                                 k7 = k3 + nxy;
01074 
01075                                                 if (ix == nx - 1) {
01076                                                         k1--;
01077                                                         k3--;
01078                                                         k5--;
01079                                                         k7--;
01080                                                 }
01081                                                 if (iy == ny - 1) {
01082                                                         k2 -= nx;
01083                                                         k3 -= nx;
01084                                                         k6 -= nx;
01085                                                         k7 -= nx;
01086                                                 }
01087                                                 if (iz == nz - 1) {
01088                                                         k4 -= nxy;
01089                                                         k5 -= nxy;
01090                                                         k6 -= nxy;
01091                                                         k7 -= nxy;
01092                                                 }
01093 
01094                                                 des_data[l] = Util::trilinear_interpolate(src_data[k0],
01095                                                           src_data[k1],
01096                                                           src_data[k2],
01097                                                           src_data[k3],
01098                                                           src_data[k4],
01099                                                           src_data[k5],
01100                                                           src_data[k6],
01101                                                           src_data[k7],
01102                                                           tuvx, tuvy, tuvz);
01103 #if EMDATA_EMAN2_DEBUG
01104                                                 printf(" ix=%d \t iy=%d \t iz=%d \t value=%f \n", ix ,iy, iz, des_data[l] );
01105                                                 std::cout << src_data[ii] << std::endl;
01106 #endif
01107                                         }
01108                                 }
01109                         }
01110                 }
01111         }
01112 
01113         if( rdata )
01114         {
01115                 EMUtil::em_free(rdata);
01116                 rdata = 0;
01117         }
01118         rdata = des_data;
01119 
01120         scale_pixel(inv_scale);
01121 
01122         attr_dict["origin_x"] = (float) attr_dict["origin_x"] * inv_scale;
01123         attr_dict["origin_y"] = (float) attr_dict["origin_y"] * inv_scale;
01124         attr_dict["origin_z"] = (float) attr_dict["origin_z"] * inv_scale;
01125 
01126         update();
01127         all_translation += translation;
01128         EXITFUNC;
01129 }

void EMData::rotate_x ( int  dx  ) 

This performs a translation of each line along x with wraparound.

This is equivalent to a rotation when performed on 'unwrapped' maps.

Parameters:
dx Translation distance align x direction.
Exceptions:
ImageDimensionException If the image is 3D.

Definition at line 1134 of file emdata.cpp.

References data, EMAN::EMUtil::em_malloc(), EMAN::EMUtil::em_memcpy(), ENTERFUNC, EXITFUNC, get_data(), get_ndim(), ImageDimensionException, nx, ny, update(), x, and y.

Referenced by EMAN::RTFExhaustiveAligner::align().

01135 {
01136         ENTERFUNC;
01137 
01138         if (get_ndim() > 2) {
01139                 throw ImageDimensionException("no 3D image");
01140         }
01141 
01142 
01143         size_t row_size = nx * sizeof(float);
01144         float *tmp = (float*)EMUtil::em_malloc(row_size);
01145         float * data = get_data();
01146 
01147         for (int y = 0; y < ny; y++) {
01148                 int y_nx = y * nx;
01149                 for (int x = 0; x < nx; x++) {
01150                         tmp[x] = data[y_nx + (x + dx) % nx];
01151                 }
01152                 EMUtil::em_memcpy(&data[y_nx], tmp, row_size);
01153         }
01154 
01155         update();
01156         if( tmp )
01157         {
01158                 delete[]tmp;
01159                 tmp = 0;
01160         }
01161         EXITFUNC;
01162 }

EMData * EMData::rotavg (  ) 

Create a (1-D) rotationally averaged image.

Exceptions:
ImageDimensionException If 'this' image is 1D.
Returns:
1-D rotationally-averaged image

Definition at line 511 of file emdata_sparx.cpp.

References abs, EMData(), ENTERFUNC, EXITFUNC, get_array_offsets(), ImageDimensionException, LOGERR, max, min, nx, ny, nz, set_array_offsets(), set_size(), sqrt(), to_zero(), and update().

Referenced by rotavg_i().

00511                        {
00512 
00513         int rmax;
00514 
00515         ENTERFUNC;
00516 
00517         if (ny<2 && nz <2) {
00518                 LOGERR("No 1D images.");
00519                 throw ImageDimensionException("No 1D images!");
00520         }
00521         vector<int> saved_offsets = get_array_offsets();
00522         set_array_offsets(-nx/2,-ny/2,-nz/2);
00523 #ifdef _WIN32
00524         //int rmax = _MIN(nx/2 + nx%2, ny/2 + ny%2);
00525         if ( nz == 1 ) {
00526                 rmax = _MIN(nx/2 + nx%2, ny/2 + ny%2);
00527         } else {
00528                 rmax = _MIN(nx/2 + nx%2, _MIN(ny/2 + ny%2, nz/2 + nz%2));
00529         }
00530 #else
00531         //int rmax = std::min(nx/2 + nx%2, ny/2 + ny%2);
00532         if ( nz == 1 ) {
00533                 rmax = std::min(nx/2 + nx%2, ny/2 + ny%2);
00534         } else {
00535                 rmax = std::min(nx/2 + nx%2, std::min(ny/2 + ny%2, nz/2 + nz%2));
00536         }
00537 #endif  //_WIN32
00538         EMData* ret = new EMData();
00539         ret->set_size(rmax+1, 1, 1);
00540         ret->to_zero();
00541         vector<float> count(rmax+1);
00542         for (int k = -nz/2; k < nz/2 + nz%2; k++) {
00543                 if (abs(k) > rmax) continue;
00544                 for (int j = -ny/2; j < ny/2 + ny%2; j++) {
00545                         if (abs(j) > rmax) continue;
00546                         for (int i = -nx/2; i < nx/2 + nx%2; i++) {
00547                                 float r = std::sqrt(float(k*k) + float(j*j) + float(i*i));
00548                                 int ir = int(r);
00549                                 if (ir >= rmax) continue;
00550                                 float frac = r - float(ir);
00551                                 (*ret)(ir) += (*this)(i,j,k)*(1.0f - frac);
00552                                 (*ret)(ir+1) += (*this)(i,j,k)*frac;
00553                                 count[ir] += 1.0f - frac;
00554                                 count[ir+1] += frac;
00555                         }
00556                 }
00557         }
00558         for (int ir = 0; ir <= rmax; ir++) {
00559         #ifdef _WIN32
00560                 (*ret)(ir) /= _MAX(count[ir],1.0f);
00561         #else
00562                 (*ret)(ir) /= std::max(count[ir],1.0f);
00563         #endif  //_WIN32
00564         }
00565 
00566         set_array_offsets(saved_offsets);
00567         ret->update();
00568         EXITFUNC;
00569         return ret;
00570 }

EMData * EMData::rotavg_i (  ) 

Create a 2-D or 3-D rotationally averaged image.

Exceptions:
ImageDimensionException If 'this' image is 1D.
Returns:
2-D or 3-D rotationally-averaged image

Definition at line 572 of file emdata_sparx.cpp.

References abs, EMData(), ENTERFUNC, EXITFUNC, ImageDimensionException, LOGERR, min, nx, ny, nz, rotavg(), set_array_offsets(), set_size(), sqrt(), to_zero(), and update().

00572                          {
00573 
00574         int rmax;
00575         ENTERFUNC;
00576         if ( ny == 1 && nz == 1 ) {
00577                 LOGERR("Input image must be 2-D or 3-D!");
00578                 throw ImageDimensionException("Input image must be 2-D or 3-D!");
00579         }
00580 
00581         EMData* avg1D  = new EMData();
00582         EMData* result = new EMData();
00583 
00584         result->set_size(nx,ny,nz);
00585         result->to_zero();
00586         result->set_array_offsets(-nx/2, -ny/2, -nz/2);
00587 
00588         if ( nz == 1 ) {
00589 #ifdef  _WIN32
00590                 rmax = _cpp_min(nx/2 + nx%2, ny/2 + ny%2);
00591         } else {
00592                 rmax = _cpp_min(nx/2 + nx%2, _cpp_min(ny/2 + ny%2, nz/2 + nz%2));
00593 #else
00594                 rmax = std::min(nx/2 + nx%2, ny/2 + ny%2);
00595         } else {
00596                 rmax = std::min(nx/2 + nx%2, std::min(ny/2 + ny%2, nz/2 + nz%2));
00597 #endif  //_WIN32
00598         }
00599 
00600         avg1D = rotavg();
00601         float padded_value = 0.0, r;
00602         int i, j, k, ir;
00603         long int number_of_pixels = 0;
00604         for ( k = -nz/2; k < nz/2 + nz%2; k++) {
00605                 if (abs(k) > rmax) continue;
00606                 for ( j = -ny/2; j < ny/2 + ny%2; j++) {
00607                         if (abs(j) > rmax) continue;
00608                         for (i = -nx/2; i < nx/2 + nx%2; i++) {
00609                                 r = std::sqrt(float(k*k) + float(j*j) + float(i*i));
00610                                 ir = int(r);
00611                                 if (ir > rmax || ir < rmax-2 ) continue ;
00612                                 else {
00613                                         padded_value += (*avg1D)(ir) ;
00614                                         number_of_pixels++ ;
00615                                 }
00616                         }
00617                 }
00618         }
00619         padded_value /= number_of_pixels;
00620         for ( k = -nz/2; k < nz/2 + nz%2; k++) {
00621                 for ( j = -ny/2; j < ny/2 + ny%2; j++) {
00622                         for ( i = -nx/2; i < nx/2 + nx%2; i++)  {
00623                                 r = std::sqrt(float(k*k) + float(j*j) + float(i*i));
00624                                 ir = int(r);
00625                                 if (ir >= rmax) (*result)(i,j,k) = padded_value ;
00626                                 else            (*result)(i,j,k) = (*avg1D)(ir)+((*avg1D)(ir+1)-(*avg1D)(ir))*(r - float(ir));
00627 
00628                         }
00629                 }
00630         }
00631         result->update();
00632         result->set_array_offsets(0,0,0);
00633         EXITFUNC;
00634         return result;
00635 }

void EMData::save_byteorder_to_dict ( ImageIO imageio  )  [private]

Definition at line 3945 of file emdata.cpp.

References attr_dict, EMAN::ByteOrder::is_host_big_endian(), and EMAN::ImageIO::is_image_big_endian().

Referenced by read_image().

03946 {
03947         string image_endian = "ImageEndian";
03948         string host_endian = "HostEndian";
03949 
03950         if (imageio->is_image_big_endian()) {
03951                 attr_dict[image_endian] = "big";
03952         }
03953         else {
03954                 attr_dict[image_endian] = "little";
03955         }
03956 
03957         if (ByteOrder::is_host_big_endian()) {
03958                 attr_dict[host_endian] = "big";
03959         }
03960         else {
03961                 attr_dict[host_endian] = "little";
03962         }
03963 }

void EMData::scale ( float  scale_factor  ) 

scale the image by a factor.

Parameters:
scale_factor scale factor.

Definition at line 822 of file emdata.cpp.

References ENTERFUNC, EXITFUNC, t, and transform().

Referenced by rot_scale_conv(), rot_scale_conv7(), rot_scale_conv_new(), rot_scale_conv_new_background(), and rotate_translate().

00823 {
00824         ENTERFUNC;
00825         Transform t;
00826         t.set_scale(s);
00827         transform(t);
00828         EXITFUNC;
00829 }

void EMData::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 make this function public for access from the Processors (David Woolford).

Author:
Unknown

Definition at line 1145 of file emdata_metadata.cpp.

References attr_dict, and EMAN::Dict::has_key().

Referenced by EMAN::MeanShrinkProcessor::accrue_mean(), EMAN::MeanShrinkProcessor::accrue_mean_one_p_five(), EMAN::MedianShrinkProcessor::accrue_median(), EMAN::TransformProcessor::process(), EMAN::FFTResampleProcessor::process(), EMAN::TransformProcessor::process_inplace(), EMAN::FFTResampleProcessor::process_inplace(), and rotate_translate().

01146 {
01147         attr_dict["apix_x"] = ((float) attr_dict["apix_x"]) * scale;
01148         attr_dict["apix_y"] = ((float) attr_dict["apix_y"]) * scale;
01149         attr_dict["apix_z"] = ((float) attr_dict["apix_z"]) * scale;
01150         if (attr_dict.has_key("ctf")) {
01151                 Ctf *ctf=(Ctf *)attr_dict["ctf"];
01152                 ctf->apix*=scale;
01153                 attr_dict["ctf"]=ctf;
01154                 if(ctf) {delete ctf; ctf=0;}
01155         }
01156 }

void EMAN::EMData::set_array_offsets ( vector< int >  offsets  )  [inline]

Definition at line 2271 of file emdata.h.

void EMAN::EMData::set_array_offsets ( const int  xoff_ = 0,
const int  yoff_ = 0,
const int  zoff_ = 0 
) [inline]

Set the array offsets.

Definition at line 2265 of file emdata.h.

Referenced by EMAN::nnSSNR_ctfReconstructor::buildFFTVolume(), EMAN::nn4_ctfReconstructor::buildFFTVolume(), EMAN::nnSSNR_Reconstructor::buildFFTVolume(), EMAN::nn4Reconstructor::buildFFTVolume(), EMAN::nnSSNR_ctfReconstructor::buildNorm2Volume(), EMAN::nnSSNR_Reconstructor::buildNorm2Volume(), EMAN::nnSSNR_ctfReconstructor::buildNorm3Volume(), EMAN::nnSSNR_ctfReconstructor::buildNormVolume(), EMAN::nn4_ctfReconstructor::buildNormVolume(), EMAN::nnSSNR_Reconstructor::buildNormVolume(), EMAN::nn4Reconstructor::buildNormVolume(), center_origin_fft(), EMAN::QuadMinDotCmp::cmp(), depad(), depad_corner(), divkbsinh(), downsample(), EMAN::Processor::EMFourierFilterFunc(), extract_plane(), extractline(), fft_shuffle(), filter_by_image(), EMAN::nn4_ctfReconstructor::finish(), EMAN::nn4Reconstructor::finish(), fouriergridrot2d(), fouriergridrot_shift2d(), EMAN::fourierproduct(), getconvpt2d_kbi0(), mult_radial(), nn(), nn_ctf(), nn_ctf_applied(), nn_SSNR(), nn_SSNR_ctf(), norm_pad(), EMAN::Util::pack_complex_to_real(), EMAN::periodogram(), replace_amplitudes(), rot_scale_conv(), rot_scale_conv7(), rot_scale_conv_new(), rot_scale_conv_new_background(), rot_scale_trans(), rot_scale_trans2D(), rot_scale_trans2D_background(), rot_scale_trans_background(), rotavg(), rotavg_i(), EMAN::rsconvolution(), symplane0(), symplane0_ctf(), symplane1(), and symplane2().

void EMData::set_attr ( const string &  key,
EMObject  val 
)

Set a header attribute's value.

Parameters:
key The header attribute name.
val The attribute value.

Definition at line 1083 of file emdata_metadata.cpp.

References attr_dict, LOGWARN, nx, ny, nz, and set_size().

Referenced by ali3d_d(), EMAN::RT3DSphereAligner::align(), EMAN::RT3DGridAligner::align(), EMAN::Refine3DAligner::align(), EMAN::RefineAligner::align(), EMAN::RTFSlowExhaustiveAligner::align(), EMAN::RTFExhaustiveAligner::align(), EMAN::RotateFlipAligner::align(), EMAN::RotateTranslateFlipAligner::align(), EMAN::RotateTranslateAligner::align(), EMAN::RotatePrecenterAligner::align(), EMAN::RotationalAligner::align(), EMAN::TranslationalAligner::align(), EMAN::RotationalAligner::align_180_ambiguous(), EMAN::PCAlarge::analyze(), EMAN::PCAsmall::analyze(), EMAN::nnSSNR_ctfReconstructor::buildFFTVolume(), EMAN::nn4_ctfReconstructor::buildFFTVolume(), EMAN::nnSSNR_Reconstructor::buildFFTVolume(), EMAN::nn4Reconstructor::buildFFTVolume(), calc_mutual_correlation(), EMAN::FRCCmp::cmp(), EMAN::PhaseCmp::cmp(), EMAN::OptVarianceCmp::cmp(), EMAN::SqEuclideanCmp::cmp(), EMAN::SetSFProcessor::create_radial_func(), depad(), depad_corner(), EMAN::FourierReconstructor::determine_slice_agreement(), EMAN::FourierReconstructor::do_compare_slice_work(), filter_by_image(), EMAN::CtfCWautoAverager::finish(), FourInterpol(), FourTruncate(), EMAN::file_store::get_image(), EMAN::TestUtil::make_image_file_by_mode(), EMAN::padfft_slice(), EMAN::PointArray::pdb2mrc_by_summation(), EMAN::NewFourierProcessor::preprocess(), EMAN::LowpassAutoBProcessor::preprocess(), EMAN::HighpassAutoPeakProcessor::preprocess(), EMAN::HighpassFourierProcessor::preprocess(), EMAN::LowpassFourierProcessor::preprocess(), EMAN::Reconstructor::preprocess_slice(), EMAN::FourierReconstructor::preprocess_slice(), EMAN::KmeansSegmentProcessor::process(), EMAN::ACFCenterProcessor::process_inplace(), EMAN::PhaseToMassCenterProcessor::process_inplace(), EMAN::ToMassCenterProcessor::process_inplace(), EMAN::NormalizeToLeastSquareProcessor::process_inplace(), EMAN::ChaoProjector::project3d(), EMAN::FourierGriddingProjector::project3d(), EMAN::GaussFFTProjector::project3d(), replace_amplitudes(), ri2inten(), wustl_mm::SkeletonMaker::VolumeData::SetOrigin(), wustl_mm::SkeletonMaker::VolumeData::SetSpacing(), EMAN::FourierReconstructor::setup(), and EMAN::FourierReconstructor::setup_seed().

01084 {
01085         if( key == "nx" && nx != (int)val) { set_size((int)val,ny,nz); return; }
01086         if( key == "ny" && ny != (int)val) { set_size(nx,(int)val,nz); return; }
01087         if( key == "nz" && nz != (int)val) { set_size(nx,ny,(int)val); return; }
01088 
01089         /* Ignore 'read only' attribute. */
01090         if(key == "sigma" ||
01091                 key == "sigma_nonzero" ||
01092                 key == "square_sum" ||
01093                 key == "maximum" ||
01094                 key == "minimum" ||
01095                 key == "mean" ||
01096                 key == "mean_nonzero" )
01097         {
01098                 LOGWARN("Ignore setting read only attribute %s", key.c_str());
01099                 return;
01100         }
01101 
01102         attr_dict[key] = val;
01103 
01104 
01105 
01106 }

void EMData::set_attr_dict ( const Dict new_dict  ) 

Merge the new values with the existing dictionary.

Parameters:
new_dict The new attribute dictionary.

Definition at line 1035 of file emdata_metadata.cpp.

References EMAN::Dict::has_key(), EMAN::Dict::keys(), nx, ny, nz, and set_size().

Referenced by ali3d_d().

01036 {
01037         /*set nx, ny nz may resize the image*/
01038         // This wasn't supposed to 'clip' the image, but just redefine the size --steve
01039         if( ( new_dict.has_key("nx") && nx!=(int)new_dict["nx"] )
01040                 || ( new_dict.has_key("ny") && ny!=(int)new_dict["ny"] )
01041                 || ( new_dict.has_key("nz") && nz!=(int)new_dict["nz"] ) ) {
01042 
01043                 int newx, newy, newz;
01044                 newx = new_dict.has_key("nx") ? (int)new_dict["nx"] : nx;
01045                 newy = new_dict.has_key("ny") ? (int)new_dict["ny"] : ny;
01046                 newz = new_dict.has_key("nz") ? (int)new_dict["nz"] : nz;
01047 
01048                 set_size(newx,newy,newz);
01049 
01050 //              EMData * new_image = get_clip(Region((nx-newx)/2, (ny-newy)/2, (nz=newz)/2, newx, newy, newz));
01051 //              if(new_image) {
01052 //                      this->operator=(*new_image);
01053 //                      delete new_image;
01054 //                      new_image = 0;
01055 //              }
01056         }
01057 
01058         vector<string> new_keys = new_dict.keys();
01059         vector<string>::const_iterator it;
01060         for(it = new_keys.begin(); it!=new_keys.end(); ++it) {
01061                 this->set_attr(*it, new_dict[*it]);
01062         }
01063 }

void EMData::set_attr_dict_explicit ( const Dict new_dict  )  [private]

Make the attributes of this EMData exactly equal to the argument dictionary Originally introduced because set_attr_dict does automatic resizing, which is undersirable in some circumstances.

Parameters:
new_dict The attribute dictionary that will become this image's attribute dictionary.

Definition at line 1065 of file emdata_metadata.cpp.

References attr_dict.

01066 {
01067         attr_dict = new_dict;
01068 }

void EMData::set_attr_python ( const string &  key,
EMObject  val 
)

Set a header attribute's value from Python.

Parameters:
key The header attribute name.
val The attribute value.

Definition at line 1108 of file emdata_metadata.cpp.

References attr_dict, copy(), EMAN::EMObject::EMDATA, LOGWARN, nx, ny, nz, set_size(), t, EMAN::EMObject::TRANSFORM, and v.

01109 {
01110         if( key == "nx" && nx != (int)val) { set_size((int)val,ny,nz); return; }
01111         if( key == "ny" && ny != (int)val) { set_size(nx,(int)val,nz); return; }
01112         if( key == "nz" && nz != (int)val) { set_size(nx,ny,(int)val); return; }
01113 
01114         /* Ignore 'read only' attribute. */
01115         if(key == "sigma" ||
01116                   key == "sigma_nonzero" ||
01117                   key == "square_sum" ||
01118                   key == "maximum" ||
01119                   key == "minimum" ||
01120                   key == "mean" ||
01121                   key == "mean_nonzero" )
01122         {
01123                 LOGWARN("Ignore setting read only attribute %s", key.c_str());
01124                 return;
01125         }
01126 
01127         EMObject::ObjectType argtype = val.get_type();
01128         if (argtype == EMObject::EMDATA) {
01129                 EMData* e = (EMData*) val;
01130                 e = e->copy();
01131                 EMObject v(e);
01132                 attr_dict[key] = v;
01133         }
01134         else if (argtype == EMObject::TRANSFORM) {
01135                 Transform* t = new Transform(*((Transform*) val));
01136                 EMObject v(t);
01137                 attr_dict[key] = v;
01138                 delete t; t=0;
01139         } else {
01140                 attr_dict[key] = val;
01141         }
01142 
01143 }

void EMAN::EMData::set_changecount ( int  c  )  [inline]

Definition at line 1203 of file emdata.h.

void EMData::set_col ( const EMData data,
int  col_index 
)

Set one column of a 2D image.

Parameters:
data The column image data.
col_index Index of the column.
Exceptions:
ImageDimensionException If this image is not 2D.

Definition at line 717 of file emdata_core.cpp.

References ENTERFUNC, EXITFUNC, get_data(), get_ndim(), ImageDimensionException, nx, ny, and update().

00718 {
00719         ENTERFUNC;
00720 
00721         if (get_ndim() != 2) {
00722                 throw ImageDimensionException("2D image only");
00723         }
00724         if (d->get_ndim() != 1) {
00725                 throw ImageDimensionException("1D image only");
00726         }
00727 
00728         float *dst = get_data();
00729         float *src = d->get_data();
00730 
00731         for (int i = 0; i < ny; i++) {
00732                 dst[i * nx + n] = src[i];
00733         }
00734 
00735         update();
00736         EXITFUNC;
00737 }

void EMAN::EMData::set_complex ( bool  is_complex  )  [inline]

Mark this image as a complex image.

Parameters:
is_complex If true, a complex image. If false, a real image.

Definition at line 995 of file emdata.h.

Referenced by absi(), EMAN::Util::addn_img(), amplitude(), EMAN::ChaoProjector::backproject3d(), EMAN::nnSSNR_ctfReconstructor::buildFFTVolume(), EMAN::nn4_ctfReconstructor::buildFFTVolume(), EMAN::nnSSNR_Reconstructor::buildFFTVolume(), EMAN::nn4Reconstructor::buildFFTVolume(), EMAN::Util::ctf_img(), depad(), depad_corner(), EMAN::Util::divn_img(), do_fft(), do_fft_inplace(), do_ift(), do_ift_inplace(), extract_plane(), extractline(), FH2F(), EMAN::nnSSNR_ctfReconstructor::finish(), EMAN::nnSSNR_Reconstructor::finish(), Four_ds(), Four_shuf_ds_cen_us(), FourInterpol(), FourTruncate(), get_fft_amplitude(), get_fft_amplitude2D(), get_fft_phase(), imag(), EMAN::Util::madn_scalar(), make_footprint(), make_rotational_footprint_cmc(), make_rotational_footprint_e1(), EMAN::Util::muln_img(), EMAN::Util::mult_scalar(), phase(), EMAN::TestImageFourierNoiseProfile::process_inplace(), EMAN::TestImageFourierNoiseGaussian::process_inplace(), EMAN::ChaoProjector::project3d(), EMAN::GaussFFTProjector::project3d(), read_image(), real(), real2complex(), real2FH(), EMAN::WienerFourierReconstructor::setup(), EMAN::FourierReconstructor::setup(), EMAN::FourierReconstructorSimple2D::setup(), EMAN::Util::subn_img(), and EMAN::Util::TwoDTestFunc().

01001       : set ts=4 noet nospell: */
01002 set ts=4 noet nospell: */

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:
x x coordinate
y y coordinate
z z coordinate
val complex<float> value to set
Returns:
The complex pixel at x,y

Definition at line 173 of file emdata_core.cpp.

References abs, nx, nxy, ny, nz, and rdata.

00173                                                                                                {
00174 if (abs(x)>=nx/2 || abs(y)>ny/2 || abs(z)>nz/2) return;
00175 //if (x==0 && (y!=0 || z!=0)) set_complex_at(0,-y,-z,conj(val));
00176 
00177 // for x=0, we need to insert the value in 2 places
00178 // complex conjugate insertion. Removed due to ambiguity with returned index
00179 /*if (x==0 && (y!=0 || z!=0)) {
00180         size_t idx=(y<=0?-y:ny-y)*nx+(z<=0?-z:nz-z)*nx*ny;
00181         rdata[idx]=(float)val.real();
00182         rdata[idx+1]=(float)-val.imag();
00183 }*/
00184 
00185 size_t idx;
00186 if (x<0) {
00187         idx=-x*2+(y<=0?-y:ny-y)*(size_t)nx+(z<=0?-z:nz-z)*(size_t)nxy;
00188         rdata[idx]=(float)val.real();
00189         rdata[idx+1]=-(float)val.imag();
00190         return;
00191 }
00192 
00193 idx=x*2+(y<0?ny+y:y)*(size_t)nx+(z<0?nz+z:z)*(size_t)nxy;
00194 rdata[idx]=(float)val.real();
00195 rdata[idx+1]=(float)val.imag();
00196 
00197 return;
00198 }

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:
x x coordinate
y y coordinate
val complex<float> value to set
Returns:
The complex pixel at x,y

Definition at line 164 of file emdata_core.cpp.

References abs, nx, ny, and rdata.

00164                                                                                   {
00165         if (abs(x)>=nx/2 || abs(y)>ny/2) return;
00166         if (x>=0 && y>=0) { rdata[ x*2+y*nx]=val.real(); rdata[x*2+y*nx+1]=val.imag(); }
00167         else if (x>0 && y<0) { rdata[ x*2+(ny+y)*nx]=val.real(); rdata[x*2+(ny+y)*nx+1]=val.imag(); }
00168         else if (x<0 && y>0) { rdata[-x*2+(ny-y)*nx]=val.real(); rdata[-x*2+(ny-y)*nx+1]=-val.imag(); }
00169         else { rdata[-x*2-y*nx]=val.real(); rdata[-x*2+-y*nx+1]=-val.imag(); }
00170         return;
00171 }

void EMAN::EMData::set_complex_size ( int  nx,
int  ny = 1,
int  nz = 1 
) [inline]

Resize 'this' complex image.

Parameters:
nx x size of this image.
ny y size of this image.
nz z size of this image.

Definition at line 618 of file emdata.h.

00749                                           {

void EMAN::EMData::set_complex_x ( bool  is_complex_x  )  [inline]

Marks this image a 1D FFT image in X direction.

Parameters:
is_complex_x If true, a 1D FFT image in X direction; If false, not such an image.

Definition at line 1030 of file emdata.h.

Referenced by absi(), amplitude(), depad(), depad_corner(), do_fft(), do_fft_inplace(), do_ift(), do_ift_inplace(), FH2F(), get_fft_amplitude(), get_fft_phase(), imag(), phase(), real(), real2complex(), and real2FH().

void EMData::set_ctf ( Ctf ctf  ) 

Set the CTF parameter of this image.

Parameters:
ctf The CTF parameter object.

Definition at line 682 of file emdata_metadata.cpp.

References attr_dict, ENTERFUNC, EXITFUNC, and EMAN::Ctf::to_vector().

00683 {
00684         ENTERFUNC;
00685 
00686         vector<float> vctf = new_ctf->to_vector();
00687         attr_dict["ctf"] = vctf;
00688 
00689         EXITFUNC;
00690 }

void EMAN::EMData::set_data ( float *  data,
const int  x,
const int  y,
const int  z 
) [inline]

Set the data explicitly data pointer must be allocated using malloc!

Parameters:
data a pointer to the pixel data which is stored in memory. Takes possession
x the number of pixels in the x direction
y the number of pixels in the y direction
z the number of pixels in the z direction

Definition at line 347 of file emdata.h.

Referenced by wustl_mm::SkeletonMaker::VolumeData::Pad(), EMAN::TransformProcessor::process_inplace(), and EMAN::TransposeProcessor::process_inplace().

00380                                    : an algorithm that transforms an original

void EMData::set_data_pickle ( std::string  vf  ) 

Definition at line 1172 of file emdata_metadata.cpp.

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

01173 {
01174 //      if (rdata) printf("rdata exists\n");
01175 //      rdata = (float *)malloc(nx*ny*nz*sizeof(float));
01176 //      std::copy(vf.begin(), vf.end(), rdata);
01177         EMUtil::em_memcpy(get_data(),vf.data(),nx*ny*nz*sizeof(float));
01178 
01179 }

void EMAN::EMData::set_fftodd ( bool  is_fftodd  )  [inline]

Mark this image as having (real-space) odd nx.

Parameters:
is_fftodd If true, mark as nx odd; If false, mark as nx not odd.

Definition at line 1165 of file emdata.h.

Referenced by EMAN::Util::addn_img(), EMAN::nnSSNR_ctfReconstructor::buildFFTVolume(), EMAN::nnSSNR_Reconstructor::buildFFTVolume(), EMAN::nn4Reconstructor::buildFFTVolume(), EMAN::Util::ctf_img(), depad(), depad_corner(), EMAN::Util::divn_img(), do_fft(), do_fft_inplace(), do_ift(), extract_plane(), extractline(), EMAN::FFTResampleProcessor::fft_resample(), FH2F(), filter_by_image(), EMAN::nnSSNR_ctfReconstructor::finish(), EMAN::nnSSNR_Reconstructor::finish(), Four_ds(), Four_shuf_ds_cen_us(), FourInterpol(), FourTruncate(), EMAN::Util::madn_scalar(), EMAN::Util::muln_img(), EMAN::Util::mult_scalar(), EMAN::TestImageFourierNoiseProfile::process_inplace(), EMAN::TestImageFourierNoiseGaussian::process_inplace(), read_image(), real2FH(), replace_amplitudes(), EMAN::FourierReconstructor::setup(), EMAN::FourierReconstructorSimple2D::setup(), EMAN::Util::subn_img(), and EMAN::Util::TwoDTestFunc().

void EMAN::EMData::set_fftpad ( bool  is_fftpadded  )  [inline]

Mark this image as already extended along x for ffts.

Parameters:
is_fftpadded If true, mark as padded along x; If false, mark as not padded along x.

Definition at line 1133 of file emdata.h.

Referenced by EMAN::nnSSNR_ctfReconstructor::buildFFTVolume(), EMAN::nn4_ctfReconstructor::buildFFTVolume(), EMAN::nnSSNR_Reconstructor::buildFFTVolume(), EMAN::nn4Reconstructor::buildFFTVolume(), depad(), depad_corner(), do_fft(), do_fft_inplace(), do_ift(), do_ift_inplace(), extract_plane(), extractline(), filter_by_image(), EMAN::nnSSNR_ctfReconstructor::finish(), EMAN::nnSSNR_Reconstructor::finish(), FourInterpol(), FourTruncate(), EMAN::TestImageFourierNoiseProfile::process_inplace(), EMAN::TestImageFourierNoiseGaussian::process_inplace(), read_image(), and replace_amplitudes().

void EMAN::EMData::set_FH ( bool  is_FH  )  [inline]

Mark this complex image as a FH image.

Parameters:
is_FH If true, a FH image. If false, not a FH image.

Definition at line 978 of file emdata.h.

Referenced by FH2F(), and real2FH().

00988         {

void EMAN::EMData::set_flags ( int  f  )  [inline]

Definition at line 1193 of file emdata.h.

void EMAN::EMData::set_flipped ( bool  is_flipped  )  [inline]

Mark this image as flipped.

Parameters:
is_flipped If true, mark this image as flipped; If false, mark this image as not flipped.

Definition at line 1065 of file emdata.h.

void EMAN::EMData::set_nxc ( int  nxc  )  [inline]

Set the number of complex elements along x.

Parameters:
nxc is the number of complex elements along x.

Definition at line 1179 of file emdata.h.

Referenced by EMAN::nnSSNR_ctfReconstructor::buildFFTVolume(), EMAN::nn4_ctfReconstructor::buildFFTVolume(), EMAN::nnSSNR_Reconstructor::buildFFTVolume(), EMAN::nn4Reconstructor::buildFFTVolume(), EMAN::nnSSNR_ctfReconstructor::finish(), and EMAN::nnSSNR_Reconstructor::finish().

void EMAN::EMData::set_path ( const string &  new_path  )  [inline]

Set the path.

Parameters:
new_path The new path.

Definition at line 626 of file emdata.h.

Referenced by calc_mutual_correlation(), and get_clip().

00749                                           {

void EMAN::EMData::set_pathnum ( int  n  )  [inline]

Set the number of paths.

Parameters:
n The number of paths.

Definition at line 635 of file emdata.h.

Referenced by get_clip().

00749                                           {

void EMAN::EMData::set_ri ( bool  is_ri  )  [inline]

Mark this image as a real/imaginary format complex image.

Parameters:
is_ri If true, mark as real/imaginary format; If false, mark as amp/phase format.

Definition at line 1100 of file emdata.h.

Referenced by ap2ri(), EMAN::ChaoProjector::backproject3d(), EMAN::nnSSNR_ctfReconstructor::buildFFTVolume(), EMAN::nn4_ctfReconstructor::buildFFTVolume(), EMAN::nnSSNR_Reconstructor::buildFFTVolume(), EMAN::nn4Reconstructor::buildFFTVolume(), EMAN::Util::ctf_img(), do_fft(), do_fft_inplace(), do_ift(), do_ift_inplace(), extract_plane(), extractline(), FH2F(), filter_by_image(), EMAN::nnSSNR_ctfReconstructor::finish(), EMAN::nnSSNR_Reconstructor::finish(), Four_ds(), Four_shuf_ds_cen_us(), FourInterpol(), FourTruncate(), get_fft_amplitude(), get_fft_amplitude2D(), get_fft_phase(), EMAN::BinarizeFourierProcessor::process_inplace(), EMAN::ChaoProjector::project3d(), EMAN::GaussFFTProjector::project3d(), read_image(), real2complex(), real2FH(), replace_amplitudes(), ri2ap(), EMAN::WienerFourierReconstructor::setup(), EMAN::FourierReconstructor::setup(), EMAN::FourierReconstructorSimple2D::setup(), to_one(), to_zero(), and EMAN::Util::TwoDTestFunc().

void EMAN::EMData::set_rotation ( const Transform3D t3d  )  [inline]

Define the 3D orientation of this particle Orientation information is extracted from a Transform3D object and stored internally in EMAN (az,alt,phi) format.

Parameters:
t3d a Transform3D object containing the particle orientation

Definition at line 581 of file emdata.h.

00749                                           {

void EMAN::EMData::set_rotation ( float  az,
float  alt,
float  phi 
) [inline]

Define the 3D orientation of this particle, also used to indicate relative rotations for reconstructions.

Parameters:
az 'az' Euler angle in EMAN convention.
alt 'alt' Euler angle in EMAN convention.
phi 'phi' Euler angle in EMAN convention.

Definition at line 567 of file emdata.h.

00749                                           {

void EMData::set_row ( const EMData data,
int  row_index 
)

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

Parameters:
data The row image data.
row_index Index of the row.
Exceptions:
ImageDimensionException If this image is 3D.

Definition at line 676 of file emdata_core.cpp.

References ENTERFUNC, EXITFUNC, get_data(), get_ndim(), ImageDimensionException, nx, and update().

00677 {
00678         ENTERFUNC;
00679 
00680         if (get_ndim() > 2) {
00681                 throw ImageDimensionException("1D/2D image only");
00682         }
00683         if (d->get_ndim() != 1) {
00684                 throw ImageDimensionException("1D image only");
00685         }
00686 
00687         float *dst = get_data();
00688         float *src = d->get_data();
00689         memcpy(dst + nx * row_index, src, nx * sizeof(float));
00690         update();
00691         EXITFUNC;
00692 }

void EMAN::EMData::set_shuffled ( bool  is_shuffled  )  [inline]

Mark this image as a shuffled image.

Parameters:
is_shuffled If true, a shuffled image. If false, not a shuffled image.

Definition at line 960 of file emdata.h.

Referenced by extract_plane(), fft_shuffle(), FH2F(), EMAN::FourierToCenterProcessor::process_inplace(), EMAN::FourierToCornerProcessor::process_inplace(), and EMAN::Util::TwoDTestFunc().

void EMData::set_size ( int  nx,
int  ny = 1,
int  nz = 1 
)

Resize this EMData's main board memory pointer.

Parameters:
nx x size of this image.
ny y size of this image.
nz z size of this image. $
Exceptions:
BadAllocException if memory allocation returns a null pointer

Definition at line 709 of file emdata_metadata.cpp.

References BadAllocException, EMAN::EMUtil::em_free(), EMAN::EMUtil::em_malloc(), EMAN::EMUtil::em_memset(), EMAN::EMUtil::em_realloc(), ENTERFUNC, EXITFUNC, get_data(), InvalidValueException, nx, nxy, nxyz, ny, nz, rdata, supp, and update().

Referenced by absi(), EMAN::CtfAverager::add_image(), EMAN::IterationAverager::add_image(), EMAN::ImageAverager::add_image(), ali3d_d(), amplitude(), EMAN::varimax::analyze(), EMAN::PCAlarge::analyze(), EMAN::PCAsmall::analyze(), EMAN::PawelProjector::backproject3d(), EMAN::ChaoProjector::backproject3d(), bispecRotTransInvN(), EMAN::nnSSNR_ctfReconstructor::buildFFTVolume(), EMAN::nn4_ctfReconstructor::buildFFTVolume(), EMAN::nnSSNR_Reconstructor::buildFFTVolume(), EMAN::nn4Reconstructor::buildFFTVolume(), EMAN::nnSSNR_ctfReconstructor::buildNorm2Volume(), EMAN::nnSSNR_Reconstructor::buildNorm2Volume(), EMAN::nnSSNR_ctfReconstructor::buildNorm3Volume(), EMAN::nnSSNR_ctfReconstructor::buildNormVolume(), EMAN::nn4_ctfReconstructor::buildNormVolume(), EMAN::nnSSNR_Reconstructor::buildNormVolume(), EMAN::nn4Reconstructor::buildNormVolume(), calc_ccfx(), clip_inplace(), common_lines(), common_lines_real(), EMAN::Util::compress_image_mask(), copy_head(), EMAN::Util::Crosrng_msg(), EMAN::Util::Crosrng_msg_m(), EMAN::Util::Crosrng_msg_s(), EMAN::Util::ctf_img(), EMAN::Util::decimate(), depad(), depad_corner(), do_fft(), do_fft_inplace(), do_ift(), do_ift_inplace(), do_radon(), downsample(), EMData(), extract_plane(), extractline(), FH2F(), EMAN::filt_dilation_(), EMAN::filt_erosion_(), EMAN::filt_median_(), EMAN::nnSSNR_ctfReconstructor::finish(), EMAN::nnSSNR_Reconstructor::finish(), Four_ds(), Four_shuf_ds_cen_us(), FourInterpol(), FourTruncate(), EMAN::Util::get_biggest_cluster(), get_circle_mean(), get_clip(), get_col(), get_fft_amplitude(), get_fft_amplitude2D(), get_fft_phase(), EMAN::file_store::get_image(), EMAN::newfile_store::get_image(), get_rotated_clip(), get_row(), EMAN::Util::get_slice(), get_top_half(), EMAN::Util::im_diff(), imag(), EMAN::BackProjectionReconstructor::insert_slice(), little_big_dot(), main(), EMAN::TestUtil::make_image_file_by_mode(), EMAN::EMUtil::make_image_median(), make_rotational_footprint_cmc(), make_rotational_footprint_e1(), EMAN::Util::move_points(), EMAN::Util::multiref_peaks_ali2d(), EMAN::Util::multiref_peaks_compress_ali2d(), operator=(), EMAN::Util::pack_complex_to_real(), EMAN::Util::pad(), EMAN::PointArray::pdb2mrc_by_summation(), EMAN::periodogram(), phase(), EMAN::Util::Polar2D(), EMAN::Util::Polar2Dm(), EMAN::Util::Polar2Dmi(), EMAN::DirectionalSumProcessor::process(), EMAN::BooleanShrinkProcessor::process(), EMAN::MeanShrinkProcessor::process(), EMAN::MedianShrinkProcessor::process(), EMAN::ZGradientProcessor::process_inplace(), EMAN::YGradientProcessor::process_inplace(), EMAN::XGradientProcessor::process_inplace(), EMAN::TestImageFourierNoiseProfile::process_inplace(), EMAN::TestImageFourierNoiseGaussian::process_inplace(), EMAN::AutoMask3D2Processor::process_inplace(), EMAN::AutoMask3DProcessor::process_inplace(), EMAN::AutoMask2DProcessor::process_inplace(), EMAN::FlattenBackgroundProcessor::process_inplace(), EMAN::BooleanShrinkProcessor::process_inplace(), EMAN::MeanShrinkProcessor::process_inplace(), EMAN::MedianShrinkProcessor::process_inplace(), EMAN::ChaoProjector::project3d(), EMAN::FourierGriddingProjector::project3d(), EMAN::PawelProjector::project3d(), EMAN::GaussFFTProjector::project3d(), read_image(), ReadVandBcast(), real(), real2complex(), real2FH(), recons3d_CGLS_mpi_Cart(), recons3d_HyBR_mpi_Cart(), recons3d_sirt_mpi(), recons3d_sirt_mpi_Cart(), EMAN::Util::reconstitute_image_mask(), rot_scale_conv(), rot_scale_conv7(), rot_scale_conv_new(), rot_scale_conv_new_background(), rotavg(), rotavg_i(), EMAN::rsconvolution(), set_attr(), set_attr_dict(), set_attr_python(), EMAN::varimax::set_params(), EMAN::PCAlarge::set_params(), EMAN::PCAsmall::set_params(), wustl_mm::SkeletonMaker::VolumeData::SetSize(), EMAN::BackProjectionReconstructor::setup(), EMAN::WienerFourierReconstructor::setup(), EMAN::FourierReconstructor::setup(), EMAN::FourierReconstructorSimple2D::setup(), EMAN::FourierReconstructor::setup_seed(), symvol(), EMAN::Util::TwoDTestFunc(), unwrap(), unwrap_largerR(), EMAN::EMUtil::vertical_acf(), and EMAN::Util::window().

00710 {
00711         ENTERFUNC;
00712 
00713         if (x <= 0) {
00714                 throw InvalidValueException(x, "x size <= 0");
00715         }
00716         else if (y <= 0) {
00717                 throw InvalidValueException(y, "y size <= 0");
00718         }
00719         else if (z <= 0) {
00720                 throw InvalidValueException(z, "z size <= 0");
00721         }
00722 
00723         int old_nx = nx;
00724 
00725         size_t size = (size_t)(x) * (size_t)y * (size_t)z * sizeof(float);
00726 
00727         if (rdata != 0) {
00728                 rdata = (float*)EMUtil::em_realloc(rdata,size);
00729         } else {
00730                 // Just pass on this for a while....see what happens
00731                 rdata = (float*)EMUtil::em_malloc(size);
00732         }
00733 //      rdata = static_cast < float *>(realloc(rdata, size));
00734         if ( rdata == 0 )
00735         {
00736                 stringstream ss;
00737                 string gigs;
00738                 ss << (float) size/1000000000.0;
00739                 ss >> gigs;
00740                 string message = "Cannot allocate " + gigs + " GB - not enough memory.";
00741                 throw BadAllocException(message);
00742         }
00743 
00744 #ifdef EMAN2_USING_CUDA
00745         // This is important
00746         free_cuda_memory();
00747 #endif // EMAN2_USING_CUDA
00748 
00749         nx = x;
00750         ny = y;
00751         nz = z;
00752         nxy = nx*ny;
00753         nxyz = nx*ny*nz;
00754 
00755         if (old_nx == 0) {
00756                 EMUtil::em_memset(get_data(),0,size);
00757         }
00758 
00759         if (supp) {
00760                 EMUtil::em_free(supp);
00761                 supp = 0;
00762         }
00763 
00764         update();
00765         EXITFUNC;
00766 }

void EMData::set_supp_pickle ( int  i  ) 

Definition at line 1186 of file emdata_metadata.cpp.

References supp.

01187 {
01188         this->supp = 0;
01189 }

void EMAN::EMData::set_translation ( float  dx,
float  dy,
float  dz 
) [inline]

Set 'this' images' translation vector from the original location.

Parameters:
dx The translation distance in x direction.
dy The translation distance in y direction.
dz The translation distance in z direction.

Definition at line 536 of file emdata.h.

00749                                           {

void EMAN::EMData::set_translation ( const Vec3f t  )  [inline]

Set 'this' images' translation vector from the original location.

Parameters:
t The new translation vector.

Definition at line 524 of file emdata.h.

00749                                           {

void EMAN::EMData::set_value_at ( int  x,
float  v 
) [inline]

Set the pixel density value at coordinate (x).

1D image only.

Parameters:
x The x cooridinate.
v The pixel density value at coordinate (x).
Exceptions:
OutofRangeException wehn index out of image data's range.

Definition at line 2186 of file emdata.h.

void EMAN::EMData::set_value_at ( int  x,
int  y,
float  v 
) [inline]

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

2D image only.

Parameters:
x The x cooridinate.
y The y cooridinate.
v The pixel density value at coordinates (x,y).
Exceptions:
OutofRangeException wehn index out of image data's range.

Definition at line 2145 of file emdata.h.

void EMAN::EMData::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:
x The x cooridinate.
y The y cooridinate.
z The z cooridinate.
v The pixel density value at coordinates (x,y,z).
Exceptions:
OutofRangeException wehn index out of image data's range.

Definition at line 2097 of file emdata.h.

Referenced by EMAN::MinMaxAverager::add_image(), bispecRotTransInvDirect(), bispecRotTransInvN(), common_lines(), EMAN::PointArray::distmx(), find_group(), get_rotated_clip(), EMAN::TestTomoImage::insert_rectangle(), make_footprint(), EMAN::DirectionalSumProcessor::process(), EMAN::TransposeProcessor::process(), EMAN::BooleanShrinkProcessor::process(), EMAN::KmeansSegmentProcessor::process(), EMAN::ZGradientProcessor::process_inplace(), EMAN::YGradientProcessor::process_inplace(), EMAN::TomoTiltEdgeMaskProcessor::process_inplace(), EMAN::XGradientProcessor::process_inplace(), EMAN::TestImageEllipse::process_inplace(), EMAN::TestImageHollowEllipse::process_inplace(), EMAN::TestImageSphericalWave::process_inplace(), EMAN::TestImageGradient::process_inplace(), EMAN::AutoMask3D2Processor::process_inplace(), EMAN::AutoMask2DProcessor::process_inplace(), EMAN::RealToFFTProcessor::process_inplace(), EMAN::BooleanShrinkProcessor::process_inplace(), EMAN::WatershedProcessor::process_inplace(), EMAN::PaintProcessor::process_inplace(), EMAN::BoxingTools::set_radial_non_zero(), EMAN::BoxingTools::set_region(), wustl_mm::SkeletonMaker::VolumeData::SetDataAt(), EMAN::Util::svdcmp(), and EMAN::WatershedProcessor::watershed().

void EMAN::EMData::set_value_at_fast ( int  x,
float  v 
) [inline]

Set the pixel density value at coordinate (x).

1D image only.

Parameters:
x The x cooridinate.
v The pixel density value at coordinate (x).

Definition at line 2206 of file emdata.h.

void EMAN::EMData::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:
x The x cooridinate.
y The y cooridinate.
v The pixel density value at coordinates (x,y).

Definition at line 2171 of file emdata.h.

void EMAN::EMData::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:
x The x cooridinate.
y The y cooridinate.
z The z cooridinate.
v The pixel density value at coordinates (x,y,z).

Definition at line 2129 of file emdata.h.

Referenced by EMAN::Rotate180Processor::process_inplace(), EMAN::WaveletProcessor::process_inplace(), EMAN::CCDNormProcessor::process_inplace(), and EMAN::TestImageLineWave::process_inplace().

void EMData::set_xyz_origin ( float  origin_x,
float  origin_y,
float  origin_z 
)

Set the x,y,z origin of the image.

Parameters:
origin_x the x origin
origin_y the y origin
origin_z the z origin

Definition at line 2866 of file emdata.cpp.

References attr_dict.

Referenced by get_clip().

02867 {
02868         attr_dict["origin_x"] = origin_x;
02869         attr_dict["origin_y"] = origin_y;
02870         attr_dict["origin_z"] = origin_z;
02871 }

void EMAN::EMData::set_xyzoff ( int  x,
int  y,
int  z 
) [inline]

Definition at line 1223 of file emdata.h.

float * EMData::setup4slice ( bool  redo = true  ) 

Set up for fftslice operations.

When interpolating in fourier space there is a little problem when we get close to x=0, since f(-x,-y,-z) = f(x,y,z)* . So this makes a supplementary array that allows for up to +-2 point interpolation all the way to the origin in x.

3D only; complex image only

Parameters:
redo If true, recalculate the supplementary array.
Exceptions:
ImageFormatException If the image is not a complex image.
ImageDimensionException If the image is not 3D.
Returns:
The supplementary array.

Definition at line 758 of file emdata.cpp.

References data, EMAN::EMUtil::em_calloc(), EMAN::EMUtil::em_free(), ENTERFUNC, EXITFUNC, get_data(), get_ndim(), ImageDimensionException, ImageFormatException, is_complex(), nx, nxy, ny, nz, supp, x, and y.

Referenced by EMAN::GaussFFTProjector::interp_ft_3d().

00759 {
00760         ENTERFUNC;
00761 
00762         if (!is_complex()) {
00763                 throw ImageFormatException("complex image only");
00764         }
00765 
00766         if (get_ndim() != 3) {
00767                 throw ImageDimensionException("3D only");
00768         }
00769 
00770         if (supp) {
00771                 if (redo) {
00772                         EMUtil::em_free(supp);
00773                         supp = 0;
00774                 }
00775                 else {
00776                         EXITFUNC;
00777                         return supp;
00778                 }
00779         }
00780 
00781         const int SUPP_ROW_SIZE = 8;
00782         const int SUPP_ROW_OFFSET = 4;
00783         const int supp_size = SUPP_ROW_SIZE + SUPP_ROW_OFFSET;
00784 
00785         supp = (float *) EMUtil::em_calloc(supp_size * ny * nz, sizeof(float));
00786         int nxy = nx * ny;
00787         int supp_xy = supp_size * ny;
00788         float * data = get_data();
00789 
00790         for (int z = 0; z < nz; z++) {
00791                 size_t cur_z1 = z * nxy;
00792                 size_t cur_z2 = z * supp_xy;
00793 
00794                 for (int y = 0; y < ny; y++) {
00795                         size_t cur_y1 = y * nx;
00796                         size_t cur_y2 = y * supp_size;
00797 
00798                         for (int x = 0; x < SUPP_ROW_SIZE; x++) {
00799                                 size_t k = (x + SUPP_ROW_OFFSET) + cur_y2 + cur_z2;
00800                                 supp[k] = data[x + cur_y1 + cur_z1];
00801                         }
00802                 }
00803         }
00804 
00805         for (int z = 1, zz = nz - 1; z < nz; z++, zz--) {
00806                 size_t cur_z1 = zz * nxy;
00807                 size_t cur_z2 = z * supp_xy;
00808 
00809                 for (int y = 1, yy = ny - 1; y < ny; y++, yy--) {
00810                         supp[y * 12 + cur_z2] = data[4 + yy * nx + cur_z1];
00811                         supp[1 + y * 12 + cur_z2] = -data[5 + yy * nx + cur_z1];
00812                         supp[2 + y * 12 + cur_z2] = data[2 + yy * nx + cur_z1];
00813                         supp[3 + y * 12 + cur_z2] = -data[3 + yy * nx + cur_z1];
00814                 }
00815         }
00816 
00817         EXITFUNC;
00818         return supp;
00819 }

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:
i 1D data array index.
Returns:
The pixel density value

Definition at line 810 of file emdata_core.cpp.

References get_data(), nx, ny, and nz.

00811 {
00812         size_t size = nx*ny;
00813         size *= nz;
00814         if (i >= size) {
00815                 return 0;
00816         }
00817         return get_data()[i];
00818 }

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:
x The x cooridinate.
y The y cooridinate.
Returns:
The pixel density value at coordinates (x,y).

Definition at line 801 of file emdata_core.cpp.

References get_data(), nx, and ny.

00802 {
00803         if (x < 0 || x >= nx || y < 0 || y >= ny) {
00804                 return 0;
00805         }
00806         return get_data()[x + y * nx];
00807 }

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:
x The x cooridinate.
y The y cooridinate.
z The z cooridinate.
Returns:
The pixel density value at coordinates (x,y,z).

Definition at line 792 of file emdata_core.cpp.

References get_data(), nx, nxy, ny, and nz.

Referenced by sget_value_at_interp().

00793 {
00794         if (x < 0 || x >= nx || y < 0 || y >= ny || z < 0 || z >= nz) {
00795                 return 0;
00796         }
00797         return get_data()[x + y * nx + z * nxy];
00798 }

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:
x The x cooridinate.
y The y cooridinate.
z The z cooridinate.
Returns:
The pixel density value at coordinates (x,y,z).

Definition at line 836 of file emdata_core.cpp.

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

00837 {
00838         int x = (int) Util::fast_floor(xx);
00839         int y = (int) Util::fast_floor(yy);
00840         int z = (int) Util::fast_floor(zz);
00841 
00842         float p1 = sget_value_at(x, y, z);
00843         float p2 = sget_value_at(x + 1, y, z);
00844         float p3 = sget_value_at(x, y + 1, z);
00845         float p4 = sget_value_at(x + 1, y + 1, z);
00846 
00847         float p5 = sget_value_at(x, y, z + 1);
00848         float p6 = sget_value_at(x + 1, y, z + 1);
00849         float p7 = sget_value_at(x, y + 1, z + 1);
00850         float p8 = sget_value_at(x + 1, y + 1, z + 1);
00851 
00852         float result = Util::trilinear_interpolate(p1, p2, p3, p4, p5, p6, p7, p8,
00853                                                                                            xx - x, yy - y, zz - z);
00854 
00855         return result;
00856 }

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:
x The x cooridinate.
y The y cooridinate.
Returns:
The pixel density value at coordinates (x,y).

Definition at line 821 of file emdata_core.cpp.

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

Referenced by get_rotated_clip(), and insert_scaled_sum().

00822 {
00823         int x = static_cast < int >(Util::fast_floor(xx));
00824         int y = static_cast < int >(Util::fast_floor(yy));
00825 
00826         float p1 = sget_value_at(x, y);
00827         float p2 = sget_value_at(x + 1, y);
00828         float p3 = sget_value_at(x, y + 1);
00829         float p4 = sget_value_at(x + 1, y + 1);
00830 
00831         float result = Util::bilinear_interpolate(p1, p2, p3, p4, xx - x, yy - y);
00832         return result;
00833 }

void EMData::shuffle_pad_corner ( float *  pad_image  ) 

Definition at line 3262 of file emdata_sparx.cpp.

References nx, and ny.

03262                                                 {
03263         int nyhalf = ny/2;
03264         int nbytes = nx*sizeof(float);
03265         for (int iy = 0; iy < nyhalf; iy++)
03266                 memcpy(&(*this)(0,iy), pad_image+6+(iy+nyhalf+3)*nx, nbytes);
03267         for (int iy = nyhalf; iy < ny; iy++)
03268                 memcpy(&(*this)(0,iy), pad_image+6+(iy-nyhalf+3)*nx, nbytes);
03269 }

EMData * EMData::sqrt (  )  const

return square root of current image

Returns:
a image which is the square root of this image
Exceptions:
ImageFormatException real image only

Definition at line 950 of file emdata_core.cpp.

References copy(), data, ENTERFUNC, EXITFUNC, get_data(), ImageFormatException, InvalidValueException, is_complex(), nxyz, sqrt(), and update().

Referenced by bispecRotTransInvDirect(), and bispecRotTransInvN().

00951 {
00952         ENTERFUNC;
00953 
00954         if (is_complex()) {
00955                 throw ImageFormatException("real image only");
00956         }
00957 
00958         EMData * r = this->copy();
00959         float * new_data = r->get_data();
00960         float * data = get_data();
00961         size_t size = nxyz;
00962         for (size_t i = 0; i < size; ++i) {
00963                 if(data[i] < 0) {
00964                         throw InvalidValueException(data[i], "pixel value must be non-negative for logrithm");
00965                 }
00966                 else {
00967                         if(data[i]) {   //do nothing with pixel has value zero
00968                                 new_data[i] = std::sqrt(data[i]);
00969                         }
00970                 }
00971         }
00972 
00973         r->update();
00974         return r;
00975 
00976         EXITFUNC;
00977 }

void EMData::sub ( const EMData image  ) 

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

Parameters:
image The image subtracted from 'this' image.
Exceptions:
ImageFormatException If the 2 images are not same size.

Definition at line 446 of file emdata_core.cpp.

References data, ENTERFUNC, EXITFUNC, get_data(), get_xsize(), get_ysize(), get_zsize(), ImageFormatException, is_real(), nx, nxyz, ny, nz, and update().

00447 {
00448         ENTERFUNC;
00449 
00450         if (nx != em.get_xsize() || ny != em.get_ysize() || nz != em.get_zsize()) {
00451                 throw ImageFormatException("images not same sizes");
00452         }
00453         else if( (is_real()^em.is_real()) == true )
00454         {
00455                 throw ImageFormatException( "not support sub between real image and complex image");
00456         }
00457         else {
00458                 const float *src_data = em.get_data();
00459                 size_t size = nxyz;
00460                 float* data = get_data();
00461 
00462                 for (size_t i = 0; i < size; i++) {
00463                         data[i] -= src_data[i];
00464                 }
00465                 update();
00466         }
00467         EXITFUNC;
00468 }

void EMData::sub ( float  f  ) 

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

Parameters:
f The float number subtracted from 'this' image.

Definition at line 400 of file emdata_core.cpp.

References data, emdata_processor_add(), ENTERFUNC, EXITFUNC, get_data(), ImageFormatException, is_complex(), is_real(), nxyz, and update().

Referenced by calc_fast_sigma_image(), make_rotational_footprint(), make_rotational_footprint_cmc(), make_rotational_footprint_e1(), EMAN::operator-(), operator-=(), and EMAN::FlattenBackgroundProcessor::process_inplace().

00401 {
00402         ENTERFUNC;
00403 
00404         float* data = get_data();
00405         if( is_real() )
00406         {
00407                 if (f != 0) {
00408 #ifdef EMAN2_USING_CUDA
00409                 if ( gpu_operation_preferred () ) {
00410                         EMDataForCuda tmp = get_data_struct_for_cuda();
00411                         emdata_processor_add(&tmp,-f);
00412                         gpu_update();
00413                         EXITFUNC;
00414                         return;
00415                 }
00416 #endif // EMAN2_USING_CUDA
00417                         size_t size = nxyz;
00418                         for (size_t i = 0; i < size; i++) {
00419                                 data[i] -= f;
00420                         }
00421                 }
00422                 update();
00423         }
00424         else if( is_complex() )
00425         {
00426                 if( f != 0 )
00427                 {
00428                         size_t size = nxyz;
00429                         for( size_t i=0; i<size; i+=2 )
00430                         {
00431                                 data[i] -= f;
00432                         }
00433                 }
00434                 update();
00435         }
00436         else
00437         {
00438                 throw ImageFormatException("This image is neither a real nor a complex image.");
00439         }
00440 
00441         EXITFUNC;
00442 }

void EMData::subsquare ( const EMData image  ) 

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

Parameters:
image The image whose square is subtracted from 'this' image.
Exceptions:
ImageFormatException If the 2 images are not same size.

Definition at line 375 of file emdata_core.cpp.

References data, ENTERFUNC, EXITFUNC, get_data(), get_xsize(), get_ysize(), get_zsize(), ImageFormatException, is_complex(), nx, nxyz, ny, nz, and update().

00376 {
00377         ENTERFUNC;
00378         if (nx != image.get_xsize() || ny != image.get_ysize() || nz != image.get_zsize()) {
00379                 throw ImageFormatException( "images not same sizes");
00380         }
00381         else if( this->is_complex() || image.is_complex() )
00382         {
00383                 throw ImageFormatException( "Cannot addsquare() with complex images");
00384         }
00385         else {
00386 
00387                 const float *src_data = image.get_data();
00388                 size_t size = nxyz;
00389                 float* data = get_data();
00390 
00391                 for (size_t i = 0; i < size; i++) {
00392                         data[i] -= src_data[i]*src_data[i];
00393                 }
00394                 update();
00395         }
00396         EXITFUNC;
00397 }

void EMData::symplane0 ( EMData norm  ) 

Calculate Wiener summation from the inserted 2D slice put the summation into 3D grids using nearest neighbour approximation a.

Map the 2D coordinates of the interted slice into 3D grid using 3D transformation b. calculate 2D CTF_K^2 and CTF_K*F_K, and put them on the voxel of 3D volume c. count the number of images entering each boxel wptr3

Definition at line 1206 of file emdata_sparx.cpp.

References attr_dict, cmplx(), ENTERFUNC, EXITFUNC, get_array_offsets(), and set_array_offsets().

Referenced by EMAN::nn4Reconstructor::finish().

01206                                    {
01207         ENTERFUNC;
01208         int nxc = attr_dict["nxc"];
01209         int n = nxc*2;
01210         // let's treat the local data as a matrix
01211         vector<int> saved_offsets = get_array_offsets();
01212         set_array_offsets(0,1,1);
01213         for (int iza = 2; iza <= nxc; iza++) {
01214                 for (int iya = 2; iya <= nxc; iya++) {
01215                         cmplx(0,iya,iza) += conj(cmplx(0,n-iya+2,n-iza+2));
01216                         (*wptr)(0,iya,iza) += (*wptr)(0,n-iya+2,n-iza+2);
01217                         cmplx(0,n-iya+2,n-iza+2) = conj(cmplx(0,iya,iza));
01218                         (*wptr)(0,n-iya+2,n-iza+2) = (*wptr)(0,iya,iza);
01219                         cmplx(0,n-iya+2,iza) += conj(cmplx(0,iya,n-iza+2));
01220                         (*wptr)(0,n-iya+2,iza) += (*wptr)(0,iya,n-iza+2);
01221                         cmplx(0,iya,n-iza+2) = conj(cmplx(0,n-iya+2,iza));
01222                         (*wptr)(0,iya,n-iza+2) = (*wptr)(0,n-iya+2,iza);
01223                 }
01224         }
01225         for (int iya = 2; iya <= nxc; iya++) {
01226                 cmplx(0,iya,1) += conj(cmplx(0,n-iya+2,1));
01227                 (*wptr)(0,iya,1) += (*wptr)(0,n-iya+2,1);
01228                 cmplx(0,n-iya+2,1) = conj(cmplx(0,iya,1));
01229                 (*wptr)(0,n-iya+2,1) = (*wptr)(0,iya,1);
01230         }
01231         for (int iza = 2; iza <= nxc; iza++) {
01232                 cmplx(0,1,iza) += conj(cmplx(0,1,n-iza+2));
01233                 (*wptr)(0,1,iza) += (*wptr)(0,1,n-iza+2);
01234                 cmplx(0,1,n-iza+2) = conj(cmplx(0,1,iza));
01235                 (*wptr)(0,1,n-iza+2) = (*wptr)(0,1,iza);
01236         }
01237         EXITFUNC;
01238 }

void EMData::symplane0_ctf ( EMData w  ) 

Symmetrize plane 0 Modifies the current object.

Parameters:
w Normalization data.

Definition at line 1740 of file emdata_sparx.cpp.

References attr_dict, cmplx(), ENTERFUNC, EXITFUNC, get_array_offsets(), and set_array_offsets().

Referenced by EMAN::nn4_ctfReconstructor::finish().

01740                                     {
01741         ENTERFUNC;
01742         int nxc = attr_dict["nxc"];
01743         int n = nxc*2;
01744         // let's treat the local data as a matrix
01745         vector<int> saved_offsets = get_array_offsets();
01746         set_array_offsets(0,1,1);
01747         for (int iza = 2; iza <= nxc; iza++) {
01748                 for (int iya = 2; iya <= nxc; iya++) {
01749                         cmplx(0,iya,iza) += conj(cmplx(0,n-iya+2,n-iza+2));
01750                         (*w)(0,iya,iza) += (*w)(0,n-iya+2,n-iza+2);
01751                         cmplx(0,n-iya+2,n-iza+2) = conj(cmplx(0,iya,iza));
01752                         (*w)(0,n-iya+2,n-iza+2) = (*w)(0,iya,iza);
01753                         cmplx(0,n-iya+2,iza) += conj(cmplx(0,iya,n-iza+2));
01754                         (*w)(0,n-iya+2,iza) += (*w)(0,iya,n-iza+2);
01755                         cmplx(0,iya,n-iza+2) = conj(cmplx(0,n-iya+2,iza));
01756                         (*w)(0,iya,n-iza+2) = (*w)(0,n-iya+2,iza);
01757                 }
01758         }
01759         for (int iya = 2; iya <= nxc; iya++) {
01760                 cmplx(0,iya,1) += conj(cmplx(0,n-iya+2,1));
01761                 (*w)(0,iya,1) += (*w)(0,n-iya+2,1);
01762                 cmplx(0,n-iya+2,1) = conj(cmplx(0,iya,1));
01763                 (*w)(0,n-iya+2,1) = (*w)(0,iya,1);
01764         }
01765         for (int iza = 2; iza <= nxc; iza++) {
01766                 cmplx(0,1,iza) += conj(cmplx(0,1,n-iza+2));
01767                 (*w)(0,1,iza) += (*w)(0,1,n-iza+2);
01768                 cmplx(0,1,n-iza+2) = conj(cmplx(0,1,iza));
01769                 (*w)(0,1,n-iza+2) = (*w)(0,1,iza);
01770         }
01771         EXITFUNC;
01772 }

void EMData::symplane1 ( EMData norm,
EMData norm2 
)

Symmetrize plane 0 Modifies the current object.

Parameters:
norm Normalization data.
norm2 

Definition at line 1240 of file emdata_sparx.cpp.

References attr_dict, cmplx(), ENTERFUNC, EXITFUNC, get_array_offsets(), and set_array_offsets().

Referenced by EMAN::nnSSNR_Reconstructor::finish().

01240                                                   {
01241         ENTERFUNC;
01242         int nxc = attr_dict["nxc"];
01243         int n = nxc*2;
01244         vector<int> saved_offsets = get_array_offsets();
01245         set_array_offsets(0,1,1);
01246         for (int iza = 2; iza <= nxc; iza++) {
01247                 for (int iya = 2; iya <= nxc; iya++) {
01248                         cmplx(0,iya,iza) += conj(cmplx(0,n-iya+2,n-iza+2));
01249                         (*wptr)(0,iya,iza) += (*wptr)(0,n-iya+2,n-iza+2);
01250                         (*wptr2)(0,iya,iza) += (*wptr2)(0,n-iya+2,n-iza+2);
01251                         cmplx(0,n-iya+2,n-iza+2) = conj(cmplx(0,iya,iza));
01252                         (*wptr)(0,n-iya+2,n-iza+2) = (*wptr)(0,iya,iza);
01253                         (*wptr2)(0,n-iya+2,n-iza+2) = (*wptr2)(0,iya,iza);
01254                         cmplx(0,n-iya+2,iza) += conj(cmplx(0,iya,n-iza+2));
01255                         (*wptr)(0,n-iya+2,iza) += (*wptr)(0,iya,n-iza+2);
01256                         (*wptr2)(0,n-iya+2,iza) += (*wptr2)(0,iya,n-iza+2);
01257                         cmplx(0,iya,n-iza+2) = conj(cmplx(0,n-iya+2,iza));
01258                         (*wptr)(0,iya,n-iza+2) = (*wptr)(0,n-iya+2,iza);
01259                         (*wptr2)(0,iya,n-iza+2) = (*wptr2)(0,n-iya+2,iza);
01260                 }
01261         }
01262         for (int iya = 2; iya <= nxc; iya++) {
01263                 cmplx(0,iya,1) += conj(cmplx(0,n-iya+2,1));
01264                 (*wptr)(0,iya,1) += (*wptr)(0,n-iya+2,1);
01265                 (*wptr2)(0,iya,1) += (*wptr2)(0,n-iya+2,1);
01266                 cmplx(0,n-iya+2,1) = conj(cmplx(0,iya,1));
01267                 (*wptr)(0,n-iya+2,1) = (*wptr)(0,iya,1);
01268                 (*wptr2)(0,n-iya+2,1) = (*wptr2)(0,iya,1);
01269         }
01270         for (int iza = 2; iza <= nxc; iza++) {
01271                 cmplx(0,1,iza) += conj(cmplx(0,1,n-iza+2));
01272                 (*wptr)(0,1,iza) += (*wptr)(0,1,n-iza+2);
01273                 (*wptr2)(0,1,iza) += (*wptr2)(0,1,n-iza+2);
01274                 cmplx(0,1,n-iza+2) = conj(cmplx(0,1,iza));
01275                 (*wptr)(0,1,n-iza+2) = (*wptr)(0,1,iza);
01276                 (*wptr2)(0,1,n-iza+2) = (*wptr2)(0,1,iza);
01277         }
01278         EXITFUNC;
01279 }

void EMData::symplane2 ( EMData norm,
EMData norm2,
EMData norm3 
)

Symmetrize plane 0 Modifies the current object.

Parameters:
norm Normalization data.
norm2 
norm3 

Definition at line 1281 of file emdata_sparx.cpp.

References attr_dict, cmplx(), ENTERFUNC, EXITFUNC, get_array_offsets(), and set_array_offsets().

Referenced by EMAN::nnSSNR_ctfReconstructor::finish().

01281                                                                  {
01282         ENTERFUNC;
01283         int nxc = attr_dict["nxc"];
01284         int n = nxc*2;
01285         vector<int> saved_offsets = get_array_offsets();
01286         set_array_offsets(0,1,1);
01287         for (int iza = 2; iza <= nxc; iza++) {
01288                 for (int iya = 2; iya <= nxc; iya++) {
01289                         cmplx(0,iya,iza) += conj(cmplx(0,n-iya+2,n-iza+2));
01290                         (*wptr)(0,iya,iza) += (*wptr)(0,n-iya+2,n-iza+2);
01291                         (*wptr2)(0,iya,iza) += (*wptr2)(0,n-iya+2,n-iza+2);
01292                         (*wptr3)(0,iya,iza) += (*wptr3)(0,n-iya+2,n-iza+2);
01293 
01294                         cmplx(0,n-iya+2,n-iza+2) = conj(cmplx(0,iya,iza));
01295                         (*wptr)(0,n-iya+2,n-iza+2) = (*wptr)(0,iya,iza);
01296                         (*wptr2)(0,n-iya+2,n-iza+2) = (*wptr2)(0,iya,iza);
01297                         (*wptr3)(0,n-iya+2,n-iza+2) = (*wptr3)(0,iya,iza);
01298 
01299                         cmplx(0,n-iya+2,iza) += conj(cmplx(0,iya,n-iza+2));
01300                         (*wptr)(0,n-iya+2,iza) += (*wptr)(0,iya,n-iza+2);
01301                         (*wptr2)(0,n-iya+2,iza) += (*wptr2)(0,iya,n-iza+2);
01302                         (*wptr3)(0,n-iya+2,iza) += (*wptr3)(0,iya,n-iza+2);
01303 
01304                         cmplx(0,iya,n-iza+2) = conj(cmplx(0,n-iya+2,iza));
01305                         (*wptr)(0,iya,n-iza+2) = (*wptr)(0,n-iya+2,iza);
01306                         (*wptr2)(0,iya,n-iza+2) = (*wptr2)(0,n-iya+2,iza);
01307                         (*wptr3)(0,iya,n-iza+2) = (*wptr3)(0,n-iya+2,iza);
01308                 }
01309         }
01310         for (int iya = 2; iya <= nxc; iya++) {
01311                 cmplx(0,iya,1) += conj(cmplx(0,n-iya+2,1));
01312                 (*wptr)(0,iya,1) += (*wptr)(0,n-iya+2,1);
01313                 (*wptr2)(0,iya,1) += (*wptr2)(0,n-iya+2,1);
01314                 (*wptr3)(0,iya,1) += (*wptr3)(0,n-iya+2,1);
01315 
01316                 cmplx(0,n-iya+2,1) = conj(cmplx(0,iya,1));
01317                 (*wptr)(0,n-iya+2,1) = (*wptr)(0,iya,1);
01318                 (*wptr2)(0,n-iya+2,1) = (*wptr2)(0,iya,1);
01319                 (*wptr3)(0,n-iya+2,1) = (*wptr3)(0,iya,1);
01320         }
01321         for (int iza = 2; iza <= nxc; iza++) {
01322                 cmplx(0,1,iza) += conj(cmplx(0,1,n-iza+2));
01323                 (*wptr)(0,1,iza) += (*wptr)(0,1,n-iza+2);
01324                 (*wptr2)(0,1,iza) += (*wptr2)(0,1,n-iza+2);
01325                 (*wptr3)(0,1,iza) += (*wptr3)(0,1,n-iza+2);
01326 
01327                 cmplx(0,1,n-iza+2) = conj(cmplx(0,1,iza));
01328                 (*wptr)(0,1,n-iza+2) = (*wptr)(0,1,iza);
01329                 (*wptr2)(0,1,n-iza+2) = (*wptr2)(0,1,iza);
01330                 (*wptr3)(0,1,n-iza+2) = (*wptr3)(0,1,iza);
01331         }
01332         EXITFUNC;
01333 }

EMData * EMData::symvol ( string  symmetry  ) 

Symmetrize volume in real space.

Parameters:
[in] symmetry Point group of the target volume.
Returns:
New symmetrized volume object.

Definition at line 940 of file emdata_sparx.cpp.

References ENTERFUNC, EXITFUNC, EMAN::Transform::get_nsym(), EMAN::Transform::get_sym(), nx, ny, nz, rot_scale_trans(), set_size(), to_zero(), and update().

00940                                        {
00941         ENTERFUNC;
00942         int nsym = Transform::get_nsym(symString); // number of symmetries
00943         Transform sym;
00944         // set up output volume
00945         EMData *svol = new EMData;
00946         svol->set_size(nx, ny, nz);
00947         svol->to_zero();
00948         // set up new copy
00949         EMData* symcopy = new EMData;
00950         symcopy->set_size(nx, ny, nz);
00951         // set up coord grid
00952         // actual work -- loop over symmetries and symmetrize
00953         for (int isym = 0; isym < nsym; isym++) {
00954                 Transform rm = sym.get_sym(symString, isym);
00955                 symcopy = this -> rot_scale_trans(rm);
00956                 *svol += (*symcopy);
00957         }
00958         *svol /=  ((float) nsym);
00959         svol->update();
00960         EXITFUNC;
00961         return svol;
00962 }

void EMData::to_one (  ) 

set all the pixel values = 1.

Definition at line 1348 of file emdata_core.cpp.

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

Referenced by EMAN::EMAN2Ctf::compute_2d_complex(), EMAN::EMAN1Ctf::compute_2d_complex(), EMAN::filt_erosion_(), get_circle_mean(), EMAN::Util::im_diff(), make_rotational_footprint_cmc(), make_rotational_footprint_e1(), EMAN::operator/(), and power().

01349 {
01350         ENTERFUNC;
01351 
01352         if (is_complex()) {
01353                 set_ri(true);
01354         }
01355         else {
01356                 set_ri(false);
01357         }
01358         to_value(1.0);
01359 
01360         update();
01361         EXITFUNC;
01362 }

void EMData::to_value ( const float &  value  ) 

set all the pixel values to a value.

Definition at line 1364 of file emdata_core.cpp.

References data, EMAN::EMUtil::em_memset(), emdata_processor_to_value(), ENTERFUNC, EXITFUNC, get_data(), get_size(), nxyz, and update().

Referenced by get_clip(), wustl_mm::SkeletonMaker::VolumeData::InitializeVolumeData(), make_rotational_footprint_e1(), EMAN::FourierReconstructor::setup_seed(), to_one(), and to_zero().

01365 {
01366         ENTERFUNC;
01367 
01368 #ifdef EMAN2_USING_CUDA
01369         if ( gpu_operation_preferred() ) {
01370                 EMDataForCuda tmp = get_data_struct_for_cuda();
01371                 emdata_processor_to_value(&tmp,value);
01372                 gpu_update();
01373                 EXITFUNC;
01374                 return;
01375         }
01376 #endif // EMAN2_USING_CUDA
01377         float* data = get_data();
01378         if ( value != 0 ) std::fill(data,data+get_size(),value);
01379         else EMUtil::em_memset(data, 0, nxyz * sizeof(float)); // This might be faster, I don't know
01380 
01381         update();
01382         EXITFUNC;
01383 }

void EMData::to_zero (  ) 

Set all the pixel value = 0.

Definition at line 1331 of file emdata_core.cpp.

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

Referenced by EMAN::CtfAverager::add_image(), EMAN::CtfCWautoAverager::add_image(), EMAN::PawelProjector::backproject3d(), EMAN::ChaoProjector::backproject3d(), EMAN::nnSSNR_ctfReconstructor::buildFFTVolume(), EMAN::nn4_ctfReconstructor::buildFFTVolume(), EMAN::nnSSNR_Reconstructor::buildFFTVolume(), EMAN::nn4Reconstructor::buildFFTVolume(), EMAN::nnSSNR_ctfReconstructor::buildNorm2Volume(), EMAN::nnSSNR_Reconstructor::buildNorm2Volume(), EMAN::nnSSNR_ctfReconstructor::buildNorm3Volume(), EMAN::nnSSNR_ctfReconstructor::buildNormVolume(), EMAN::nn4_ctfReconstructor::buildNormVolume(), EMAN::nnSSNR_Reconstructor::buildNormVolume(), EMAN::nn4Reconstructor::buildNormVolume(), calc_ccfx(), delete_disconnected_regions(), EMAN::PointArray::distmx(), do_radon(), downsample(), EMData(), extract_plane(), extractline(), FH2F(), EMAN::filt_dilation_(), EMAN::filt_median_(), EMAN::nnSSNR_ctfReconstructor::finish(), EMAN::nnSSNR_Reconstructor::finish(), Four_ds(), Four_shuf_ds_cen_us(), FourInterpol(), EMAN::Util::get_biggest_cluster(), get_fft_amplitude(), get_fft_amplitude2D(), get_fft_phase(), helicise(), little_big_dot(), make_footprint(), EMAN::Util::move_points(), mult_radial(), EMAN::PointArray::pdb2mrc_by_summation(), EMAN::DirectionalSumProcessor::process(), EMAN::TestImageScurve::process_inplace(), EMAN::TestImageFourierNoiseProfile::process_inplace(), EMAN::SymSearchProcessor::process_inplace(), EMAN::MeanShrinkProcessor::process_inplace(), EMAN::WatershedProcessor::process_inplace(), EMAN::FourierGriddingProjector::project3d(), EMAN::PawelProjector::project3d(), read_image(), real2FH(), recons3d_CGLS_mpi_Cart(), recons3d_HyBR_mpi_Cart(), recons3d_sirt_mpi(), recons3d_sirt_mpi_Cart(), rotavg(), rotavg_i(), EMAN::rsconvolution(), EMAN::FourierReconstructor::setup(), symvol(), EMAN::Util::TwoDTestFunc(), and EMAN::ReconstructorVolumeData::zero_memory().

01332 {
01333         ENTERFUNC;
01334 
01335         if (is_complex()) {
01336                 set_ri(true);
01337         }
01338         else {
01339                 set_ri(false);
01340         }
01341 
01342         //EMUtil::em_memset(get_data(), 0, nxyz * sizeof(float));
01343         to_value(0.0);
01344         update();
01345         EXITFUNC;
01346 }

void EMAN::EMData::transform ( const Transform t  )  [inline]

Transform the image.

Parameters:
t the transform object that describes the transformation to be applied to the image.

Definition at line 3260 of file emdata.h.

Referenced by common_lines_real(), cut_slice(), do_radon(), EMAN::BackProjectionReconstructor::insert_slice(), EMAN::BackProjectionReconstructor::preprocess_slice(), EMAN::TestImageSinewave::process_inplace(), rotate(), scale(), and uncut_slice().

void EMData::translate ( const Vec3i translation  ) 

Translate this image.

integer only translation could be done faster, without interpolation.

Parameters:
translation The translation distance vector.

Definition at line 856 of file emdata.cpp.

References all_translation, ENTERFUNC, EXITFUNC, and process_inplace().

00857 {
00858         ENTERFUNC;
00859 
00860         //if traslation is 0, do nothing
00861         if( translation[0] == 0 && translation[1] == 0 && translation[2] == 0) {
00862                 EXITFUNC;
00863                 return;
00864         }
00865 
00866         Dict params("trans",static_cast< vector<int> >(translation));
00867         process_inplace("math.translate.int",params);
00868 
00869         // update() - clip_inplace does the update
00870         all_translation += translation;
00871 
00872         EXITFUNC;
00873 }

void EMData::translate ( int  dx,
int  dy,
int  dz 
)

Translate this image.

integer only translation could be done faster, without interpolation.

Parameters:
dx Translation distance in x direction.
dy Translation distance in y direction.
dz Translation distance in z direction.

Definition at line 832 of file emdata.cpp.

References ENTERFUNC, EXITFUNC, and translate().

00833 {
00834         ENTERFUNC;
00835         translate(Vec3i(dx, dy, dz));
00836         EXITFUNC;
00837 }

void EMData::translate ( const Vec3f translation  ) 

Translate this image.

Parameters:
translation The translation distance vector.

Definition at line 876 of file emdata.cpp.

References all_translation, ENTERFUNC, EXITFUNC, process_inplace(), and t.

00877 {
00878         ENTERFUNC;
00879 
00880         if( translation[0] == 0.0f && translation[1] == 0.0f && translation[2] == 0.0f ) {
00881                 EXITFUNC;
00882                 return;
00883         }
00884 
00885         Transform* t = new Transform();
00886         t->set_trans(translation);
00887         process_inplace("xform",Dict("transform",t));
00888         delete t;
00889 
00890         all_translation += translation;
00891         EXITFUNC;
00892 }

void EMData::translate ( float  dx,
float  dy,
float  dz 
)

Translate this image.

Parameters:
dx Translation distance in x direction.
dy Translation distance in y direction.
dz Translation distance in z direction.

Definition at line 840 of file emdata.cpp.

References ENTERFUNC, EXITFUNC, and EMAN::Util::round().

Referenced by main(), EMAN::ACFCenterProcessor::process_inplace(), EMAN::PhaseToMassCenterProcessor::process_inplace(), EMAN::ToMassCenterProcessor::process_inplace(), EMAN::GaussFFTProjector::project3d(), and translate().

00841 {
00842         ENTERFUNC;
00843         int dx_ = Util::round(dx);
00844         int dy_ = Util::round(dy);
00845         int dz_ = Util::round(dz);
00846         if( ( (dx-dx_) == 0 ) && ( (dy-dy_) == 0 ) && ( (dz-dz_) == 0 )) {
00847                 translate(dx_, dy_, dz_);
00848         }
00849         else {
00850                 translate(Vec3f(dx, dy, dz));
00851         }
00852         EXITFUNC;
00853 }

void EMData::uncut_slice ( EMData *const   map,
const Transform tr 
) const

Opposite of the cut_slice().

It will take a slice and insert the data into a real 3D map. It does not interpolate, it uses the nearest neighbor.

Parameters:
map The real 3D map.
tr Orientation of the slice.
Exceptions:
NullPointerException If map is NULL.
ImageDimensionException If this image is not 2D.
ImageDimensionException If map image is not 3D.
ImageFormatException If this image is complex
ImageFormatException If map is complex
Author:
David Woolford (adapted from an original version by Steve Ludtke)
Date:
Feb 2008

Definition at line 3880 of file emdata.cpp.

References ENTERFUNC, EXITFUNC, get_data(), get_ndim(), get_xsize(), get_ysize(), get_zsize(), ImageDimensionException, ImageFormatException, is_complex(), NullPointerException, nx, ny, EMAN::Util::round(), transform(), update(), x, and y.

03881 {
03882         ENTERFUNC;
03883 
03884         if (!map) throw NullPointerException("NULL image");
03885         // These restrictions should be ultimately restricted so that all that matters is get_ndim() = (map->get_ndim() -1)
03886         if ( get_ndim() != 2 ) throw ImageDimensionException("Can not call cut slice on an image that is not 2D");
03887         if ( map->get_ndim() != 3 ) throw ImageDimensionException("Can not cut slice from an image that is not 3D");
03888         // Now check for complex images - this is really just being thorough
03889         if ( is_complex() ) throw ImageFormatException("Can not call cut slice on an image that is complex");
03890         if ( map->is_complex() ) throw ImageFormatException("Can not cut slice from a complex image");
03891 
03892 //      Transform3D r( 0, 0, 0); // EMAN by default
03893 //      if (!ort) {
03894 //              ort = &r;
03895 //      }
03896 
03897         float *ddata = map->get_data();
03898         float *sdata = get_data();
03899 
03900         int map_nx = map->get_xsize();
03901         int map_ny = map->get_ysize();
03902         int map_nz = map->get_zsize();
03903         int map_nxy = map_nx * map_ny;
03904         float map_nz_round_limit = (float) map_nz-0.5f;
03905         float map_ny_round_limit = (float) map_ny-0.5f;
03906         float map_nx_round_limit = (float) map_nx-0.5f;
03907 /*
03908         Vec3f posttrans = ort->get_posttrans();
03909         Vec3f pretrans = ort->get_pretrans();*/
03910 
03911         int ymax = ny/2;
03912         if ( ny % 2 == 1 ) ymax += 1;
03913         int xmax = nx/2;
03914         if ( nx % 2 == 1 ) xmax += 1;
03915         for (int y = -ny/2; y < ymax; y++) {
03916                 for (int x = -nx/2; x < xmax; x++) {
03917                         Vec3f coord(x,y,0);
03918                         Vec3f soln = transform*coord;
03919 //                      float xx = (x+pretrans[0]) * (*ort)[0][0] +  (y+pretrans[1]) * (*ort)[0][1] + pretrans[2] * (*ort)[0][2] + posttrans[0];
03920 //                      float yy = (x+pretrans[0]) * (*ort)[1][0] +  (y+pretrans[1]) * (*ort)[1][1] + pretrans[2] * (*ort)[1][2] + posttrans[1];
03921 //                      float zz = (x+pretrans[0]) * (*ort)[2][0] +  (y+pretrans[1]) * (*ort)[2][1] + pretrans[2] * (*ort)[2][2] + posttrans[2];
03922 //
03923 //                      xx += map_nx/2;
03924 //                      yy += map_ny/2;
03925 //                      zz += map_nz/2;
03926 //
03927                         float xx = soln[0]+map_nx/2;
03928                         float yy = soln[1]+map_ny/2;
03929                         float zz = soln[2]+map_nz/2;
03930 
03931                         // These 0.5 offsets are here because the round function rounds to the nearest whole number.
03932                         if (xx < -0.5 || yy < -0.5 || zz < -0.5 || xx >= map_nx_round_limit || yy >= map_ny_round_limit || zz >= map_nz_round_limit) continue;
03933 
03934                         int k = Util::round(xx) + Util::round(yy) * map_nx + Util::round(zz) * map_nxy;
03935                         int l = (x+nx/2) + (y+ny/2) * nx;
03936                         ddata[k] = sdata[l];
03937                 }
03938         }
03939 
03940         map->update();
03941         EXITFUNC;
03942 }

EMData * EMData::unwrap_largerR ( int  r1,
int  r2,
int  xs,
float  rmax_f 
)

Definition at line 3725 of file emdata.cpp.

References EMAN::Util::calc_best_fft_size(), get_data(), get_xsize(), get_ysize(), set_size(), sqrt(), t, update(), x, and y.

03725                                                                  {
03726         float *d,*dd;
03727         int do360=2;
03728         int rmax = (int)(rmax_f+0.5f);
03729         unsigned long i;
03730         unsigned int nvox=get_xsize()*get_ysize();//ming
03731         float maxmap=0.0f, minmap=0.0f;
03732         float temp=0.0f, diff_den=0.0f, norm=0.0f;
03733         float cut_off_va =0.0f;
03734 
03735         d=get_data();
03736         maxmap=-1000000.0f;
03737         minmap=1000000.0f;
03738         for (i=0;i<nvox;i++){
03739                 if(d[i]>maxmap) maxmap=d[i];
03740                 if(d[i]<minmap) minmap=d[i];
03741         }
03742         diff_den = maxmap-minmap;
03743         for(i=0;i<nvox;i++) {
03744                 temp = (d[i]-minmap)/diff_den;
03745                 if(cut_off_va != 0.0) {               // cut off the lowerset ?% noisy information
03746                         if(temp < cut_off_va)
03747                                 d[i] = 0.0f;                   // set the empty part density=0.0
03748                         else
03749                                 d[i] = temp-cut_off_va;
03750                 }
03751                 else    d[i] = temp;
03752         }
03753 
03754         for(i=0;i<nvox;i++) {
03755                 temp=d[i];
03756                 norm += temp*temp;
03757         }
03758         for(i=0;i<nvox;i++)             d[i] /= norm;                      //  y' = y/norm(y)
03759 
03760         if (xs<1) {
03761                 xs = (int) floor(do360*M_PI*get_ysize()/4); // ming
03762                 xs=Util::calc_best_fft_size(xs); // ming
03763         }
03764         if (r1<0) r1=0;
03765         float maxext=ceil(0.6*std::sqrt((double)(get_xsize()*get_xsize()+get_ysize()*get_ysize())));// ming add std::
03766 
03767         if (r2<r1) r2=(int)maxext;
03768         EMData *ret = new EMData;
03769 
03770         ret->set_size(xs,r2+1,1);
03771 
03772         dd=ret->get_data();
03773 
03774         for (int i=0; i<xs; i++) {
03775                 float si=sin(i*M_PI*2/xs);
03776                 float co=cos(i*M_PI*2/xs);
03777                 for (int r=0; r<=maxext; r++) {
03778                         float x=(r+r1)*co+get_xsize()/2; // ming
03779                         float y=(r+r1)*si+get_ysize()/2; // ming
03780                         if(x<0.0 || x>=get_xsize()-1.0 || y<0.0 || y>=get_ysize()-1.0 || r>rmax){    //Ming , ~~~~ rmax need pass here
03781                                 for(;r<=r2;r++)                                   // here r2=MAXR
03782                                         dd[i+r*xs]=0.0;
03783                         break;
03784                     }
03785                         int x1=floor(x);
03786                         int y1=floor(y);
03787                         float t=x-x1;
03788                         float u=y-y1;
03789                         float f11= d[x1+y1*get_xsize()]; // ming
03790                         float f21= d[(x1+1)+y1*get_xsize()]; // ming
03791                         float f12= d[x1+(y1+1)*get_xsize()]; // ming
03792                         float f22= d[(x1+1)+(y1+1)*get_xsize()]; // ming
03793                         dd[i+r*xs] = (1-t)*(1-u)*f11+t*(1-u)*f21+t*u*f22+(1-t)*u*f12;
03794                 }
03795         }
03796         update();
03797         ret->update();
03798         return ret;
03799 }

void EMAN::EMData::update (  )  [inline]

Mark EMData as changed, statistics, etc will be updated at need.

Definition at line 388 of file emdata.h.

Referenced by absi(), EMAN::MeanShrinkProcessor::accrue_mean_one_p_five(), add(), EMAN::CtfAverager::add_image(), EMAN::Util::add_img(), EMAN::Util::add_img2(), EMAN::Util::add_img_abs(), add_incoherent(), EMAN::Util::addn_img(), addsquare(), EMAN::TranslationalAligner::align(), amplitude(), ap2ri(), apply_radial_func(), average_circ_sub(), EMAN::PawelProjector::backproject3d(), EMAN::ChaoProjector::backproject3d(), calc_ccfx(), calc_mutual_correlation(), center_origin(), center_origin_fft(), center_origin_yz(), EMAN::Util::cml_prepare_line(), EMAN::FRCCmp::cmp(), EMAN::PhaseCmp::cmp(), common_lines(), common_lines_real(), EMAN::EMAN2Ctf::compute_2d_complex(), EMAN::EMAN1Ctf::compute_2d_complex(), convolute(), copy_head(), EMAN::Util::ctf_img(), cut_slice(), EMAN::Util::cyclicshift(), EMAN::Util::decimate(), delete_disconnected_regions(), depad(), depad_corner(), EMAN::PointArray::distmx(), div(), EMAN::Util::div_filter(), EMAN::Util::div_img(), EMAN::Util::divn_filter(), EMAN::Util::divn_img(), do_fft(), do_fft_inplace(), do_ift(), do_ift_inplace(), do_radon(), EMData(), EMAN::Processor::EMFourierFilterFunc(), fft_shuffle(), FH2F(), filter_by_image(), EMAN::nnSSNR_ctfReconstructor::finish(), EMAN::nnSSNR_Reconstructor::finish(), EMAN::WienerFourierReconstructor::finish(), EMAN::FourierReconstructor::finish(), EMAN::CtfAverager::finish(), EMAN::CtfCWautoAverager::finish(), EMAN::IterationAverager::finish(), EMAN::MinMaxAverager::finish(), EMAN::ImageAverager::finish(), Four_ds(), Four_shuf_ds_cen_us(), fouriergridrot2d(), fouriergridrot_shift2d(), EMAN::fourierproduct(), FourInterpol(), FourTruncate(), get_clip(), get_col(), get_fft_amplitude(), get_fft_amplitude2D(), get_fft_phase(), EMAN::file_store::get_image(), EMAN::newfile_store::get_image(), get_rotated_clip(), get_row(), get_top_half(), helicise(), EMAN::Util::im_diff(), imag(), insert_clip(), insert_scaled_sum(), EMAN::WienerFourierReconstructor::insert_slice(), little_big_dot(), log(), log10(), EMAN::Util::mad_scalar(), EMAN::Util::madn_scalar(), main(), EMAN::TestUtil::make_image_file_by_mode(), EMAN::EMUtil::make_image_median(), EMAN::Util::move_points(), EMAN::Util::mul_img(), EMAN::Util::mul_scalar(), EMAN::Util::muln_img(), mult(), mult_complex_efficient(), mult_radial(), EMAN::Util::mult_scalar(), EMAN::Util::Normalize_ring(), operator *=(), operator+=(), operator-=(), operator/=(), EMAN::Util::pack_complex_to_real(), EMAN::Util::pad(), EMAN::PointArray::pdb2mrc_by_summation(), EMAN::periodogram(), phase(), power(), EMAN::BinarySkeletonizerProcessor::process(), EMAN::DirectionalSumProcessor::process(), EMAN::BooleanShrinkProcessor::process(), EMAN::MeanShrinkProcessor::process(), EMAN::FFTResampleProcessor::process(), EMAN::MedianShrinkProcessor::process(), EMAN::BinaryOperateProcessor< Type >::process_inplace(), EMAN::BinarySkeletonizerProcessor::process_inplace(), EMAN::TomoTiltEdgeMaskProcessor::process_inplace(), EMAN::ConvolutionProcessor::process_inplace(), EMAN::ClampingProcessor::process_inplace(), EMAN::Rotate180Processor::process_inplace(), EMAN::TransformProcessor::process_inplace(), EMAN::MirrorProcessor::process_inplace(), EMAN::RadialProcessor::process_inplace(), EMAN::RampProcessor::process_inplace(), EMAN::TestImageCylinder::process_inplace(), EMAN::TestImageNoiseGauss::process_inplace(), EMAN::TestImageNoiseUniformRand::process_inplace(), EMAN::TestImageEllipse::process_inplace(), EMAN::TestImageHollowEllipse::process_inplace(), EMAN::TestImageCirclesphere::process_inplace(), EMAN::TestImageSquarecube::process_inplace(), EMAN::TestImageSinewaveCircular::process_inplace(), EMAN::TestImageSinewave::process_inplace(), EMAN::TestImageSphericalWave::process_inplace(), EMAN::TestImagePureGaussian::process_inplace(), EMAN::TestImageScurve::process_inplace(), EMAN::TestImageAxes::process_inplace(), EMAN::TestImageGradient::process_inplace(), EMAN::TestImageGaussian::process_inplace(), EMAN::IterBinMaskProcessor::process_inplace(), EMAN::AutoMask3D2Processor::process_inplace(), EMAN::AutoMask3DProcessor::process_inplace(), EMAN::SmartMaskProcessor::process_inplace(), EMAN::CoordinateMaskFileProcessor::process_inplace(), EMAN::AddMaskShellProcessor::process_inplace(), EMAN::AddRandomNoiseProcessor::process_inplace(), EMAN::AutoMask2DProcessor::process_inplace(), EMAN::AddNoiseProcessor::process_inplace(), EMAN::FlipProcessor::process_inplace(), EMAN::RotationalSubstractProcessor::process_inplace(), EMAN::RotationalAverageProcessor::process_inplace(), EMAN::BilateralProcessor::process_inplace(), EMAN::BinarizeFourierProcessor::process_inplace(), EMAN::NormalizeToLeastSquareProcessor::process_inplace(), EMAN::NormalizeRowProcessor::process_inplace(), EMAN::NormalizeByMassProcessor::process_inplace(), EMAN::NormalizeRampNormVar::process_inplace(), EMAN::NormalizeProcessor::process_inplace(), EMAN::ZeroEdgePlaneProcessor::process_inplace(), EMAN::ZeroEdgeRowProcessor::process_inplace(), EMAN::DecayEdgeProcessor::process_inplace(), EMAN::AverageXProcessor::process_inplace(), EMAN::MeanZeroEdgeProcessor::process_inplace(), EMAN::BeamstopProcessor::process_inplace(), EMAN::SigmaZeroEdgeProcessor::process_inplace(), EMAN::RealToFFTProcessor::process_inplace(), EMAN::VerticalStripeProcessor::process_inplace(), EMAN::GradientPlaneRemoverProcessor::process_inplace(), EMAN::GradientRemoverProcessor::process_inplace(), EMAN::BooleanShrinkProcessor::process_inplace(), EMAN::MeanShrinkProcessor::process_inplace(), EMAN::FFTResampleProcessor::process_inplace(), EMAN::MedianShrinkProcessor::process_inplace(), EMAN::CutoffBlockProcessor::process_inplace(), EMAN::DiffBlockProcessor::process_inplace(), EMAN::BoxStatProcessor::process_inplace(), EMAN::AreaProcessor::process_inplace(), EMAN::ComplexPixelProcessor::process_inplace(), EMAN::ToMinvalProcessor::process_inplace(), EMAN::WatershedProcessor::process_inplace(), EMAN::PaintProcessor::process_inplace(), EMAN::CoordinateProcessor::process_inplace(), EMAN::RealPixelProcessor::process_inplace(), EMAN::Wiener2DFourierProcessor::process_inplace(), EMAN::Wiener2DAutoAreaProcessor::process_inplace(), EMAN::LinearPyramidProcessor::process_inplace(), EMAN::AmpweightFourierProcessor::process_inplace(), EMAN::FourierAnlProcessor::process_inplace(), EMAN::FourierProcessor::process_inplace(), EMAN::ImageProcessor::process_inplace(), EMAN::ChaoProjector::project3d(), EMAN::FourierGriddingProjector::project3d(), EMAN::PawelProjector::project3d(), EMAN::GaussFFTProjector::project3d(), read_image(), real(), real2complex(), real2FH(), EMAN::Util::reconstitute_image_mask(), replace_amplitudes(), ri2ap(), ri2inten(), rotate_translate(), rotate_x(), rotavg(), rotavg_i(), EMAN::rsconvolution(), set_col(), EMAN::PointArray::set_from_density_map(), EMAN::Util::set_line(), set_row(), set_size(), EMAN::WienerFourierReconstructor::setup(), EMAN::FourierReconstructor::setup(), sqrt(), sub(), EMAN::Util::sub_fav(), EMAN::Util::sub_img(), EMAN::Util::subn_img(), subsquare(), symvol(), to_one(), to_value(), to_zero(), EMAN::Util::TwoDTestFunc(), uncut_slice(), unwrap(), unwrap_largerR(), EMAN::Util::update_fav(), EMAN::EMUtil::vertical_acf(), EMAN::Util::window(), EMAN::Util::WTF(), and EMAN::Util::WTM().

00397                                 : this method internally just calls the

void EMData::update_stat (  )  const [private]

Definition at line 2677 of file emdata.cpp.

References attr_dict, data, EMDATA_NEEDUPD, ENTERFUNC, EXITFUNC, flags, get_data(), is_complex(), is_ri(), max, min, nx, ny, nz, rot_fp, sqrt(), and v.

Referenced by get_attr(), get_attr_dict(), make_rotational_footprint(), make_rotational_footprint_cmc(), make_rotational_footprint_e1(), and write_image().

02678 {
02679         ENTERFUNC;
02680 //      printf("update stat %f %d\n",(float)attr_dict["mean"],flags);
02681         if (!(flags & EMDATA_NEEDUPD))
02682         {
02683                 EXITFUNC;
02684                 return;
02685         }
02686 
02687         float* data = get_data();
02688         float max = -FLT_MAX;
02689         float min = -max;
02690 
02691         double sum = 0;
02692         double square_sum = 0;
02693 
02694         int step = 1;
02695         if (is_complex() && !is_ri()) {
02696                 step = 2;
02697         }
02698 
02699         int n_nonzero = 0;
02700 
02701         //cout << "point 1" << endl;
02702         //cout << "size is " << nx << " " << ny << " " << nz << endl;
02703 
02704         size_t size = nx*ny*nz;
02705         for (size_t i = 0; i < size; i += step) {
02706                 float v = data[i];
02707         #ifdef _WIN32
02708                 max = _cpp_max(max,v);
02709                 min = _cpp_min(min,v);
02710         #else
02711                 max=std::max<float>(max,v);
02712                 min=std::min<float>(min,v);
02713         #endif  //_WIN32
02714                 sum += v;
02715                 square_sum += v * (double)(v);
02716                 if (v != 0) n_nonzero++;
02717         }
02718         //cout << "Point 2" << endl;
02719         size_t n = size / step;
02720         double mean = sum / n;
02721 
02722 #ifdef _WIN32
02723         float sigma = (float)std::sqrt( _cpp_max(0.0,(square_sum - sum*sum / n)/(n-1)));
02724         n_nonzero = _cpp_max(1,n_nonzero);
02725         double sigma_nonzero = std::sqrt( _cpp_max(0,(square_sum  - sum*sum/n_nonzero)/(n_nonzero-1)));
02726 #else
02727         float sigma = (float)std::sqrt(std::max<double>(0.0,(square_sum - sum*sum / n)/(n-1)));
02728         n_nonzero = std::max<int>(1,n_nonzero);
02729         double sigma_nonzero = std::sqrt(std::max<double>(0,(square_sum  - sum*sum/n_nonzero)/(n_nonzero-1)));
02730 #endif  //_WIN32
02731         double mean_nonzero = sum / n_nonzero; // previous version overcounted! G2
02732 
02733         attr_dict["minimum"] = min;
02734         attr_dict["maximum"] = max;
02735         attr_dict["mean"] = (float)(mean);
02736         attr_dict["sigma"] = (float)(sigma);
02737         attr_dict["square_sum"] = (float)(square_sum);
02738         attr_dict["mean_nonzero"] = (float)(mean_nonzero);
02739         attr_dict["sigma_nonzero"] = (float)(sigma_nonzero);
02740         attr_dict["is_complex"] = (int) is_complex();
02741         attr_dict["is_complex_ri"] = (int) is_ri();
02742 
02743         flags &= ~EMDATA_NEEDUPD;
02744 
02745         if (rot_fp != 0)
02746         {
02747                 delete rot_fp; rot_fp = 0;
02748         }
02749 
02750         EXITFUNC;
02751 //      printf("done stat %f %f %f\n",(float)mean,(float)max,(float)sigma);
02752 }

EMData * EMData::window_center ( int  l  ) 

Window the center of an image.

Often an image is padded with zeros for fourier interpolation. In that case the desired lxlxl volume (or lxl area) lies in the center of a larger volume (or area). This routine creates a new object that contains only the desired window. (This routine is a thin wrapper around get_clip.)

Parameters:
l Length of the window.
Returns:
An image object that has been windowed.

Definition at line 712 of file emdata.cpp.

References ENTERFUNC, EXITFUNC, get_clip(), get_ndim(), ImageDimensionException, ImageFormatException, is_complex(), is_fftodd(), is_fftpadded(), LOGERR, nx, ny, and nz.

00712                                    {
00713         ENTERFUNC;
00714         // sanity checks
00715         int n = nx;
00716         if (is_complex()) {
00717                 LOGERR("Need real-space data for window_center()");
00718                 throw ImageFormatException(
00719                         "Complex input image; real-space expected.");
00720         }
00721         if (is_fftpadded()) {
00722                 // image has been fft-padded, compute the real-space size
00723                 n -= (2 - int(is_fftodd()));
00724         }
00725         int corner = n/2 - l/2;
00726         int ndim = get_ndim();
00727         EMData* ret;
00728         switch (ndim) {
00729                 case 3:
00730                         if ((n != ny) || (n != nz)) {
00731                                 LOGERR("Need the real-space image to be cubic.");
00732                                 throw ImageFormatException(
00733                                                 "Need cubic real-space image.");
00734                         }
00735                         ret = get_clip(Region(corner, corner, corner, l, l, l));
00736                         break;
00737                 case 2:
00738                         if (n != ny) {
00739                                 LOGERR("Need the real-space image to be square.");
00740                                 throw ImageFormatException(
00741                                                 "Need square real-space image.");
00742                         }
00743                         //cout << "Using corner " << corner << endl;
00744                         ret = get_clip(Region(corner, corner, l, l));
00745                         break;
00746                 case 1:
00747                         ret = get_clip(Region(corner, l));
00748                         break;
00749                 default:
00750                         throw ImageDimensionException(
00751                                         "window_center only supports 1-d, 2-d, and 3-d images");
00752         }
00753         return ret;
00754         EXITFUNC;
00755 }

void EMData::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.

Parameters:
fsp The filename to write the image data to
loc Location to seek to in the file before writing (size_t)
area The image region you want to read, default 0 means read the whole image
file_nx Image x size.
file_ny Image y size.
file_nz Image z size.
Author:
Steve Ludtke
Date:
Mon Jun 23, 2008

Definition at line 239 of file emdata_metadata.cpp.

References FileAccessException, get_data(), nx, ny, nz, portable_fseek(), EMAN::EMUtil::process_region_io(), EMAN::ImageIO::READ_WRITE, and UnexpectedBehaviorException.

00239                                                                                                                         {
00240 
00241         if (area) {
00242                 struct stat fileinfo;
00243                 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");
00244         }
00245 
00246 
00247         FILE *f = 0;
00248         f=fopen(fsp.c_str(), "rb+");
00249         if (!f) f=fopen(fsp.c_str(), "wb");
00250         if (!f) throw FileAccessException(fsp);
00251         portable_fseek(f,loc,SEEK_SET);
00252         if (!area) {
00253                 if (fwrite(get_data(),nx*ny,nz*4,f)!=(size_t)(nz*4)) throw FileAccessException(fsp);
00254         } else {
00255                 int fnx = nx;
00256                 if (file_nx != 0) fnx = file_nx;
00257                 int fny = ny;
00258                 if (file_ny != 0) fny = file_ny;
00259                 int fnz = nz;
00260                 if (file_nz != 0) fnz = file_nz;
00261 
00262                 EMUtil::process_region_io(get_data(), f, ImageIO::READ_WRITE,
00263                                                                   0, 4,fnx,fny,fnz,area);
00264         }
00265         fclose(f);
00266 }

void EMData::write_image ( const string &  filename,
int  img_index = 0,
EMUtil::ImageType  imgtype = EMUtil::IMAGE_UNKNOWN,
bool  header_only = false,
const Region region = 0,
EMUtil::EMDataType  filestoragetype = EMUtil::EM_FLOAT,
bool  use_host_endian = true 
)

write the header and data out to an image.

If the img_index = -1, append the image to the given image file.

If the given image file already exists, this image format only stores 1 image, and no region is given, then truncate the image file to zero length before writing data out. For header writing only, no truncation happens.

If a region is given, then write a region only.

Parameters:
filename The image file name.
img_index The nth image to write as.
imgtype Write to the given image format type. if not specified, use the 'filename' extension to decide.
header_only To write only the header or both header and data.
region Define the region to write to.
filestoragetype The image data type used in the output file.
use_host_endian To write in the host computer byte order.
Exceptions:
ImageFormatException 
ImageWriteException 

Definition at line 129 of file emdata_io.cpp.

References attr_dict, changecount, ENTERFUNC, EXITFUNC, fft_shuffle(), EMAN::ImageIO::flush(), get_data(), EMAN::EMUtil::get_image_ext_type(), EMAN::EMUtil::get_imageio(), EMAN::EMUtil::IMAGE_LST, EMAN::EMUtil::IMAGE_LSTFAST, EMAN::EMUtil::IMAGE_PNG, EMAN::EMUtil::IMAGE_UNKNOWN, ImageFormatException, ImageWriteException, is_complex(), EMAN::Util::is_file_exist(), is_shuffled(), EMAN::ImageIO::is_single_image_format(), LOGVAR, nx, ny, nz, path, pathnum, EMAN::ImageIO::READ_ONLY, EMAN::ImageIO::READ_WRITE, UnexpectedBehaviorException, update_stat(), EMAN::ImageIO::write_data(), EMAN::ImageIO::write_header(), and EMAN::ImageIO::WRITE_ONLY.

Referenced by ali3d_d(), append_image(), bispecRotTransInvDirect(), bispecRotTransInvN(), EMAN::OptVarianceCmp::cmp(), EMAN::PCA::dopca_ooc(), EMAN::FourierReconstructor::finish(), main(), EMAN::TestUtil::make_image_file_by_mode(), EMAN::AutoMask3DProcessor::process_inplace(), EMAN::LocalNormProcessor::process_inplace(), EMAN::WatershedProcessor::process_inplace(), unified(), and write_lst().

00134 {
00135         ENTERFUNC;
00136 
00137         struct stat fileinfo;
00138         if ( region && stat(filename.c_str(),&fileinfo) != 0 ) throw UnexpectedBehaviorException("To write an image using a region the file must already exist and be the correct dimensions");
00139 
00140         if (is_complex() && is_shuffled())
00141                 fft_shuffle();
00142 
00143         if (imgtype == EMUtil::IMAGE_UNKNOWN) {
00144                 const char *ext = strrchr(filename.c_str(), '.');
00145                 if (ext) {
00146                         ext++;
00147                         imgtype = EMUtil::get_image_ext_type(ext);
00148                 }
00149         }
00150         ImageIO::IOMode rwmode = ImageIO::READ_WRITE;
00151 
00152         //set "nx", "ny", "nz" and "changecount" in attr_dict, since they are taken out of attribute dictionary
00153         attr_dict["nx"] = nx;
00154         attr_dict["ny"] = ny;
00155         attr_dict["nz"] = nz;
00156         attr_dict["changecount"] = changecount;
00157 
00158         if (Util::is_file_exist(filename)) {
00159                 LOGVAR("file exists");
00160                 if (!header_only && region == 0) {
00161                         ImageIO * tmp_imageio = EMUtil::get_imageio(filename, ImageIO::READ_ONLY,
00162                                                                                                                 imgtype);
00163                         if (tmp_imageio->is_single_image_format()) {
00164                                 rwmode = ImageIO::WRITE_ONLY;
00165                         }
00166 #ifndef IMAGEIO_CACHE
00167                         if( tmp_imageio )
00168                         {
00169                                 delete tmp_imageio;
00170                                 tmp_imageio = 0;
00171                         }
00172 #endif
00173                 }
00174         }
00175         LOGVAR("getimageio %d",rwmode);
00176         ImageIO *imageio = EMUtil::get_imageio(filename, rwmode, imgtype);
00177         if (!imageio) {
00178                 throw ImageFormatException("cannot create an image io");
00179         }
00180         else {
00181                 update_stat();
00182                 /* Let each image format decide how to deal with negative image_index*/
00183 //              if (img_index < 0) {
00184 //                      img_index = imageio->get_nimg();
00185 //              }
00186                 LOGVAR("header write %d",img_index);
00187                 int err = imageio->write_header(attr_dict, img_index, region, filestoragetype,
00188                                                                                 use_host_endian);
00189                 if (err) {
00190                         throw ImageWriteException(filename, "imageio write header failed");
00191                 }
00192                 else {
00193                         if (!header_only) {
00194                                 if (imgtype == EMUtil::IMAGE_LST) {
00195                                         const char *reffile = attr_dict["LST.reffile"];
00196                                         if (strcmp(reffile, "") == 0) {
00197                                                 reffile = path.c_str();
00198                                         }
00199                                         int refn = attr_dict["LST.refn"];
00200                                         if (refn < 0) {
00201                                                 refn = pathnum;
00202                                         }
00203 
00204                                         const char *comment = attr_dict["LST.comment"];
00205                                         char *lstdata = new char[1024];
00206                                         sprintf(lstdata, "%d\t%s", refn, reffile);
00207                                         if(strcmp(comment, "") != 0) {
00208                                                 sprintf(lstdata+strlen(lstdata), "\t%s\n", comment);
00209                                         }
00210                                         else {
00211                                                 strcat(lstdata, "\n");
00212                                         }
00213                                         err = imageio->write_data((float*)lstdata, img_index,
00214                                                                                           region, filestoragetype, use_host_endian);
00215                                         if( lstdata )
00216                                         {
00217                                                 delete [] lstdata;
00218                                                 lstdata = 0;
00219                                         }
00220                                 }
00221                                 if (imgtype == EMUtil::IMAGE_LSTFAST) {
00222                                         const char *reffile = attr_dict["LST.reffile"];
00223                                         if (strcmp(reffile, "") == 0) {
00224                                                 reffile = path.c_str();
00225                                         }
00226                                         int refn = attr_dict["LST.refn"];
00227                                         if (refn < 0) {
00228                                                 refn = pathnum;
00229                                         }
00230 
00231                                         const char *comment = attr_dict["LST.comment"];
00232                                         char *lstdata = new char[1024];
00233                                         sprintf(lstdata, "%d\t%s", refn, reffile);
00234                                         if(strcmp(comment, "") != 0) {
00235                                                 sprintf(lstdata+strlen(lstdata), "\t%s\n", comment);
00236                                         }
00237                                         else {
00238                                                 strcat(lstdata, "\n");
00239                                         }
00240                                         err = imageio->write_data((float*)lstdata, img_index,
00241                                                                                           region, filestoragetype, use_host_endian);
00242                                         if( lstdata )
00243                                         {
00244                                                 delete [] lstdata;
00245                                                 lstdata = 0;
00246                                         }
00247                                 }
00248                                 else {
00249                                         err = imageio->write_data(get_data(), img_index, region, filestoragetype,
00250                                                                                           use_host_endian);
00251                                 }
00252                                 if (err) {
00253                                         imageio->flush();
00254                                         throw ImageWriteException(filename, "imageio write data failed");
00255                                 }
00256                         }
00257                 }
00258         }
00259         //PNG image already do cleaning in write_data function.
00260         if (!(imgtype == EMUtil::IMAGE_PNG)) {
00261                 imageio->flush();
00262         }
00263 
00264 #ifndef IMAGEIO_CACHE
00265         if( imageio )
00266         {
00267                 delete imageio;
00268                 imageio = 0;
00269         }
00270 #endif
00271 
00272 
00273 
00274         EXITFUNC;
00275 }

void EMData::write_lst ( const string &  filename,
const string &  reffile = "",
int  refn = -1,
const string &  comment = "" 
)

Append data to a LST image file.

Parameters:
filename The LST image file name.
reffile Reference file name.
refn The reference file number.
comment The comment to the added reference file.
See also:
lstio.h

Definition at line 287 of file emdata_io.cpp.

References attr_dict, ENTERFUNC, EXITFUNC, EMAN::EMUtil::IMAGE_LST, and write_image().

00289 {
00290         ENTERFUNC;
00291         attr_dict["LST.reffile"] = reffile;
00292         attr_dict["LST.refn"] = refn;
00293         attr_dict["LST.comment"] = comment;
00294         write_image(filename, -1, EMUtil::IMAGE_LST, false);
00295         EXITFUNC;
00296 }

vector< Dict > EMData::xform_align_nbest ( const string &  aligner_name,
EMData to_img,
const Dict params = Dict(),
const unsigned int  nsoln = 1,
const string &  cmp_name = "dot",
const Dict cmp_params = Dict() 
)

Align this image with another image, return the parameters of the "n best" solutions See Aligner::xform_align_nbest for more comments.

Parameters:
aligner_name Alignment algorithm name.
to_img The image 'this' image aligns to.
params Alignment algorithm parameters in a keyed dictionary.
nsoln the number of solutions you want to receive in the return vector.
cmp_name Comparison algorithm used in alignment.
cmp_params Parameter dictionary for comparison algorithm.
Exceptions:
NotExistingObjectError If the alignment algorithm doesn't exist.
Returns:
an ordered vector of Dicts of length nsoln. The Dicts in the vector have keys "score" (i.e. correlation score) and "xform.align3d" (Transform containing the alignment)

Definition at line 140 of file emdata_modular.cpp.

References ENTERFUNC, and EMAN::Aligner::xform_align_nbest().

00143 {
00144         ENTERFUNC;
00145         Aligner *a = Factory < Aligner >::get(aligner_name, params);
00146         vector<Dict> result;
00147         if (a) {
00148                 result = a->xform_align_nbest(this,to_img,nsoln,cmp_name,cmp_params);
00149         }
00150 
00151         return result;
00152 }

void EMData::zero_corner_circulant ( const int  radius = 0  ) 

Zero the pixels in the bottom left corner of the image If radius is greater than 1, than circulant zeroing occurs assuming that the center of operation starts in the bottom left corner and proceed outwards to the NE and backwards in a circulant fashion towards the SW.

Intended to zero the area corresponding to the middle of the image, as generated by calc_ccf

Parameters:
radius the radius to the zeroing operation
Exceptions:
ImageDimensionException if nx > 1 and nx < 2*radius + 1
ImageDimensionException if ny > 1 and ny < 2*radius + 1
ImageDimensionException if nz > 1 and nz < 2*radius + 1

Definition at line 1387 of file emdata.cpp.

References get_value_at_wrap(), ImageDimensionException, nx, ny, nz, x, and y.

Referenced by EMAN::TranslationalAligner::align().

01388 {
01389         if ( nz > 1 && nz < (2*radius+1) ) throw ImageDimensionException("Error: cannot zero corner - nz is too small");
01390         if ( ny > 1 && ny < (2*radius+1) ) throw ImageDimensionException("Error: cannot zero corner - ny is too small");
01391         if ( nx > 1 && nx < (2*radius+1) ) throw ImageDimensionException("Error: cannot zero corner - nx is too small");
01392 
01393         int it_z = radius;
01394         int it_y = radius;
01395         int it_x = radius;
01396 
01397         if ( nz == 1 ) it_z = 0;
01398         if ( ny == 1 ) it_y = 0;
01399         if ( nx == 1 ) it_z = 0;
01400 
01401         if ( nz == 1 && ny == 1 )
01402         {
01403                 for ( int x = -it_x; x <= it_x; ++x )
01404                         get_value_at_wrap(x) = 0;
01405 
01406         }
01407         else if ( nz == 1 )
01408         {
01409                 for ( int y = -it_y; y <= it_y; ++y)
01410                         for ( int x = -it_x; x <= it_x; ++x )
01411                                 get_value_at_wrap(x,y) = 0;
01412         }
01413         else
01414         {
01415                 for( int z = -it_z; z <= it_z; ++z )
01416                         for ( int y = -it_y; y <= it_y; ++y)
01417                                 for ( int x = -it_x; x < it_x; ++x )
01418                                         get_value_at_wrap(x,y,z) = 0;
01419 
01420         }
01421 
01422 }


Friends And Related Function Documentation

friend class GLUtil [friend]

Definition at line 90 of file emdata.h.


Member Data Documentation

Vec3f EMAN::EMData::all_translation [private]

translation from the original location

Definition at line 3799 of file emdata.h.

Referenced by copy_head(), operator=(), rotate_translate(), and translate().

Dict EMAN::EMData::attr_dict [mutable, private]

to store all image header info

Definition at line 3778 of file emdata.h.

Referenced by copy_head(), del_attr(), depad(), depad_corner(), EMData(), get_attr(), get_attr_default(), get_attr_dict(), get_clip(), get_ctf(), get_top_half(), nn(), nn_ctf(), nn_ctf_applied(), nn_SSNR(), nn_SSNR_ctf(), operator=(), read_image(), rotate_translate(), save_byteorder_to_dict(), scale_pixel(), set_attr(), set_attr_dict_explicit(), set_attr_python(), set_ctf(), set_xyz_origin(), symplane0(), symplane0_ctf(), symplane1(), symplane2(), update_stat(), write_image(), and write_lst().

int EMAN::EMData::changecount [private]

Definition at line 3791 of file emdata.h.

Referenced by get_attr(), get_attr_dict(), operator=(), and write_image().

int EMAN::EMData::flags [mutable, private]

flags

Definition at line 3789 of file emdata.h.

Referenced by copy_head(), EMData(), operator=(), and update_stat().

int EMAN::EMData::nx [private]

image size

Definition at line 3793 of file emdata.h.

Referenced by absi(), add(), add_complex_at(), add_incoherent(), addsquare(), amplitude(), ap2ri(), apply_radial_func(), average_circ_sub(), calc_az_dist(), calc_ccf(), calc_ccfx(), calc_center_density(), calc_center_of_mass(), calc_dist(), calc_fast_sigma_image(), calc_flcf(), calc_fourier_shell_correlation(), calc_highest_locations(), calc_hist(), calc_max_index(), calc_max_location(), calc_min_index(), calc_min_location(), calc_n_highest_locations(), calc_radial_dist(), calc_sigma_diff(), cconj(), center_origin(), center_origin_fft(), center_origin_yz(), clip_inplace(), cog(), common_lines(), conjg(), copy_head(), cut_slice(), delete_disconnected_regions(), depad(), depad_corner(), div(), divkbsinh(), do_fft(), do_fft_inplace(), do_ift(), do_ift_inplace(), do_radon(), dot_rotate_translate(), downsample(), EMData(), extract_plane(), extractline(), extractpoint(), fft_shuffle(), FH2F(), filter_by_image(), find_3d_threshold(), Four_ds(), Four_shuf_ds_cen_us(), fouriergridrot2d(), fouriergridrot_shift2d(), FourInterpol(), FourTruncate(), get_2dcview(), get_2dview(), get_3dcview(), get_3dcviewptr(), get_3dview(), get_attr(), get_attr_dict(), get_circle_mean(), get_clip(), get_col(), get_complex_at(), get_complex_index(), get_data_pickle(), get_edge_mean(), get_fft_amplitude(), get_fft_amplitude2D(), get_fft_phase(), get_pixel_conv(), get_pixel_conv7(), get_pixel_filtered(), get_pow(), get_rotated_clip(), get_row(), get_top_half(), get_value_at_wrap(), getconvpt2d_kbi0(), helicise(), imag(), insert_clip(), insert_scaled_sum(), little_big_dot(), make_rotational_footprint_cmc(), make_rotational_footprint_e1(), max_search(), mult(), mult_complex_efficient(), mult_radial(), nn_SSNR(), nn_SSNR_ctf(), norm_pad(), operator=(), operator==(), pad_corner(), peak_ccf(), peak_search(), phase(), phase_cog(), print_image(), read_data(), read_image(), real(), real2complex(), real2FH(), render_amp24(), render_ap24(), replace_amplitudes(), ri2ap(), ri2inten(), rot_scale_conv(), rot_scale_conv7(), rot_scale_conv_new(), rot_scale_conv_new_background(), rot_scale_trans(), rot_scale_trans2D(), rot_scale_trans2D_background(), rot_scale_trans_background(), rotate_translate(), rotate_x(), rotavg(), rotavg_i(), set_attr(), set_attr_dict(), set_attr_python(), set_col(), set_complex_at(), set_data_pickle(), set_row(), set_size(), setup4slice(), sget_value_at(), shuffle_pad_corner(), sub(), subsquare(), symvol(), uncut_slice(), unwrap(), update_stat(), window_center(), write_data(), write_image(), and zero_corner_circulant().

int EMAN::EMData::nxy [private]

Definition at line 3793 of file emdata.h.

Referenced by add_complex_at(), calc_center_of_mass(), calc_highest_locations(), calc_max_location(), calc_min_location(), calc_n_highest_locations(), get_complex_at(), get_complex_index(), get_edge_mean(), get_value_at_wrap(), mult_complex_efficient(), rotate_translate(), set_complex_at(), set_size(), setup4slice(), and sget_value_at().

size_t EMAN::EMData::nxyz [private]

Definition at line 3794 of file emdata.h.

Referenced by add(), add_complex_at(), addsquare(), div(), get_complex_index(), log(), log10(), mult(), mult_complex_efficient(), norm_pad(), set_size(), sqrt(), sub(), subsquare(), and to_value().

int EMAN::EMData::ny [private]

Definition at line 3793 of file emdata.h.

Referenced by absi(), add(), add_complex_at(), add_incoherent(), addsquare(), amplitude(), ap2ri(), apply_radial_func(), average_circ_sub(), calc_az_dist(), calc_ccf(), calc_ccfx(), calc_center_density(), calc_center_of_mass(), calc_dist(), calc_fast_sigma_image(), calc_flcf(), calc_fourier_shell_correlation(), calc_highest_locations(), calc_hist(), calc_max_index(), calc_max_location(), calc_min_index(), calc_min_location(), calc_n_highest_locations(), calc_radial_dist(), calc_sigma_diff(), cconj(), center_origin(), center_origin_fft(), center_origin_yz(), clip_inplace(), cog(), common_lines(), conjg(), copy_head(), cut_slice(), delete_disconnected_regions(), depad(), depad_corner(), div(), divkbsinh(), do_fft(), do_fft_inplace(), do_ift(), do_ift_inplace(), do_radon(), dot_rotate_translate(), downsample(), EMData(), extract_plane(), extractline(), extractpoint(), fft_shuffle(), FH2F(), filter_by_image(), find_3d_threshold(), Four_ds(), Four_shuf_ds_cen_us(), fouriergridrot2d(), fouriergridrot_shift2d(), FourInterpol(), FourTruncate(), get_2dcview(), get_2dview(), get_3dcview(), get_3dcviewptr(), get_3dview(), get_attr(), get_attr_dict(), get_circle_mean(), get_clip(), get_col(), get_complex_at(), get_complex_index(), get_data_pickle(), get_edge_mean(), get_fft_amplitude(), get_fft_amplitude2D(), get_fft_phase(), get_pixel_conv(), get_pixel_conv7(), get_pixel_filtered(), get_pow(), get_rotated_clip(), get_top_half(), get_value_at_wrap(), getconvpt2d_kbi0(), helicise(), imag(), insert_clip(), insert_scaled_sum(), little_big_dot(), make_rotational_footprint_cmc(), make_rotational_footprint_e1(), max_search(), mult(), mult_radial(), nn(), nn_ctf(), nn_ctf_applied(), nn_SSNR(), nn_SSNR_ctf(), norm_pad(), operator=(), operator==(), pad_corner(), peak_ccf(), peak_search(), phase(), phase_cog(), print_image(), read_data(), read_image(), real(), real2complex(), real2FH(), render_amp24(), render_ap24(), replace_amplitudes(), ri2ap(), ri2inten(), rot_scale_conv(), rot_scale_conv7(), rot_scale_conv_new(), rot_scale_conv_new_background(), rot_scale_trans(), rot_scale_trans2D(), rot_scale_trans2D_background(), rot_scale_trans_background(), rotate_translate(), rotate_x(), rotavg(), rotavg_i(), set_attr(), set_attr_dict(), set_attr_python(), set_col(), set_complex_at(), set_data_pickle(), set_size(), setup4slice(), sget_value_at(), shuffle_pad_corner(), sub(), subsquare(), symvol(), uncut_slice(), unwrap(), update_stat(), window_center(), write_data(), write_image(), and zero_corner_circulant().

int EMAN::EMData::nz [private]

Definition at line 3793 of file emdata.h.

Referenced by absi(), add(), add_complex_at(), add_incoherent(), addsquare(), amplitude(), ap2ri(), apply_radial_func(), average_circ_sub(), calc_ccf(), calc_ccfx(), calc_center_density(), calc_center_of_mass(), calc_fast_sigma_image(), calc_flcf(), calc_fourier_shell_correlation(), calc_highest_locations(), calc_hist(), calc_max_location(), calc_min_location(), calc_n_highest_locations(), calc_radial_dist(), calc_sigma_diff(), cconj(), center_origin(), center_origin_fft(), center_origin_yz(), clip_inplace(), cog(), conjg(), copy_head(), delete_disconnected_regions(), depad(), depad_corner(), div(), divkbsinh(), do_fft(), do_fft_inplace(), do_ift(), do_ift_inplace(), downsample(), EMData(), extract_plane(), fft_shuffle(), FH2F(), filter_by_image(), find_3d_threshold(), Four_ds(), Four_shuf_ds_cen_us(), FourInterpol(), FourTruncate(), get_3dcview(), get_3dcviewptr(), get_3dview(), get_attr(), get_attr_dict(), get_circle_mean(), get_clip(), get_complex_at(), get_complex_index(), get_data_pickle(), get_edge_mean(), get_fft_amplitude(), get_fft_amplitude2D(), get_fft_phase(), get_pixel_conv(), get_pixel_conv7(), get_pow(), get_rotated_clip(), get_top_half(), get_value_at_wrap(), helicise(), imag(), insert_clip(), little_big_dot(), make_rotational_footprint_cmc(), make_rotational_footprint_e1(), max_search(), mult(), mult_radial(), nn_SSNR(), nn_SSNR_ctf(), norm_pad(), operator=(), operator==(), peak_search(), phase(), phase_cog(), print_image(), read_data(), read_image(), real(), real2complex(), real2FH(), replace_amplitudes(), ri2ap(), ri2inten(), rot_scale_conv(), rot_scale_conv7(), rot_scale_conv_new(), rot_scale_conv_new_background(), rot_scale_trans(), rot_scale_trans2D(), rot_scale_trans2D_background(), rot_scale_trans_background(), rotate_translate(), rotavg(), rotavg_i(), set_attr(), set_attr_dict(), set_attr_python(), set_complex_at(), set_data_pickle(), set_size(), setup4slice(), sget_value_at(), sub(), subsquare(), symvol(), update_stat(), window_center(), write_data(), write_image(), and zero_corner_circulant().

string EMAN::EMData::path [private]

Definition at line 3802 of file emdata.h.

Referenced by copy_head(), get_clip(), operator=(), and write_image().

int EMAN::EMData::pathnum [private]

Definition at line 3803 of file emdata.h.

Referenced by copy_head(), get_clip(), operator=(), and write_image().

float* EMAN::EMData::rdata [mutable, private]

image real data

Definition at line 3780 of file emdata.h.

Referenced by add_complex_at(), clip_inplace(), cog(), do_fft_inplace(), do_ift(), EMData(), find_3d_threshold(), free_memory(), get_complex_at(), operator=(), phase_cog(), rotate_translate(), set_complex_at(), and set_size().

EMData* EMAN::EMData::rot_fp [mutable, private]

This is a cached rotational footprint, can save much time.

Definition at line 3806 of file emdata.h.

Referenced by EMData(), free_memory(), make_rotational_footprint(), make_rotational_footprint_cmc(), make_rotational_footprint_e1(), operator=(), and update_stat().

float* EMAN::EMData::supp [private]

supplementary data array

Definition at line 3782 of file emdata.h.

Referenced by free_memory(), set_size(), set_supp_pickle(), and setup4slice().

int EMData::totalalloc = 0 [static]

Definition at line 3085 of file emdata.h.

Referenced by EMData(), and ~EMData().

int EMAN::EMData::xoff [private]

array index offsets

Definition at line 3796 of file emdata.h.

Referenced by operator=().

int EMAN::EMData::yoff [private]

Definition at line 3796 of file emdata.h.

Referenced by operator=().

int EMAN::EMData::zoff [private]

Definition at line 3796 of file emdata.h.

Referenced by operator=().


The documentation for this class was generated from the following files:
Generated on Tue May 25 17:15:57 2010 for EMAN2 by  doxygen 1.4.7