#include <processor.h>
Inheritance diagram for EMAN::TomoTiltEdgeMaskProcessor:
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 = "tomo.tiltedgemask" |
Classes | |
class | GaussianFunctoid |
This processors masks out 'mass' in tilted images that is not present in the zero-tilt (0 degrees) image. It does this based on the tilt angle. The tilt angle can be extracted from the image metadata (stored as the euler_alt attribute), or it may be specified explicitly (specifying the angle is the default behavior). The masked out regions at both sides of the image are set to 0 by default, but can also be set to the mean of the nearest non-masked data edge (in the y direction), or similarly the mean of both non-masked data edges on either side of the image. A gaussian fall-off is optional (but off by default).
biedgemean | Mutually exclusive of edgemean. Experimental. Causes the pixels in the masked out areas to take the average value of both the left and right edge pixel strips | |
edgemean | Mutually exclusive of biedgemean. Masked pixels values assume the mean edge pixel value, independently, for both sides of the image | |
angle | The angle that the image is, with respect to the zero tilt image | |
angle_fim | Read fim as 'from image metadata' - this causes the altitude angle stored in by the image object (i.e. as extracted from the header, as currently stored in memory) to be used as the angle. This overrides the angle argument | |
gauss_falloff | Causes the edge masking to have a smooth Gaussian fall-off - this parameter specifies how many pixels the fall-off will proceed over. Default is 0 | |
gauss_sigma | The sigma of the Gaussian function used to smooth the edge fall-off (functional form is exp(-(pixel distance)^2/sigma^2) |
Definition at line 6649 of file processor.h.
virtual string EMAN::TomoTiltEdgeMaskProcessor::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 6676 of file processor.h.
06677 { 06678 return "Masks the part of the image which is not present in the 0-tilt image. Masked areas can be 0 or set to the edgemean (of the nearest or both edges). Masked areas can also have a Gaussian fall-off to make the appearance smooth."; 06679 }
virtual string EMAN::TomoTiltEdgeMaskProcessor::get_name | ( | ) | const [inline, virtual] |
Get the processor's name.
Each processor is identified by a unique name.
Implements EMAN::Processor.
Definition at line 6654 of file processor.h.
References NAME.
06655 { 06656 return NAME; 06657 }
virtual TypeDict EMAN::TomoTiltEdgeMaskProcessor::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 6664 of file processor.h.
References EMAN::EMObject::BOOL, EMAN::EMObject::FLOAT, EMAN::EMObject::INT, and EMAN::TypeDict::put().
06665 { 06666 TypeDict d; 06667 d.put("biedgemean", EMObject::BOOL, "Mutually exclusive of edgemean. Experimental. Causes the pixels in the masked out areas to take the average value of both the left and right edge pixel strips"); 06668 d.put("edgemean", EMObject::BOOL, "Mutually exclusive of biedgemean. Masked pixels values assume the mean edge pixel value, independently, for both sides of the image."); 06669 d.put("angle", EMObject::INT, "The angle that the image is, with respect to the zero tilt image"); 06670 d.put("gauss_falloff",EMObject::INT, "Causes the edge masking to have a smooth Gaussian fall-off - this parameter specifies how many pixels the fall-off will proceed over. Default is 0."); 06671 d.put("gauss_sigma",EMObject::FLOAT,"The sigma of the Gaussian function used to smooth the edge fall-off (functional form is exp(-(pixel distance)^2/sigma^2)"); 06672 d.put("angle_fim",EMObject::BOOL,"Read fim as 'from image metadata' - this causes the altitude angle stored in by the image object (i.e. as extracted from the header, as currently stored in memory) to be used as the angle. This overrides the angle argument"); 06673 return d; 06674 }
static Processor* EMAN::TomoTiltEdgeMaskProcessor::NEW | ( | ) | [inline, static] |
Definition at line 6659 of file processor.h.
06660 { 06661 return new TomoTiltEdgeMaskProcessor(); 06662 }
void TomoTiltEdgeMaskProcessor::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 9309 of file processor.cpp.
References EMAN::EMData::get_attr(), EMAN::EMData::get_value_at(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), InvalidParameterException, EMAN::Processor::params, EMAN::EMData::process_inplace(), EMAN::Dict::set_default(), EMAN::EMData::set_value_at(), t, and EMAN::EMData::update().
09310 { 09311 bool biedgemean = params.set_default("biedgemean", false); 09312 bool edgemean = params.set_default("edgemean", false); 09313 // You can only do one of these - so if someone specifies them both the code complains loudly 09314 if (biedgemean && edgemean) throw InvalidParameterException("The edgemean and biedgemean options are mutually exclusive"); 09315 09316 bool fim = params.set_default("angle_fim", false); 09317 float alt; 09318 if ( fim ) { 09319 Transform* t = (Transform*)image->get_attr("xform.projection"); 09320 Dict d = t->get_params("eman"); 09321 alt = (float) d["alt"]; 09322 if(t) {delete t; t=0;} 09323 } 09324 else alt = params.set_default("angle", 0.0f); 09325 09326 09327 float cosine = cos(alt*M_PI/180.0f); 09328 09329 // Zero the edges 09330 int nx = image->get_xsize(); 09331 int ny = image->get_ysize(); 09332 int x_clip = static_cast<int>( (float) nx * ( 1.0 - cosine ) / 2.0); 09333 09334 float x1_edge_mean = 0.0; 09335 float x2_edge_mean = 0.0; 09336 09337 if ( biedgemean ) 09338 { 09339 float edge_mean = 0.0; 09340 09341 // Accrue the pixel densities on the side strips 09342 for ( int i = 0; i < ny; ++i ) { 09343 edge_mean += image->get_value_at(x_clip, i ); 09344 edge_mean += image->get_value_at(nx - x_clip-1, i ); 09345 } 09346 // Now make it so the mean is stored 09347 edge_mean /= 2*ny; 09348 09349 // Now shift pixel values accordingly 09350 for ( int i = 0; i < ny; ++i ) { 09351 for ( int j = nx-1; j >= nx - x_clip; --j) { 09352 image->set_value_at(j,i,edge_mean); 09353 } 09354 for ( int j = 0; j < x_clip; ++j) { 09355 image->set_value_at(j,i,edge_mean); 09356 } 09357 } 09358 x1_edge_mean = edge_mean; 09359 x2_edge_mean = edge_mean; 09360 } 09361 else if (edgemean) 09362 { 09363 for ( int i = 0; i < ny; ++i ) { 09364 x1_edge_mean += image->get_value_at(x_clip, i ); 09365 x2_edge_mean += image->get_value_at(nx - x_clip-1, i ); 09366 } 09367 x1_edge_mean /= ny; 09368 x2_edge_mean /= ny; 09369 09370 for ( int i = 0; i < ny; ++i ) { 09371 for ( int j = 0; j < x_clip; ++j) { 09372 image->set_value_at(j,i,x1_edge_mean); 09373 } 09374 for ( int j = nx-1; j >= nx - x_clip; --j) { 09375 image->set_value_at(j,i,x2_edge_mean); 09376 } 09377 } 09378 } 09379 else 09380 { 09381 // The edges are just zeroed - 09382 Dict zero_dict; 09383 zero_dict["x0"] = x_clip; 09384 zero_dict["x1"] = x_clip; 09385 zero_dict["y0"] = 0; 09386 zero_dict["y1"] = 0; 09387 image->process_inplace( "mask.zeroedge2d", zero_dict ); 09388 } 09389 09390 int gauss_rad = params.set_default("gauss_falloff", 0); 09391 if ( gauss_rad != 0) 09392 { 09393 // If the gaussian falloff distance is greater than x_clip, it will technically 09394 // go beyond the image boundaries. Thus we clamp gauss_rad so this cannot happen. 09395 // Therefore, there is potential here for (benevolent) unexpected behavior. 09396 if ( gauss_rad > x_clip ) gauss_rad = x_clip; 09397 09398 float gauss_sigma = params.set_default("gauss_sigma", 3.0f); 09399 if ( gauss_sigma < 0 ) throw InvalidParameterException("Error - you must specify a positive, non-zero gauss_sigma"); 09400 float sigma = (float) gauss_rad/gauss_sigma; 09401 09402 GaussianFunctoid gf(sigma); 09403 09404 for ( int i = 0; i < ny; ++i ) { 09405 09406 float left_value = image->get_value_at(x_clip, i ); 09407 float scale1 = left_value-x1_edge_mean; 09408 09409 float right_value = image->get_value_at(nx - x_clip - 1, i ); 09410 float scale2 = right_value-x2_edge_mean; 09411 09412 for ( int j = 1; j < gauss_rad; ++j ) 09413 { 09414 image->set_value_at(x_clip-j, i, scale1*gf((float)j)+x1_edge_mean ); 09415 image->set_value_at(nx - x_clip + j-1, i, scale2*gf((float)j)+x2_edge_mean); 09416 } 09417 } 09418 } 09419 09420 image->update(); 09421 }
const string TomoTiltEdgeMaskProcessor::NAME = "tomo.tiltedgemask" [static] |