#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 4499 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 4521 of file processor.h. 04522 { 04523 return "flip an image around an axis."; 04524 }
|
|
Get the processor's name. Each processor is identified by a unique name.
Implements EMAN::Processor. Definition at line 4504 of file processor.h. 04505 {
04506 return NAME;
04507 }
|
|
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 4514 of file processor.h. References EMAN::TypeDict::put(). 04515 { 04516 TypeDict d; 04517 d.put("axis", EMObject::STRING, "'x', 'y', or 'z' axis. 'x' means horizonal flip; 'y' means vertical flip;"); 04518 return d; 04519 }
|
|
Definition at line 4509 of file processor.h. 04510 { 04511 return new FlipProcessor(); 04512 }
|
|
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 4215 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. 04216 { 04217 ENTERFUNC; 04218 if (!image) { 04219 LOGWARN("NULL Image"); 04220 return; 04221 } 04222 string axis = (const char*)params["axis"]; 04223 #ifdef EMAN2_USING_CUDA 04224 if (image->gpu_operation_preferred()) { 04225 float array[12] = {1.0, 0.0, 0.0, 0.0, 04226 0.0, 1.0, 0.0, 0.0, 04227 0.0, 0.0, 1.0, 0.0}; 04228 if (axis == "x" || axis == "X") { // horizontal flip 04229 array[0] = -1.0; 04230 }else if (axis == "y" || axis == "Y") { // vertical flip 04231 array[5] = -1.0; 04232 } 04233 else if (axis == "z" || axis == "Z") { // vertical flip 04234 array[10] = -1.0; 04235 } 04236 Transform t(array); 04237 Dict params("transform",(Transform*)&t); 04238 image->process_inplace("xform",params); 04239 EXITFUNC; 04240 return; 04241 } 04242 #endif 04243 04244 04245 float *d = image->get_data(); 04246 int nx = image->get_xsize(); 04247 int ny = image->get_ysize(); 04248 int nz = image->get_zsize(); 04249 04250 size_t nxy = nx * ny; 04251 04252 04253 // Note in all cases the origin is nx/2, ny/2 and nz/2 04254 // This means when flipping even sized dimensions that some pixels are redundant. 04255 // Here redundant pixels are set to zero, however, should this change to something 04256 // like the mean. 04257 if (axis == "x" || axis == "X") { // Horizontal flip 04258 int offset = (nx%2 == 0); 04259 size_t idx1, idx2; 04260 for(int z = 0; z < nz; ++z) { 04261 for(int y = 0; y < ny; ++y) { 04262 if (offset != 0 ) { 04263 idx1 = z*nxy + y*nx; 04264 d[idx1] = 0; // Here's where you'd make it the mean 04265 } 04266 for(int x = offset; x < nx / 2; ++x) { 04267 idx1 = z*nxy + y*nx + x; 04268 idx2 = z*nxy + y*nx + (nx-x-1+offset); 04269 std::swap(d[idx1], d[idx2]); 04270 } 04271 04272 } 04273 } 04274 } 04275 04276 else if (axis == "y" || axis == "Y") { // vertical flip 04277 int offset = (ny%2 == 0); 04278 for(int z=0; z<nz; ++z) { 04279 if (offset != 0) { 04280 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) 04281 } 04282 for(int y=offset; y<ny/2; ++y) { 04283 for(int x=0; x<nx; ++x) { 04284 std::swap(d[z*nxy + y*nx +x], d[z*nxy + (ny -y -1+offset)*nx +x]); 04285 } 04286 } 04287 } 04288 } 04289 else if (axis == "z" || axis == "Z") { //z axis flip 04290 int offset = (nz%2 == 0); 04291 if (offset != 0) { 04292 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) 04293 } 04294 size_t idx1, idx2; 04295 for(int z=offset; z<nz/2; ++z) { 04296 for(int y=0; y<ny; ++y) { 04297 for(int x=0; x<nx; ++x) { 04298 idx1 = z*nxy + y*nx + x; 04299 idx2 = (nz-z-1+offset)*nxy + y*nx + x; 04300 std::swap(d[idx1], d[idx2]); 04301 } 04302 } 04303 } 04304 } 04305 04306 image->update(); 04307 EXITFUNC; 04308 }
|
|
Definition at line 157 of file processor.cpp. |