#include <processor.h>
Inheritance diagram for EMAN::FlattenBackgroundProcessor:


Public Member Functions | |
| void | process_inplace (EMData *image) |
| To process an image in-place. | |
| string | get_name () const |
| Get the processor's name. | |
| string | get_desc () const |
| Get the descrition of this specific processor. | |
| TypeDict | get_param_types () const |
| Get processor parameter information in a dictionary. | |
Static Public Member Functions | |
| Processor * | NEW () |
Static Public Attributes | |
| const string | NAME = "filter.flattenbackground" |
| map | an EMData object that defines the extent of the local neighbourhood - will be used for convolution | |
| radius | exclusive of the mask parameter, this defines the radius of a circle/sphere that will be used for local mean subtraction |
Definition at line 3655 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 3670 of file processor.h. 03671 {
03672 return "Flattens the background by subtracting the local mean";
03673 }
|
|
|
Get the processor's name. Each processor is identified by a unique name.
Implements EMAN::Processor. Definition at line 3660 of file processor.h. 03661 {
03662 return NAME;
03663 }
|
|
|
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 3675 of file processor.h. References EMAN::TypeDict::put(). 03676 {
03677 TypeDict d;
03678 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");
03679 d.put("radius", EMObject::INT, "The radius of circle/sphere that defines the local neighborhood. Exclusive of the mask argument");
03680 return d;
03681 }
|
|
|
Definition at line 3665 of file processor.h. 03666 {
03667 return new FlattenBackgroundProcessor();
03668 }
|
|
|
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 2665 of file processor.cpp. References EMAN::EMData::clip_inplace(), EMAN::EMData::convolute(), EMAN::EMData::get_edge_mean(), EMAN::EMData::get_ndim(), EMAN::EMData::get_value_at(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, InvalidParameterException, EMAN::EMData::mult(), nx, ny, EMAN::EMData::process_inplace(), EMAN::Dict::set_default(), EMAN::EMData::set_size(), and EMAN::EMData::sub(). 02666 {
02667
02668 EMData* mask = params.set_default("mask",(EMData*)0);
02669 int radius = params.set_default("radius",0);
02670
02671 if (radius != 0 && mask != 0) throw InvalidParameterException("Error - the mask and radius parameters are mutually exclusive.");
02672
02673 if (mask == 0 && radius == 0) throw InvalidParameterException("Error - you must specify either the mask or the radius parameter.");
02674
02675 // If the radius isn't 0, then turn the mask into the thing we want...
02676 bool deletemask = false;
02677 if (radius != 0) {
02678 mask = new EMData;
02679 int n = image->get_ndim();
02680 if (n==1){
02681 mask->set_size(2*radius+1);
02682 } else if (n==2) {
02683 mask->set_size(2*radius+1,2*radius+1);
02684 }
02685 else /*n==3*/ {
02686 mask->set_size(2*radius+1,2*radius+1,2*radius+1);
02687 }
02688 // assuming default behavior is to make a circle/sphere with using the radius of the mask
02689 mask->process_inplace("testimage.circlesphere");
02690 }
02691
02692 // Double check that that mask isn't too big
02693 int mnx = mask->get_xsize(); int mny = mask->get_ysize(); int mnz = mask->get_zsize();
02694 int nx = image->get_xsize(); int ny = image->get_ysize(); int nz = image->get_zsize();
02695 int nxc = nx+mnx; int nyc = ny+mny; int nzc = nz+mnz;
02696 if (nz == 1) nzc = 1; // Sanity check
02697 if (ny == 1) nyc = 1; // Sanity check
02698
02699 if ( mnx > nx || mny > ny || mnz > nz)
02700 throw ImageDimensionException("Can not flatten using a mask that is larger than the image.");
02701
02702 // Get the normalization factor
02703 float normfac = 0.0;
02704 for (int i=0; i<mask->get_xsize()*mask->get_ysize()*mask->get_zsize(); ++i){
02705 normfac += mask->get_value_at(i);
02706 }
02707 // If the sum is zero the user probably doesn't understand that determining a measure of the mean requires
02708 // strictly positive numbers. The user has specified a mask that consists entirely of zeros, or the mask
02709 // has a mean of zero.
02710 if (normfac == 0) throw InvalidParameterException("Error - the pixels in the mask sum to zero. This breaks the flattening procedure");
02711 normfac = 1.0f/normfac;
02712
02713 // The mask can now be automatically resized to the dimensions of the image
02714 // bool undoclip = false;
02715
02716 Region r;
02717 if (ny == 1) r = Region((mnx-nxc)/2,nxc);
02718 else if (nz == 1) r = Region((mnx-nxc)/2, (mny-nyc)/2,nxc,nyc);
02719 else r = Region((mnx-nxc)/2, (mny-nyc)/2,(mnz-nzc)/2,nxc,nyc,nzc);
02720 mask->clip_inplace(r,0);
02721 // undoclip = true;
02722 // if ( mnx < nx || mny < ny || mnz < nz) {
02723 // Region r((mnx-nx)/2, (mny-ny)/2,(mnz-nz)/2,nx,ny,nz);
02724 // mask->clip_inplace(r);
02725 // undoclip = true;
02726 // }
02727
02728 Region r2;
02729 if (ny == 1) r2 = Region((nx-nxc)/2,nxc);
02730 else if (nz == 1) r2 = Region((nx-nxc)/2, (ny-nyc)/2,nxc,nyc);
02731 else r2 = Region((nx-nxc)/2, (ny-nyc)/2,(nz-nzc)/2,nxc,nyc,nzc);
02732 image->clip_inplace(r2,image->get_edge_mean());
02733 // Finally do the convolution
02734 EMData* m = image->convolute(mask);
02735 // Normalize so that m is truly the local mean
02736 m->mult(normfac);
02737 // Before we can subtract, the mean must be phase shifted
02738 m->process_inplace("xform.phaseorigin.tocenter");
02739 // Subtract the local mean
02740 // image->write_image("a.mrc");
02741 // m->write_image("b.mrc");
02742 image->sub(*m); // WE'RE DONE!
02743 delete m;
02744
02745 if (deletemask) {
02746 delete mask;
02747 } else { // I clipped it inplace, so undo this clipping so the user gets back what the put in
02748 Region r;
02749 if (ny == 1) r = Region((nxc-mnx)/2,mnx);
02750 else if (nz == 1) r = Region((nxc-mnx)/2, (nyc-mny)/2,mnx,mny);
02751 else r = Region((nxc-mnx)/2, (nyc-mny)/2,(nzc-mnz)/2,mnx,mny,mnz);
02752 mask->clip_inplace(r);
02753 }
02754
02755 Region r3;
02756 if (ny == 1) r3 = Region((nxc-nx)/2,nx);
02757 else if (nz == 1) r3 = Region((nxc-nx)/2, (nyc-ny)/2,nx,ny);
02758 else r3 = Region((nxc-nx)/2, (nyc-ny)/2,(nzc-nz)/2,nx,ny,nz);
02759 image->clip_inplace(r3);
02760 // if ( undoclip ) {
02761 // Region r((nx-mnx)/2, (ny-mny)/2, (nz-mnz)/2,mnx,mny,mnz);
02762 // mask->clip_inplace(r);
02763 // }
02764
02765 }
|
|
|
Definition at line 136 of file processor.cpp. |
1.3.9.1