#include <processor.h>
Inheritance diagram for EMAN::FlipProcessor:
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 Processor * | NEW () |
Static Public Attributes | |
static const string | NAME = "xform.flip" |
axis | 'x', 'y', or 'z' axis. 'x' means horizonal flip; 'y' means vertical flip; |
Definition at line 4579 of file processor.h.
virtual string EMAN::FlipProcessor::get_desc | ( | ) | const [inline, virtual] |
Get the descrition of this specific processor.
This function must be overwritten by a subclass.
Implements EMAN::Processor.
Definition at line 4601 of file processor.h.
04602 { 04603 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."; 04604 }
virtual string EMAN::FlipProcessor::get_name | ( | ) | const [inline, virtual] |
Get the processor's name.
Each processor is identified by a unique name.
Implements EMAN::Processor.
Definition at line 4584 of file processor.h.
References NAME.
04585 { 04586 return NAME; 04587 }
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.
Reimplemented from EMAN::Processor.
Definition at line 4594 of file processor.h.
References EMAN::TypeDict::put(), and EMAN::EMObject::STRING.
04595 { 04596 TypeDict d; 04597 d.put("axis", EMObject::STRING, "'x', 'y', or 'z' axis."); 04598 return d; 04599 }
static Processor* EMAN::FlipProcessor::NEW | ( | ) | [inline, static] |
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.
image | The image to be processed. |
Implements EMAN::Processor.
Definition at line 4387 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.
04388 { 04389 ENTERFUNC; 04390 if (!image) { 04391 LOGWARN("NULL Image"); 04392 return; 04393 } 04394 string axis = (const char*)params["axis"]; 04395 04396 #ifdef EMAN2_USING_CUDA 04397 if (EMData::usecuda == 1 && image->getcudarwdata()) { 04398 //cout << "flip processor" << endl; 04399 float array[12] = {1.0, 0.0, 0.0, 0.0, 04400 0.0, 1.0, 0.0, 0.0, 04401 0.0, 0.0, 1.0, 0.0}; 04402 if (axis == "x" || axis == "X") { // horizontal flip 04403 array[0] = -1.0; 04404 }else if (axis == "y" || axis == "Y") { // vertical flip 04405 array[5] = -1.0; 04406 } 04407 else if (axis == "z" || axis == "Z") { // vertical flip 04408 array[10] = -1.0; 04409 } 04410 Transform t(array); 04411 Dict params("transform",(Transform*)&t); 04412 image->process_inplace("xform",params); 04413 04414 EXITFUNC; 04415 return; 04416 } 04417 #endif 04418 04419 04420 float *d = image->get_data(); 04421 int nx = image->get_xsize(); 04422 int ny = image->get_ysize(); 04423 int nz = image->get_zsize(); 04424 04425 size_t nxy = nx * ny; 04426 04427 04428 // Note in all cases the origin is nx/2, ny/2 and nz/2 04429 // This means when flipping even sized dimensions that some pixels are redundant. 04430 // Here redundant pixels are set to zero, however, should this change to something 04431 // like the mean. 04432 if (axis == "x" || axis == "X") { // Horizontal flip 04433 int offset = (nx%2 == 0); 04434 size_t idx1, idx2; 04435 for(int z = 0; z < nz; ++z) { 04436 for(int y = 0; y < ny; ++y) { 04437 if (offset != 0 ) { 04438 idx1 = z*nxy + y*nx; 04439 d[idx1] = 0; // Here's where you'd make it the mean 04440 } 04441 for(int x = offset; x < nx / 2; ++x) { 04442 idx1 = z*nxy + y*nx + x; 04443 idx2 = z*nxy + y*nx + (nx-x-1+offset); 04444 std::swap(d[idx1], d[idx2]); 04445 } 04446 04447 } 04448 } 04449 } 04450 04451 else if (axis == "y" || axis == "Y") { // vertical flip 04452 int offset = (ny%2 == 0); 04453 for(int z=0; z<nz; ++z) { 04454 if (offset != 0) { 04455 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) 04456 } 04457 for(int y=offset; y<ny/2; ++y) { 04458 for(int x=0; x<nx; ++x) { 04459 std::swap(d[(size_t)z*nxy + y*nx +x], d[(size_t)z*nxy + (ny -y -1+offset)*nx +x]); 04460 } 04461 } 04462 } 04463 } 04464 else if (axis == "z" || axis == "Z") { //z axis flip 04465 int offset = (nz%2 == 0); 04466 if (offset != 0) { 04467 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) 04468 } 04469 size_t idx1, idx2; 04470 for(int z=offset; z<nz/2; ++z) { 04471 for(int y=0; y<ny; ++y) { 04472 for(int x=0; x<nx; ++x) { 04473 idx1 = (size_t)z*nxy + y*nx + x; 04474 idx2 = (size_t)(nz-z-1+offset)*nxy + y*nx + x; 04475 std::swap(d[idx1], d[idx2]); 04476 } 04477 } 04478 } 04479 } 04480 04481 image->update(); 04482 EXITFUNC; 04483 }
const string FlipProcessor::NAME = "xform.flip" [static] |