EMAN::FlipProcessor Class Reference

flip 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]
List of all members.

Public Member Functions

virtual void process_inplace (EMData *image)
 To process an image in-place.
virtual string get_name () const
 Get the processor's name.
virtual TypeDict get_param_types () const
 Get processor parameter information in a dictionary.
virtual string get_desc () const
 Get the descrition of this specific processor.

Static Public Member Functions

static ProcessorNEW ()

Static Public Attributes

static const string NAME = "xform.flip"

Detailed Description

flip an image around an axis

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

Definition at line 4581 of file processor.h.


Member Function Documentation

virtual string EMAN::FlipProcessor::get_desc (  )  const [inline, virtual]

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 4603 of file processor.h.

04604                 {
04605                         return "Mirrors an image along the specified axis, preserving the center. This will introduce a plane of 0's for even box sizes. Use 'xform.mirror' processor to avoid the zero plane, but not preserve the center.";
04606                 }

virtual string EMAN::FlipProcessor::get_name (  )  const [inline, virtual]

Get the processor's name.

Each processor is identified by a unique name.

Returns:
The processor's name.

Implements EMAN::Processor.

Definition at line 4586 of file processor.h.

References NAME.

04587                 {
04588                         return NAME;
04589                 }

virtual TypeDict EMAN::FlipProcessor::get_param_types (  )  const [inline, virtual]

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 4596 of file processor.h.

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

04597                 {
04598                         TypeDict d;
04599                         d.put("axis", EMObject::STRING, "'x', 'y', or 'z' axis.");
04600                         return d;
04601                 }

static Processor* EMAN::FlipProcessor::NEW (  )  [inline, static]

Definition at line 4591 of file processor.h.

04592                 {
04593                         return new FlipProcessor();
04594                 }

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:
image The image to be processed.

Implements EMAN::Processor.

Definition at line 4393 of file processor.cpp.

References ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), LOGWARN, EMAN::Processor::params, EMAN::EMData::process_inplace(), t, EMAN::EMData::update(), and x.

04394 {
04395         ENTERFUNC;
04396         if (!image) {
04397                 LOGWARN("NULL Image");
04398                 return;
04399         }
04400         string axis = (const char*)params["axis"];
04401         
04402 #ifdef EMAN2_USING_CUDA
04403         if (EMData::usecuda == 1 && image->getcudarwdata()) {
04404                 //cout << "flip processor" << endl;
04405                 float array[12] = {1.0, 0.0, 0.0, 0.0,
04406                                                    0.0, 1.0, 0.0, 0.0,
04407                                                    0.0, 0.0, 1.0, 0.0};
04408                 if (axis == "x" || axis == "X") {               // horizontal flip
04409                         array[0] = -1.0;
04410                 }else if (axis == "y" || axis == "Y") {         // vertical flip
04411                         array[5] = -1.0;
04412                 }
04413                 else if (axis == "z" || axis == "Z") {          // vertical flip
04414                         array[10] = -1.0;
04415                 }
04416                 Transform t(array);
04417                 Dict params("transform",(Transform*)&t);
04418                 image->process_inplace("xform",params);
04419 
04420                 EXITFUNC;
04421                 return;
04422         }
04423 #endif
04424 
04425 
04426         float *d = image->get_data();
04427         int nx = image->get_xsize();
04428         int ny = image->get_ysize();
04429         int nz = image->get_zsize();
04430 
04431         size_t nxy = nx * ny;
04432 
04433 
04434         // Note in all cases the origin is nx/2, ny/2 and nz/2
04435         // This means when flipping even sized dimensions that some pixels are redundant.
04436         // Here redundant pixels are set to zero, however, should this change to something
04437         // like the mean.
04438         if (axis == "x" || axis == "X") {               // Horizontal flip
04439                 int offset = (nx%2 == 0);
04440                 size_t idx1, idx2;
04441                 for(int z = 0; z < nz; ++z) {
04442                         for(int y = 0; y < ny; ++y) {
04443                                 if (offset != 0 ) {
04444                                         idx1 = z*nxy + y*nx;
04445                                         d[idx1] = 0; // Here's where you'd make it the mean
04446                                 }
04447                                 for(int x = offset; x < nx / 2; ++x) {
04448                                         idx1 = z*nxy + y*nx + x;
04449                                         idx2 = z*nxy + y*nx + (nx-x-1+offset);
04450                                         std::swap(d[idx1], d[idx2]);
04451                                 }
04452 
04453                         }
04454                 }
04455         }
04456 
04457         else if (axis == "y" || axis == "Y") {          // vertical flip
04458                 int offset = (ny%2 == 0);
04459                 for(int z=0; z<nz; ++z) {
04460                         if (offset != 0) {
04461                                 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)
04462                         }
04463                         for(int y=offset; y<ny/2; ++y) {
04464                                 for(int x=0; x<nx; ++x) {
04465                                         std::swap(d[(size_t)z*nxy + y*nx +x], d[(size_t)z*nxy + (ny -y -1+offset)*nx +x]);
04466                                 }
04467                         }
04468                 }
04469         }
04470         else if (axis == "z" || axis == "Z") {          //z axis flip
04471                 int offset = (nz%2 == 0);
04472                 if (offset != 0) {
04473                         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)
04474                 }
04475                 size_t idx1, idx2;
04476                 for(int z=offset; z<nz/2; ++z) {
04477                         for(int y=0; y<ny; ++y) {
04478                                 for(int x=0; x<nx; ++x) {
04479                                         idx1 = (size_t)z*nxy + y*nx + x;
04480                                         idx2 = (size_t)(nz-z-1+offset)*nxy + y*nx + x;
04481                                         std::swap(d[idx1], d[idx2]);
04482                                 }
04483                         }
04484                 }
04485         }
04486 
04487         image->update();
04488         EXITFUNC;
04489 }


Member Data Documentation

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

Definition at line 4608 of file processor.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Tue Jun 11 12:44:19 2013 for EMAN2 by  doxygen 1.4.7