Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

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

04563                 {
04564                         return "flip an image around an axis.";
04565                 }

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

References NAME.

04546                 {
04547                         return NAME;
04548                 }

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

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

04556                 {
04557                         TypeDict d;
04558                         d.put("axis", EMObject::STRING, "'x', 'y', or 'z' axis. 'x' means horizonal flip; 'y' means vertical flip;");
04559                         return d;
04560                 }

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

Definition at line 4550 of file processor.h.

04551                 {
04552                         return new FlipProcessor();
04553                 }

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 4353 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.

04354 {
04355         ENTERFUNC;
04356         if (!image) {
04357                 LOGWARN("NULL Image");
04358                 return;
04359         }
04360         string axis = (const char*)params["axis"];
04361 #ifdef EMAN2_USING_CUDA
04362         if (image->gpu_operation_preferred()) {
04363                 float array[12] = {1.0, 0.0, 0.0, 0.0,
04364                                                    0.0, 1.0, 0.0, 0.0,
04365                                                    0.0, 0.0, 1.0, 0.0};
04366                 if (axis == "x" || axis == "X") {               // horizontal flip
04367                         array[0] = -1.0;
04368                 }else if (axis == "y" || axis == "Y") {         // vertical flip
04369                         array[5] = -1.0;
04370                 }
04371                 else if (axis == "z" || axis == "Z") {          // vertical flip
04372                         array[10] = -1.0;
04373                 }
04374                 Transform t(array);
04375                 Dict params("transform",(Transform*)&t);
04376                 image->process_inplace("xform",params);
04377                 EXITFUNC;
04378                 return;
04379         }
04380 #endif
04381 
04382 
04383         float *d = image->get_data();
04384         int nx = image->get_xsize();
04385         int ny = image->get_ysize();
04386         int nz = image->get_zsize();
04387 
04388         size_t nxy = nx * ny;
04389 
04390 
04391         // Note in all cases the origin is nx/2, ny/2 and nz/2
04392         // This means when flipping even sized dimensions that some pixels are redundant.
04393         // Here redundant pixels are set to zero, however, should this change to something
04394         // like the mean.
04395         if (axis == "x" || axis == "X") {               // Horizontal flip
04396                 int offset = (nx%2 == 0);
04397                 size_t idx1, idx2;
04398                 for(int z = 0; z < nz; ++z) {
04399                         for(int y = 0; y < ny; ++y) {
04400                                 if (offset != 0 ) {
04401                                         idx1 = z*nxy + y*nx;
04402                                         d[idx1] = 0; // Here's where you'd make it the mean
04403                                 }
04404                                 for(int x = offset; x < nx / 2; ++x) {
04405                                         idx1 = z*nxy + y*nx + x;
04406                                         idx2 = z*nxy + y*nx + (nx-x-1+offset);
04407                                         std::swap(d[idx1], d[idx2]);
04408                                 }
04409 
04410                         }
04411                 }
04412         }
04413 
04414         else if (axis == "y" || axis == "Y") {          // vertical flip
04415                 int offset = (ny%2 == 0);
04416                 for(int z=0; z<nz; ++z) {
04417                         if (offset != 0) {
04418                                 std::fill(d+z*nxy,d+z*nxy+nx,0); // So if we have change it to the mean it's easy to do so. (instead of using memset)
04419                         }
04420                         for(int y=offset; y<ny/2; ++y) {
04421                                 for(int x=0; x<nx; ++x) {
04422                                         std::swap(d[z*nxy + y*nx +x], d[z*nxy + (ny -y -1+offset)*nx +x]);
04423                                 }
04424                         }
04425                 }
04426         }
04427         else if (axis == "z" || axis == "Z") {          //z axis flip
04428                 int offset = (nz%2 == 0);
04429                 if (offset != 0) {
04430                         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)
04431                 }
04432                 size_t idx1, idx2;
04433                 for(int z=offset; z<nz/2; ++z) {
04434                         for(int y=0; y<ny; ++y) {
04435                                 for(int x=0; x<nx; ++x) {
04436                                         idx1 = z*nxy + y*nx + x;
04437                                         idx2 = (nz-z-1+offset)*nxy + y*nx + x;
04438                                         std::swap(d[idx1], d[idx2]);
04439                                 }
04440                         }
04441                 }
04442         }
04443 
04444         image->update();
04445         EXITFUNC;
04446 }


Member Data Documentation

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

Definition at line 4567 of file processor.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Mon Jul 19 13:07:06 2010 for EMAN2 by  doxygen 1.4.4