#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 | |
Processor * | NEW () |
Static Public Attributes | |
const string | NAME = "tomo.tiltedgemask" |
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 6555 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 6582 of file processor.h. 06583 { 06584 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."; 06585 }
|
|
Get the processor's name. Each processor is identified by a unique name.
Implements EMAN::Processor. Definition at line 6560 of file processor.h. 06561 {
06562 return NAME;
06563 }
|
|
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 6570 of file processor.h. References EMAN::TypeDict::put(). 06571 { 06572 TypeDict d; 06573 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"); 06574 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."); 06575 d.put("angle", EMObject::INT, "The angle that the image is, with respect to the zero tilt image"); 06576 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."); 06577 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)"); 06578 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"); 06579 return d; 06580 }
|
|
Definition at line 6565 of file processor.h. 06566 { 06567 return new TomoTiltEdgeMaskProcessor(); 06568 }
|
|
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 9280 of file processor.cpp. References EMAN::EMData::get_attr(), EMAN::Transform::get_params(), EMAN::EMData::get_value_at(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), InvalidParameterException, nx, ny, EMAN::EMData::process_inplace(), EMAN::Dict::set_default(), EMAN::EMData::set_value_at(), t, and EMAN::EMData::update(). 09281 { 09282 bool biedgemean = params.set_default("biedgemean", false); 09283 bool edgemean = params.set_default("edgemean", false); 09284 // You can only do one of these - so if someone specifies them both the code complains loudly 09285 if (biedgemean && edgemean) throw InvalidParameterException("The edgemean and biedgemean options are mutually exclusive"); 09286 09287 bool fim = params.set_default("angle_fim", false); 09288 float alt; 09289 if ( fim ) { 09290 Transform* t = (Transform*)image->get_attr("xform.projection"); 09291 Dict d = t->get_params("eman"); 09292 alt = (float) d["alt"]; 09293 if(t) {delete t; t=0;} 09294 } 09295 else alt = params.set_default("angle", 0.0f); 09296 09297 09298 float cosine = cos(alt*M_PI/180.0f); 09299 09300 // Zero the edges 09301 int nx = image->get_xsize(); 09302 int ny = image->get_ysize(); 09303 int x_clip = static_cast<int>( (float) nx * ( 1.0 - cosine ) / 2.0); 09304 09305 float x1_edge_mean = 0.0; 09306 float x2_edge_mean = 0.0; 09307 09308 if ( biedgemean ) 09309 { 09310 float edge_mean = 0.0; 09311 09312 // Accrue the pixel densities on the side strips 09313 for ( int i = 0; i < ny; ++i ) { 09314 edge_mean += image->get_value_at(x_clip, i ); 09315 edge_mean += image->get_value_at(nx - x_clip-1, i ); 09316 } 09317 // Now make it so the mean is stored 09318 edge_mean /= 2*ny; 09319 09320 // Now shift pixel values accordingly 09321 for ( int i = 0; i < ny; ++i ) { 09322 for ( int j = nx-1; j >= nx - x_clip; --j) { 09323 image->set_value_at(j,i,edge_mean); 09324 } 09325 for ( int j = 0; j < x_clip; ++j) { 09326 image->set_value_at(j,i,edge_mean); 09327 } 09328 } 09329 x1_edge_mean = edge_mean; 09330 x2_edge_mean = edge_mean; 09331 } 09332 else if (edgemean) 09333 { 09334 for ( int i = 0; i < ny; ++i ) { 09335 x1_edge_mean += image->get_value_at(x_clip, i ); 09336 x2_edge_mean += image->get_value_at(nx - x_clip-1, i ); 09337 } 09338 x1_edge_mean /= ny; 09339 x2_edge_mean /= ny; 09340 09341 for ( int i = 0; i < ny; ++i ) { 09342 for ( int j = 0; j < x_clip; ++j) { 09343 image->set_value_at(j,i,x1_edge_mean); 09344 } 09345 for ( int j = nx-1; j >= nx - x_clip; --j) { 09346 image->set_value_at(j,i,x2_edge_mean); 09347 } 09348 } 09349 } 09350 else 09351 { 09352 // The edges are just zeroed - 09353 Dict zero_dict; 09354 zero_dict["x0"] = x_clip; 09355 zero_dict["x1"] = x_clip; 09356 zero_dict["y0"] = 0; 09357 zero_dict["y1"] = 0; 09358 image->process_inplace( "mask.zeroedge2d", zero_dict ); 09359 } 09360 09361 int gauss_rad = params.set_default("gauss_falloff", 0); 09362 if ( gauss_rad != 0) 09363 { 09364 // If the gaussian falloff distance is greater than x_clip, it will technically 09365 // go beyond the image boundaries. Thus we clamp gauss_rad so this cannot happen. 09366 // Therefore, there is potential here for (benevolent) unexpected behavior. 09367 if ( gauss_rad > x_clip ) gauss_rad = x_clip; 09368 09369 float gauss_sigma = params.set_default("gauss_sigma", 3.0f); 09370 if ( gauss_sigma < 0 ) throw InvalidParameterException("Error - you must specify a positive, non-zero gauss_sigma"); 09371 float sigma = (float) gauss_rad/gauss_sigma; 09372 09373 GaussianFunctoid gf(sigma); 09374 09375 for ( int i = 0; i < ny; ++i ) { 09376 09377 float left_value = image->get_value_at(x_clip, i ); 09378 float scale1 = left_value-x1_edge_mean; 09379 09380 float right_value = image->get_value_at(nx - x_clip - 1, i ); 09381 float scale2 = right_value-x2_edge_mean; 09382 09383 for ( int j = 1; j < gauss_rad; ++j ) 09384 { 09385 image->set_value_at(x_clip-j, i, scale1*gf((float)j)+x1_edge_mean ); 09386 image->set_value_at(nx - x_clip + j-1, i, scale2*gf((float)j)+x2_edge_mean); 09387 } 09388 } 09389 } 09390 09391 image->update(); 09392 }
|
|
Definition at line 210 of file processor.cpp. |