EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
EMAN::FlipProcessor Class Reference

flip/mirror an image around an axis More...

#include <processor.h>

Inheritance diagram for EMAN::FlipProcessor:
Inheritance graph
[legend]
Collaboration diagram for EMAN::FlipProcessor:
Collaboration graph
[legend]

Public Member Functions

virtual void process_inplace (EMData *image)
 To process an image in-place. More...
 
virtual string get_name () const
 Get the processor's name. More...
 
virtual TypeDict get_param_types () const
 Get processor parameter information in a dictionary. More...
 
virtual string get_desc () const
 Get the descrition of this specific processor. More...
 
- Public Member Functions inherited from EMAN::Processor
virtual ~Processor ()
 
virtual EMDataprocess (const EMData *const image)
 To proccess an image out-of-place. More...
 
virtual void process_list_inplace (vector< EMData * > &images)
 To process multiple images using the same algorithm. More...
 
virtual Dict get_params () const
 Get the processor parameters in a key/value dictionary. More...
 
virtual void set_params (const Dict &new_params)
 Set the processor parameters using a key/value dictionary. More...
 

Static Public Member Functions

static ProcessorNEW ()
 
- Static Public Member Functions inherited from EMAN::Processor
static string get_group_desc ()
 Get the description of this group of processors. More...
 
static void EMFourierFilterInPlace (EMData *fimage, Dict params)
 Compute a Fourier-filter processed image in place. More...
 
static EMDataEMFourierFilter (EMData *fimage, Dict params)
 Compute a Fourier-processor processed image without altering the original image. More...
 

Static Public Attributes

static const string NAME = "xform.flip"
 

Additional Inherited Members

- Public Types inherited from EMAN::Processor
enum  fourier_filter_types {
  TOP_HAT_LOW_PASS , TOP_HAT_HIGH_PASS , TOP_HAT_BAND_PASS , TOP_HOMOMORPHIC ,
  GAUSS_LOW_PASS , GAUSS_HIGH_PASS , GAUSS_BAND_PASS , GAUSS_INVERSE ,
  GAUSS_HOMOMORPHIC , BUTTERWORTH_LOW_PASS , BUTTERWORTH_HIGH_PASS , BUTTERWORTH_HOMOMORPHIC ,
  KAISER_I0 , KAISER_SINH , KAISER_I0_INVERSE , KAISER_SINH_INVERSE ,
  SHIFT , TANH_LOW_PASS , TANH_HIGH_PASS , TANH_HOMOMORPHIC ,
  TANH_BAND_PASS , RADIAL_TABLE , CTF_
}
 Fourier filter Processor type enum. More...
 
- Protected Attributes inherited from EMAN::Processor
Dict params
 

Detailed Description

flip/mirror an image around an axis

Parameters
axis'x', 'y', or 'z' axis. 'x' means horizonal flip; 'y' means vertical flip;

Definition at line 6396 of file processor.h.

Member Function Documentation

◆ get_desc()

virtual string EMAN::FlipProcessor::get_desc ( ) const
inlinevirtual

Get the descrition of this specific processor.

This function must be overwritten by a subclass.

Returns
The description of this processor.

Implements EMAN::Processor.

Definition at line 6418 of file processor.h.

6419 {
6420 return "Flips an image along the specified axis, preserving the center. This will introduce a plane of 0's for even box sizes. Use 'xform.reverse' processor to avoid the zero plane, but not preserve the center.";
6421 }

◆ get_name()

virtual string EMAN::FlipProcessor::get_name ( ) const
inlinevirtual

Get the processor's name.

Each processor is identified by a unique name.

Returns
The processor's name.

Implements EMAN::Processor.

Definition at line 6401 of file processor.h.

6402 {
6403 return NAME;
6404 }
static const string NAME
Definition: processor.h:6423

References NAME.

◆ get_param_types()

virtual TypeDict EMAN::FlipProcessor::get_param_types ( ) const
inlinevirtual

Get processor parameter information in a dictionary.

Each parameter has one record in the dictionary. Each record contains its name, data-type, and description.

Returns
A dictionary containing the parameter info.

Reimplemented from EMAN::Processor.

Definition at line 6411 of file processor.h.

6412 {
6413 TypeDict d;
6414 d.put("axis", EMObject::STRING, "'x', 'y', or 'z' axis.");
6415 return d;
6416 }
TypeDict is a dictionary to store <string, EMObject::ObjectType> pair.
Definition: emobject.h:305
void put(const string &key, EMObject::ObjectType o, const string &desc="")
Definition: emobject.h:330

References EMAN::TypeDict::put(), and EMAN::EMObject::STRING.

◆ NEW()

static Processor * EMAN::FlipProcessor::NEW ( )
inlinestatic

Definition at line 6406 of file processor.h.

6407 {
6408 return new FlipProcessor();
6409 }
flip/mirror an image around an axis
Definition: processor.h:6397

◆ process_inplace()

