EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
EMAN::ToCenterProcessor Class Reference

ToCenterProcessor centers image, ignores old dx, dy. More...

#include <processor.h>

Inheritance diagram for EMAN::ToCenterProcessor:
Inheritance graph
[legend]
Collaboration diagram for EMAN::ToCenterProcessor:
Collaboration graph
[legend]

Public Member Functions

virtual void process_inplace (EMData *image)
 To process an image in-place. More...
 
virtual string get_name () const
 Get the processor's name. More...
 
virtual string get_desc () const
 Get the descrition of this specific processor. More...
 
virtual TypeDict get_param_types () const
 Get processor parameter information in a dictionary. More...
 
- Public Member Functions inherited from EMAN::Processor
virtual ~Processor ()
 
virtual EMDataprocess (const EMData *const image)
 To proccess an image out-of-place. More...
 
virtual void process_list_inplace (vector< EMData * > &images)
 To process multiple images using the same algorithm. More...
 
virtual Dict get_params () const
 Get the processor parameters in a key/value dictionary. More...
 
virtual void set_params (const Dict &new_params)
 Set the processor parameters using a key/value dictionary. More...
 

Static Public Member Functions

static ProcessorNEW ()
 
- Static Public Member Functions inherited from EMAN::Processor
static string get_group_desc ()
 Get the description of this group of processors. More...
 
static void EMFourierFilterInPlace (EMData *fimage, Dict params)
 Compute a Fourier-filter processed image in place. More...
 
static EMDataEMFourierFilter (EMData *fimage, Dict params)
 Compute a Fourier-processor processed image without altering the original image. More...
 

Static Public Attributes

static const string NAME = "xform.center"
 

Additional Inherited Members

- Public Types inherited from EMAN::Processor
enum  fourier_filter_types {
  TOP_HAT_LOW_PASS , TOP_HAT_HIGH_PASS , TOP_HAT_BAND_PASS , TOP_HOMOMORPHIC ,
  GAUSS_LOW_PASS , GAUSS_HIGH_PASS , GAUSS_BAND_PASS , GAUSS_INVERSE ,
  GAUSS_HOMOMORPHIC , BUTTERWORTH_LOW_PASS , BUTTERWORTH_HIGH_PASS , BUTTERWORTH_HOMOMORPHIC ,
  KAISER_I0 , KAISER_SINH , KAISER_I0_INVERSE , KAISER_SINH_INVERSE ,
  SHIFT , TANH_LOW_PASS , TANH_HIGH_PASS , TANH_HOMOMORPHIC ,
  TANH_BAND_PASS , RADIAL_TABLE , CTF_
}
 Fourier filter Processor type enum. More...
 
- Protected Attributes inherited from EMAN::Processor
Dict params
 

Detailed Description

ToCenterProcessor centers image, ignores old dx, dy.

Definition at line 7090 of file processor.h.

Member Function Documentation

◆ get_desc()

virtual string EMAN::ToCenterProcessor::get_desc ( ) const
inlinevirtual

Get the descrition of this specific processor.

This function must be overwritten by a subclass.

Returns
The description of this processor.

Implements EMAN::Processor.

Definition at line 7105 of file processor.h.

7106 {
7107 return "Centers similar to the way a human would, by identifying the shape of the object and centering its sillouette. May be inaccurate if sillouette cannot be clearly identified. ";
7108 }

◆ get_name()

virtual string EMAN::ToCenterProcessor::get_name ( ) const
inlinevirtual

Get the processor's name.

Each processor is identified by a unique name.

Returns
The processor's name.

Implements EMAN::Processor.

Definition at line 7095 of file processor.h.

7096 {
7097 return NAME;
7098 }
static const string NAME
Definition: processor.h:7119

References NAME.

◆ get_param_types()

virtual TypeDict EMAN::ToCenterProcessor::get_param_types ( ) const
inlinevirtual

Get processor parameter information in a dictionary.

Each parameter has one record in the dictionary. Each record contains its name, data-type, and description.

Returns
A dictionary containing the parameter info.

Reimplemented from EMAN::Processor.

Definition at line 7110 of file processor.h.

7111 {
7112 TypeDict d;
7113// d.put("int_shift_only", EMObject::INT, "set to 1 only shift by integer, no interpolation");
7114// d.put("threshold", EMObject::FLOAT, "Only values larger than the threshold are included in the center of mass computation. Default is 0.");
7115// d.put("positive", EMObject::INT, "uses only densities >0 for the calculatton");
7116 return d;
7117 }
TypeDict is a dictionary to store <string, EMObject::ObjectType> pair.
Definition: emobject.h:305

◆ NEW()

static Processor * EMAN::ToCenterProcessor::NEW ( )
inlinestatic

Definition at line 7100 of file processor.h.

7101 {
7102 return new ToCenterProcessor();
7103 }
ToCenterProcessor centers image, ignores old dx, dy.
Definition: processor.h:7091

◆ process_inplace()

void ToCenterProcessor::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.

Parameters
imageThe image to be processed.

Implements EMAN::Processor.

Definition at line 7331 of file processor.cpp.

