EMAN::RampProcessor Class Reference

Ramp processor -- Fits a least-squares plane to the picture, and subtracts the plane from the picture. More...

#include <processor.h>

Inheritance diagram for EMAN::RampProcessor:

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

Collaboration graph
[legend]
List of all members.

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.

Static Public Member Functions

static ProcessorNEW ()

Static Public Attributes

static const string NAME = "filter.ramp"

Detailed Description

Ramp processor -- Fits a least-squares plane to the picture, and subtracts the plane from the picture.

A wedge-shaped overall density profile can thus be removed from the picture.

Definition at line 3765 of file processor.h.


Member Function Documentation

string EMAN::RampProcessor::get_desc (  )  const [inline, virtual]

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 3779 of file processor.h.

03780                 {
03781                         return "Ramp processor -- Fits a least-squares plane "
03782                                    "to the picture, and subtracts the plane from "
03783                                    "the picture.  A wedge-shaped overall density "
03784                                    "profile can thus be removed from the picture.";
03785                 }

string EMAN::RampProcessor::get_name (  )  const [inline, virtual]

Get the processor's name.

Each processor is identified by a unique name.

Returns:
The processor's name.

Implements EMAN::Processor.

Definition at line 3770 of file processor.h.

References NAME.

Referenced by process_inplace().

03771                 {
03772                         return NAME;
03773                 }

static Processor* EMAN::RampProcessor::NEW (  )  [inline, static]

Definition at line 3774 of file processor.h.

03775                 {
03776                         return new RampProcessor();
03777                 }

void RampProcessor::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:
image The image to be processed.

Implements EMAN::Processor.

Definition at line 8016 of file processor.cpp.

References EMAN::EMData::get_data(), get_name(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, LOGERR, and EMAN::EMData::update().

08017 {
08018         if (!image) {
08019                 return;
08020         }
08021 
08022         int nz = image->get_zsize();
08023         if (nz > 1) {
08024                 LOGERR("%s Processor doesn't support 3D model", get_name().c_str());
08025                 throw ImageDimensionException("3D model not supported");
08026         }
08027 
08028         int nsam = image->get_xsize();
08029         int nrow = image->get_ysize();
08030         int n1 = nsam / 2;
08031         double sx1 = double(n1)*double(nsam+1);
08032         if ( nsam % 2 == 1 )
08033                 sx1 += 1 + n1;
08034         sx1 *= nrow;
08035         int n2 = nrow / 2;
08036         double sx2 = double(n2)*double(nrow+1);
08037         if ( nrow % 2 == 1 )
08038                 sx2 += 1 + n2;
08039         sx2 *= nsam;
08040         float *data = image->get_data();
08041         float *row = NULL; // handy pointer for values in a specific row of the data
08042         // statistical sums
08043         double syx1 = 0, syx2 = 0, sy = 0, sx1q = 0, sx2q = 0, syq = 0;
08044         for (int j=1; j <= nrow; j++) {
08045                 row = data + (j-1)*nsam - 1; // "-1" so that we can start counting at 1
08046                 for (int i=1; i<=nsam; i++) {
08047                         syx1 += row[i]*i;
08048                         syx2 += row[i]*j;
08049                         sy += row[i];
08050                         sx1q += i*i;
08051                         sx2q += j*j;
08052                         syq += row[i]*double(row[i]);
08053                 }
08054         }
08055         // least-squares
08056         float dn = float(nsam)*float(nrow);
08057         double qyx1 = syx1 - sx1*sy / dn;
08058         double qyx2 = syx2 - sx2*sy / dn;
08059         double qx1x2 = 0.0;
08060         double qx1 = sx1q - sx1*sx1 / dn;
08061         double qx2 = sx2q - sx2*sx2 / dn;
08062         double qy = syq - sy*sy / dn;
08063         double c = qx1*qx2 - qx1x2*qx1x2;
08064         if ( c > FLT_EPSILON ) {
08065                 double b1 = (qyx1*qx2 - qyx2*qx1x2) / c;
08066                 double b2 = (qyx2*qx1 - qyx1*qx1x2) / c;
08067                 double a = (sy - b1*sx1 - b2*sx2) / dn;
08068                 double d = a + b1 + b2;
08069                 for (int i=1; i<=nrow; i++) {
08070                         qy = d;
08071                         row = data + (i-1)*nsam - 1;
08072                         for (int k=1; k<=nsam; k++) {
08073                                 row[k] -= static_cast<float>(qy);
08074                                 qy += b1;
08075                         }
08076                         d += b2;
08077                 }
08078         } // image not altered if c is zero
08079 
08080         image->update();
08081 }


Member Data Documentation

const string RampProcessor::NAME = "filter.ramp" [static]

Definition at line 3787 of file processor.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Thu May 3 10:10:16 2012 for EMAN2 by  doxygen 1.4.7