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

Flattens the background by subtracting the local mean. More...

#include <processor.h>

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

Public Member Functions

void process_inplace (EMData *image)
 To process an image in-place. More...
 
string get_name () const
 Get the processor's name. More...
 
string get_desc () const
 Get the descrition of this specific processor. More...
 
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 = "filter.flattenbackground"
 

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

Flattens the background by subtracting the local mean.

Parameters
mapan EMData object that defines the extent of the local neighbourhood - will be used for convolution
radiusexclusive of the mask parameter, this defines the radius of a circle/sphere that will be used for local mean subtraction
Author
David Woolford
Date
April 2008

Definition at line 5276 of file processor.h.

Member Function Documentation

◆ get_desc()

string EMAN::FlattenBackgroundProcessor::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 5291 of file processor.h.

5292 {
5293 return "Flattens the background by subtracting the local mean";
5294 }

◆ get_name()

string EMAN::FlattenBackgroundProcessor::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 5281 of file processor.h.

5282 {
5283 return NAME;
5284 }
static const string NAME
Definition: processor.h:5304

References NAME.

◆ get_param_types()

TypeDict EMAN::FlattenBackgroundProcessor::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 5296 of file processor.h.

5297 {
5298 TypeDict d;
5299 d.put("mask", EMObject::EMDATA, "A mask the defines the local neighborhood that will be used to find the local mean. Exclusive of the radius argument");
5300 d.put("radius", EMObject::INT, "The radius of circle/sphere that defines the local neighborhood. Exclusive of the mask argument");
5301 return d;
5302 }
TypeDict is a dictionary to store <string, EMObject::ObjectType> pair.
Definition: emobject.h:305
void put(const string &key, EMObject::ObjectType o, const string &desc="")
Definition: emobject.h:330

References EMAN::EMObject::EMDATA, EMAN::EMObject::INT, and EMAN::TypeDict::put().

◆ NEW()

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

Definition at line 5286 of file processor.h.

5287 {
5288 return new FlattenBackgroundProcessor();
5289 }
Flattens the background by subtracting the local mean.
Definition: processor.h:5277

◆ process_inplace()

void FlattenBackgroundProcessor::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 3622 of file processor.cpp.