7332{
7333 if (!image) {
7334 LOGWARN("NULL Image");
7335 return;
7336 }
7337
7338 if ((float)image->get_attr("sigma")==0.0f) return; // Can't center a constant valued image
7339 int nx = image->get_xsize();
7340 int ny = image->get_ysize();
7341 int nz = image->get_zsize();
7342
7343 // Preprocess a copy of the image to better isolate the "bulk" of the object
7344 float gmw=(nx/16)>5?nx/16:5; // gaussian mask width
7345 EMData *image2=image->process("filter.highpass.gauss",Dict("cutoff_pixels",nx<50?nx/10:5)); // clear out large scale gradients
7346 image2->process_inplace("normalize.circlemean",Dict("radius",ny/2-4));
7347 image2->process_inplace("mask.gaussian",Dict("inner_radius",nx/2-gmw,"outer_radius",gmw/1.3)); // get rid of peripheral garbage
7348 image2->process_inplace("math.squared"); // exaggerate stronger density and includes strong negative density
7349 image2->process_inplace("filter.lowpass.gauss",Dict("cutoff_abs",0.05)); // get rid of peripheral garbage
7350 image2->process_inplace("normalize.circlemean",Dict("radius",ny/2-6));
7351
7352 // We compute a histogram so we can decide on a good threshold value
7353 float hmin=(float)image2->get_attr("mean");
7354 float hmax=(float)image2->get_attr("mean")+(float)image2->get_attr("sigma")*4.0;
7355 vector <float> hist = image2->calc_hist( 100,hmin,hmax);
7356 double tot=0;
7357 int i;
7358 for (i=99; i>=0; i--) {
7359 tot+=hist[i];
7360 if (tot>nx*ny*nz/10) break; // find a threshold encompassing a specific fraction of the total area/volume
7361 }
7362 float thr=(i*hmax+(99-i)*hmin)/99.0; // this should now be a threshold encompasing ~1/10 of the area in the image
7363// printf("mean %f sigma %f thr %f\n",(float)image2->get_attr("mean"),(float)image2->get_attr("sigma"),thr);
7364
7365 // threshold so we are essentially centering the object silhouette
7366 image2->process_inplace("threshold.belowtozero",Dict("minval",thr));
7367// image2->process_inplace("threshold.binary",Dict("value",thr));
7368// image2->write_image("dbg1.hdf",-1);
7369
7370 EMData *image3;
7371 if (nz==1) image3=image2->process("mask.auto2d",Dict("radius",nx/10,"threshold",thr*0.9,"nmaxseed",5));
7372 else image3=image2->process("mask.auto3d",Dict("radius",nx/10,"threshold",thr*0.9,"nmaxseed",5));
7373
7374 // if the mask failed, we revert to the thresholded, but unmasked image
7375 if (nz==1 && (float)image3->get_attr("sigma")==0) {
7376 delete image3;
7377 image3=image2->process("math.linearpyramid");
7378 image3->add(9.0f); // we comress the pyramid from .9-1
7379 image3->mult(0.9f);
7380 image3->process_inplace("mask.auto2d",Dict("threshold",0.5,"nmaxseed",5)); // should find seed points with a central bias
7381// image3->write_image("dbg3.hdf",-1);
7382 }
7383
7384 image3->process_inplace("threshold.binary",Dict("value",thr));
7385
7386 if ((float)image3->get_attr("sigma")==0) delete image3;
7387 else {
7388 delete image2;
7389 image2=image3;
7390 }
7391
7392// image2->write_image("dbg2.hdf",-1);
7393 FloatPoint com = image2->calc_center_of_mass(0.5);
7394 delete image2;
7395
7396 // actual centering is int translate only
7397 int dx = -(floor(com[0] + 0.5f) - nx / 2);
7398 int dy = -(floor(com[1] + 0.5f) - ny / 2);
7399 int dz = 0;
7400 if (nz > 1) {
7401 dz = -(floor(com[2] + 0.5f) - nz / 2);
7402 }
7403 if (abs(dx)>=nx-1 || abs(dy)>=ny-1 || abs(dz)>=nz) {
7404 printf("ERROR, center of mass outside image\n");
7405 }
7406 else {
7407 image->translate(dx, dy, dz);
7408
7409 Transform t;
7410 t.set_trans((float)dx,(float)dy,(float)dz);
7411
7412 if (nz > 1) {
7413 image->set_attr("xform.align3d",&t);
7414 } else {
7415 image->set_attr("xform.align2d",&t);
7416 }
7417 }
7418
7419
7420}
Dict is a dictionary to store <string, EMObject> pair.
Definition: emobject.h:385
EMData stores an image's data and defines core image processing routines.
Definition: emdata.h:82
void translate(float dx, float dy, float dz)
Translate this image.
Definition: emdata.cpp:904
vector< float > calc_hist(int hist_size=128, float hist_min=0, float hist_max=0, const float &brt=0.0f, const float &cont=1.0f)
Calculates the histogram of 'this' image.
Definition: emdata.cpp:2365
FloatPoint defines a float-coordinate point in a 1D/2D/3D space.
Definition: geometry.h:278
A Transform object is a somewhat specialized object designed specifically for EMAN2/Sparx storage of ...
Definition: transform.h:75
void set_trans(const float &x, const float &y, const float &z=0)
Set the post translation component.
Definition: transform.cpp:1036
#define LOGWARN
Definition: log.h:53

References EMAN::EMData::calc_hist(), LOGWARN, EMAN::Transform::set_trans(), and EMAN::EMData::translate().

Member Data Documentation

◆ NAME

const string ToCenterProcessor::NAME = "xform.center"
static

Definition at line 7119 of file processor.h.

Referenced by get_name().


The documentation for this class was generated from the following files: