EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes
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 4834 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 4856 of file processor.h.

                {
                        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.";
                }
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 4839 of file processor.h.

References NAME.

                {
                        return NAME;
                }
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 4849 of file processor.h.

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

                {
                        TypeDict d;
                        d.put("axis", EMObject::STRING, "'x', 'y', or 'z' axis.");
                        return d;
                }
static Processor* EMAN::FlipProcessor::NEW ( ) [inline, static]

Definition at line 4844 of file processor.h.

                {
                        return new FlipProcessor();
                }
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 4607 of file processor.cpp.

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

{
        ENTERFUNC;
        if (!image) {
                LOGWARN("NULL Image");
                return;
        }
        string axis = (const char*)params["axis"];

#ifdef EMAN2_USING_CUDA
        if (EMData::usecuda == 1 && image->getcudarwdata()) {
                //cout << "flip processor" << endl;
                float array[12] = {1.0, 0.0, 0.0, 0.0,
                                                   0.0, 1.0, 0.0, 0.0,
                                                   0.0, 0.0, 1.0, 0.0};
                if (axis == "x" || axis == "X") {               // horizontal flip
                        array[0] = -1.0;
                }else if (axis == "y" || axis == "Y") {         // vertical flip
                        array[5] = -1.0;
                }
                else if (axis == "z" || axis == "Z") {          // vertical flip
                        array[10] = -1.0;
                }
                Transform t(array);
                Dict params("transform",(Transform*)&t);
                image->process_inplace("xform",params);

                EXITFUNC;
                return;
        }
#endif


        float *d = image->get_data();
        int nx = image->get_xsize();
        int ny = image->get_ysize();
        int nz = image->get_zsize();

        size_t nxy = nx * ny;


        // Note in all cases the origin is nx/2, ny/2 and nz/2
        // This means when flipping even sized dimensions that some pixels are redundant.
        // Here redundant pixels are set to zero, however, should this change to something
        // like the mean.
        if (axis == "x" || axis == "X") {               // Horizontal flip
                int offset = (nx%2 == 0);
                size_t idx1, idx2;
                for(int z = 0; z < nz; ++z) {
                        for(int y = 0; y < ny; ++y) {
                                if (offset != 0 ) {
                                        idx1 = z*nxy + y*nx;
                                        d[idx1] = 0; // Here's where you'd make it the mean
                                }
                                for(int x = offset; x < nx / 2; ++x) {
                                        idx1 = z*nxy + y*nx + x;
                                        idx2 = z*nxy + y*nx + (nx-x-1+offset);
                                        std::swap(d[idx1], d[idx2]);
                                }

                        }
                }
        }

        else if (axis == "y" || axis == "Y") {          // vertical flip
                int offset = (ny%2 == 0);
                for(int z=0; z<nz; ++z) {
                        if (offset != 0) {
                                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)
                        }
                        for(int y=offset; y<ny/2; ++y) {
                                for(int x=0; x<nx; ++x) {
                                        std::swap(d[(size_t)z*nxy + y*nx +x], d[(size_t)z*nxy + (ny -y -1+offset)*nx +x]);
                                }
                        }
                }
        }
        else if (axis == "z" || axis == "Z") {          //z axis flip
                int offset = (nz%2 == 0);
                if (offset != 0) {
                        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)
                }
                size_t idx1, idx2;
                for(int z=offset; z<nz/2; ++z) {
                        for(int y=0; y<ny; ++y) {
                                for(int x=0; x<nx; ++x) {
                                        idx1 = (size_t)z*nxy + y*nx + x;
                                        idx2 = (size_t)(nz-z-1+offset)*nxy + y*nx + x;
                                        std::swap(d[idx1], d[idx2]);
                                }
                        }
                }
        }

        image->update();
        EXITFUNC;
}

Member Data Documentation

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

Definition at line 4861 of file processor.h.

Referenced by get_name().


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