3623{
3624
3625 EMData* mask = params.set_default("mask",(EMData*)0);
3626 int radius = params.set_default("radius",0);
3627
3628 if (radius != 0 && mask != 0) throw InvalidParameterException("Error - the mask and radius parameters are mutually exclusive.");
3629
3630 if (mask == 0 && radius == 0) throw InvalidParameterException("Error - you must specify either the mask or the radius parameter.");
3631
3632 // If the radius isn't 0, then turn the mask into the thing we want...
3633 bool deletemask = false;
3634 if (radius != 0) {
3635 mask = new EMData;
3636 int n = image->get_ndim();
3637 if (n==1){
3638 mask->set_size(2*radius+1);
3639 } else if (n==2) {
3640 mask->set_size(2*radius+1,2*radius+1);
3641 }
3642 else /*n==3*/ {
3643 mask->set_size(2*radius+1,2*radius+1,2*radius+1);
3644 }
3645 // assuming default behavior is to make a circle/sphere with using the radius of the mask
3646 mask->process_inplace("testimage.circlesphere");
3647 }
3648
3649 // Double check that that mask isn't too big
3650 int mnx = mask->get_xsize(); int mny = mask->get_ysize(); int mnz = mask->get_zsize();
3651 int nx = image->get_xsize(); int ny = image->get_ysize(); int nz = image->get_zsize();
3652 int nxc = nx+mnx; int nyc = ny+mny; int nzc = nz+mnz;
3653 if (nz == 1) nzc = 1; // Sanity check
3654 if (ny == 1) nyc = 1; // Sanity check
3655
3656 if ( mnx > nx || mny > ny || mnz > nz)
3657 throw ImageDimensionException("Can not flatten using a mask that is larger than the image.");
3658
3659 // Get the normalization factor
3660 float normfac = 0.0;
3661 for (int i=0; i<mask->get_xsize()*mask->get_ysize()*mask->get_zsize(); ++i){
3662 normfac += mask->get_value_at(i);
3663 }
3664 // If the sum is zero the user probably doesn't understand that determining a measure of the mean requires
3665 // strictly positive numbers. The user has specified a mask that consists entirely of zeros, or the mask
3666 // has a mean of zero.
3667 if (normfac == 0) throw InvalidParameterException("Error - the pixels in the mask sum to zero. This breaks the flattening procedure");
3668 normfac = 1.0f/normfac;
3669
3670 // The mask can now be automatically resized to the dimensions of the image
3671// bool undoclip = false;
3672
3673 Region r;
3674 if (ny == 1) r = Region((mnx-nxc)/2,nxc);
3675 else if (nz == 1) r = Region((mnx-nxc)/2, (mny-nyc)/2,nxc,nyc);
3676 else r = Region((mnx-nxc)/2, (mny-nyc)/2,(mnz-nzc)/2,nxc,nyc,nzc);
3677 mask->clip_inplace(r,0);
3678// undoclip = true;
3679// if ( mnx < nx || mny < ny || mnz < nz) {
3680// Region r((mnx-nx)/2, (mny-ny)/2,(mnz-nz)/2,nx,ny,nz);
3681// mask->clip_inplace(r);
3682// undoclip = true;
3683// }
3684
3685 Region r2;
3686 if (ny == 1) r2 = Region((nx-nxc)/2,nxc);
3687 else if (nz == 1) r2 = Region((nx-nxc)/2, (ny-nyc)/2,nxc,nyc);
3688 else r2 = Region((nx-nxc)/2, (ny-nyc)/2,(nz-nzc)/2,nxc,nyc,nzc);
3689 image->clip_inplace(r2,image->get_edge_mean());
3690 // Finally do the convolution
3691 EMData* m = image->convolute(mask);
3692 // Normalize so that m is truly the local mean
3693 m->mult(normfac);
3694 // Before we can subtract, the mean must be phase shifted
3695 m->process_inplace("xform.phaseorigin.tocenter");
3696 // Subtract the local mean
3697// image->write_image("a.mrc");
3698// m->write_image("b.mrc");
3699 image->sub(*m); // WE'RE DONE!
3700 delete m;
3701
3702 if (deletemask) {
3703 delete mask;
3704 } else { // I clipped it inplace, so undo this clipping so the user gets back what the put in
3705 Region r;
3706 if (ny == 1) r = Region((nxc-mnx)/2,mnx);
3707 else if (nz == 1) r = Region((nxc-mnx)/2, (nyc-mny)/2,mnx,mny);
3708 else r = Region((nxc-mnx)/2, (nyc-mny)/2,(nzc-mnz)/2,mnx,mny,mnz);
3709 mask->clip_inplace(r);
3710 }
3711
3712 Region r3;
3713 if (ny == 1) r3 = Region((nxc-nx)/2,nx);
3714 else if (nz == 1) r3 = Region((nxc-nx)/2, (nyc-ny)/2,nx,ny);
3715 else r3 = Region((nxc-nx)/2, (nyc-ny)/2,(nzc-nz)/2,nx,ny,nz);
3716 image->clip_inplace(r3);
3717// if ( undoclip ) {
3718// Region r((nx-mnx)/2, (ny-mny)/2, (nz-mnz)/2,mnx,mny,mnz);
3719// mask->clip_inplace(r);
3720// }
3721
3722}
type set_default(const string &key, type val)
Default setting behavior This can be achieved using a template - d.woolford Jan 2008 (before there wa...
Definition: emobject.h:569
EMData stores an image's data and defines core image processing routines.
Definition: emdata.h:82
EMData * convolute(EMData *with)
Convolutes 2 data sets.
Definition: emdata.cpp:3567
void clip_inplace(const Region &area, const float &fill_value=0)
Clip the image inplace - clipping region must be smaller than the current region internally memory is...
Definition: emdata.cpp:350
Region defines a 2D or 3D rectangular region specified by its origin coordinates and all edges' sizes...
Definition: geometry.h:497
#define InvalidParameterException(desc)
Definition: exception.h:361
#define ImageDimensionException(desc)
Definition: exception.h:166

References EMAN::EMData::clip_inplace(), EMAN::EMData::convolute(), ImageDimensionException, InvalidParameterException, EMAN::Processor::params, and EMAN::Dict::set_default().

Member Data Documentation

◆ NAME

const string FlattenBackgroundProcessor::NAME = "filter.flattenbackground"
static

Definition at line 5304 of file processor.h.

Referenced by get_name().


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