#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 | |
| Processor * | NEW () |
Static Public Attributes | |
| const string | NAME = "xform.flip" |
| axis | 'x', 'y', or 'z' axis. 'x' means horizonal flip; 'y' means vertical flip; |
Definition at line 4503 of file processor.h.
|
|
Get the descrition of this specific processor. This function must be overwritten by a subclass.
Implements EMAN::Processor. Definition at line 4525 of file processor.h. 04526 {
04527 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.";
04528 }
|
|
|
Get the processor's name. Each processor is identified by a unique name.
Implements EMAN::Processor. Definition at line 4508 of file processor.h. 04509 {
04510 return NAME;
04511 }
|
|
|
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 4518 of file processor.h. References EMAN::TypeDict::put(). 04519 {
04520 TypeDict d;
04521 d.put("axis", EMObject::STRING, "'x', 'y', or 'z' axis.");
04522 return d;
04523 }
|
|
|
Definition at line 4513 of file processor.h. 04514 {
04515 return new FlipProcessor();
04516 }
|
|
|
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.
Implements EMAN::Processor. Definition at line 4300 of file processor.cpp. References 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. 04301 {
04302 ENTERFUNC;
04303 if (!image) {
04304 LOGWARN("NULL Image");
04305 return;
04306 }
04307 string axis = (const char*)params["axis"];
04308
04309 #ifdef EMAN2_USING_CUDA
04310 if (EMData::usecuda == 1 && image->getcudarwdata()) {
04311 //cout << "flip processor" << endl;
04312 float array[12] = {1.0, 0.0, 0.0, 0.0,
04313 0.0, 1.0, 0.0, 0.0,
04314 0.0, 0.0, 1.0, 0.0};
04315 if (axis == "x" || axis == "X") { // horizontal flip
04316 array[0] = -1.0;
04317 }else if (axis == "y" || axis == "Y") { // vertical flip
04318 array[5] = -1.0;
04319 }
04320 else if (axis == "z" || axis == "Z") { // vertical flip
04321 array[10] = -1.0;
04322 }
04323 Transform t(array);
04324 Dict params("transform",(Transform*)&t);
04325 image->process_inplace("xform",params);
04326
04327 EXITFUNC;
04328 return;
04329 }
04330 #endif
04331
04332
04333 float *d = image->get_data();
04334 int nx = image->get_xsize();
04335 int ny = image->get_ysize();
04336 int nz = image->get_zsize();
04337
04338 size_t nxy = nx * ny;
04339
04340
04341 // Note in all cases the origin is nx/2, ny/2 and nz/2
04342 // This means when flipping even sized dimensions that some pixels are redundant.
04343 // Here redundant pixels are set to zero, however, should this change to something
04344 // like the mean.
04345 if (axis == "x" || axis == "X") { // Horizontal flip
04346 int offset = (nx%2 == 0);
04347 size_t idx1, idx2;
04348 for(int z = 0; z < nz; ++z) {
04349 for(int y = 0; y < ny; ++y) {
04350 if (offset != 0 ) {
04351 idx1 = z*nxy + y*nx;
04352 d[idx1] = 0; // Here's where you'd make it the mean
04353 }
04354 for(int x = offset; x < nx / 2; ++x) {
04355 idx1 = z*nxy + y*nx + x;
04356 idx2 = z*nxy + y*nx + (nx-x-1+offset);
04357 std::swap(d[idx1], d[idx2]);
04358 }
04359
04360 }
04361 }
04362 }
04363
04364 else if (axis == "y" || axis == "Y") { // vertical flip
04365 int offset = (ny%2 == 0);
04366 for(int z=0; z<nz; ++z) {
04367 if (offset != 0) {
04368 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)
04369 }
04370 for(int y=offset; y<ny/2; ++y) {
04371 for(int x=0; x<nx; ++x) {
04372 std::swap(d[(size_t)z*nxy + y*nx +x], d[(size_t)z*nxy + (ny -y -1+offset)*nx +x]);
04373 }
04374 }
04375 }
04376 }
04377 else if (axis == "z" || axis == "Z") { //z axis flip
04378 int offset = (nz%2 == 0);
04379 if (offset != 0) {
04380 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)
04381 }
04382 size_t idx1, idx2;
04383 for(int z=offset; z<nz/2; ++z) {
04384 for(int y=0; y<ny; ++y) {
04385 for(int x=0; x<nx; ++x) {
04386 idx1 = (size_t)z*nxy + y*nx + x;
04387 idx2 = (size_t)(nz-z-1+offset)*nxy + y*nx + x;
04388 std::swap(d[idx1], d[idx2]);
04389 }
04390 }
04391 }
04392 }
04393
04394 image->update();
04395 EXITFUNC;
04396 }
|
|
|
Definition at line 163 of file processor.cpp. |
1.3.9.1