void FlipProcessor::process_inplace ( EMData image)
virtual

To process an image in-place.

For those processors which can only be processed out-of-place, override this function to just print out some error message to remind user call the out-of-place version.

Parameters
imageThe image to be processed.

Implements EMAN::Processor.

Definition at line 5755 of file processor.cpp.

5756{
5757 ENTERFUNC;
5758 if (!image) {
5759 LOGWARN("NULL Image");
5760 return;
5761 }
5762 string axis = (const char*)params["axis"];
5763
5764#ifdef EMAN2_USING_CUDA
5765 if (EMData::usecuda == 1 && image->getcudarwdata()) {
5766 //cout << "flip processor" << endl;
5767 float array[12] = {1.0, 0.0, 0.0, 0.0,
5768 0.0, 1.0, 0.0, 0.0,
5769 0.0, 0.0, 1.0, 0.0};
5770 if (axis == "x" || axis == "X") { // horizontal flip
5771 array[0] = -1.0;
5772 }else if (axis == "y" || axis == "Y") { // vertical flip
5773 array[5] = -1.0;
5774 }
5775 else if (axis == "z" || axis == "Z") { // vertical flip
5776 array[10] = -1.0;
5777 }
5778 Transform t(array);
5779 Dict params("transform",(Transform*)&t);
5780 image->process_inplace("xform",params);
5781
5782 EXITFUNC;
5783 return;
5784 }
5785#endif
5786
5787
5788 float *d = image->get_data();
5789 int nx = image->get_xsize();
5790 int ny = image->get_ysize();
5791 int nz = image->get_zsize();
5792
5793 size_t nxy = nx * ny;
5794
5795
5796 // Note in all cases the origin is nx/2, ny/2 and nz/2
5797 // This means when flipping even sized dimensions that some pixels are redundant.
5798 // Here redundant pixels are set to zero, however, should this change to something
5799 // like the mean.
5800 if (axis == "x" || axis == "X") { // Horizontal flip
5801 int offset = (nx%2 == 0);
5802 size_t idx1, idx2;
5803 for(int z = 0; z < nz; ++z) {
5804 for(int y = 0; y < ny; ++y) {
5805 if (offset != 0 ) {
5806 idx1 = z*nxy + y*nx;
5807 d[idx1] = 0; // Here's where you'd make it the mean
5808 }
5809 for(int x = offset; x < nx / 2; ++x) {
5810 idx1 = z*nxy + y*nx + x;
5811 idx2 = z*nxy + y*nx + (nx-x-1+offset);
5812 std::swap(d[idx1], d[idx2]);
5813 }
5814
5815 }
5816 }
5817 }
5818
5819 else if (axis == "y" || axis == "Y") { // vertical flip
5820 int offset = (ny%2 == 0);
5821 for(int z=0; z<nz; ++z) {
5822 if (offset != 0) {
5823 std::fill(d+z*nxy,d+(size_t)z*nxy+nx,0); // So if we have change it to the mean it's easy to do so. (instead of using memset)
5824 }
5825 for(int y=offset; y<ny/2; ++y) {
5826 for(int x=0; x<nx; ++x) {
5827 std::swap(d[(size_t)z*nxy + y*nx +x], d[(size_t)z*nxy + (ny -y -1+offset)*nx +x]);
5828 }
5829 }
5830 }
5831 }
5832 else if (axis == "z" || axis == "Z") { //z axis flip
5833 int offset = (nz%2 == 0);
5834 if (offset != 0) {
5835 std::fill(d,d+nxy,0);// So if we have change it to the mean it's easy to do so. (instead of using memset)
5836 }
5837 size_t idx1, idx2;
5838 for(int z=offset; z<nz/2; ++z) {
5839 for(int y=0; y<ny; ++y) {
5840 for(int x=0; x<nx; ++x) {
5841 idx1 = (size_t)z*nxy + y*nx + x;
5842 idx2 = (size_t)(nz-z-1+offset)*nxy + y*nx + x;
5843 std::swap(d[idx1], d[idx2]);
5844 }
5845 }
5846 }
5847 }
5848
5849 image->update();
5850 EXITFUNC;
5851}
Dict is a dictionary to store <string, EMObject> pair.
Definition: emobject.h:385
A Transform object is a somewhat specialized object designed specifically for EMAN2/Sparx storage of ...
Definition: transform.h:75
#define LOGWARN
Definition: log.h:53
#define ENTERFUNC
Definition: log.h:48
#define EXITFUNC
Definition: log.h:49
#define y(i, j)
Definition: projector.cpp:1516
#define x(i)
Definition: projector.cpp:1517

References ENTERFUNC, EXITFUNC, LOGWARN, EMAN::Processor::params, x, and y.

Member Data Documentation

◆ NAME

const string FlipProcessor::NAME = "xform.flip"
static

Definition at line 6423 of file processor.h.

Referenced by get_name().


The documentation for this class was generated from the following files: