EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes
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 3954 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 3968 of file processor.h.

                {
                        return "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.";
                }
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 3959 of file processor.h.

References NAME.

                {
                        return NAME;
                }
static Processor* EMAN::RampProcessor::NEW ( ) [inline, static]

Definition at line 3963 of file processor.h.

                {
                        return new RampProcessor();
                }
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:
imageThe image to be processed.

Implements EMAN::Processor.

Definition at line 8534 of file processor.cpp.

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

{
        if (!image) {
                return;
        }

        int nz = image->get_zsize();
        if (nz > 1) {
                LOGERR("%s Processor doesn't support 3D model", get_name().c_str());
                throw ImageDimensionException("3D model not supported");
        }

        int nsam = image->get_xsize();
        int nrow = image->get_ysize();
        int n1 = nsam / 2;
        double sx1 = double(n1)*double(nsam+1);
        if ( nsam % 2 == 1 )
                sx1 += 1 + n1;
        sx1 *= nrow;
        int n2 = nrow / 2;
        double sx2 = double(n2)*double(nrow+1);
        if ( nrow % 2 == 1 )
                sx2 += 1 + n2;
        sx2 *= nsam;
        float *data = image->get_data();
        float *row = NULL; // handy pointer for values in a specific row of the data
        // statistical sums
        double syx1 = 0, syx2 = 0, sy = 0, sx1q = 0, sx2q = 0, syq = 0;
        for (int j=1; j <= nrow; j++) {
                row = data + (j-1)*nsam - 1; // "-1" so that we can start counting at 1
                for (int i=1; i<=nsam; i++) {
                        syx1 += row[i]*i;
                        syx2 += row[i]*j;
                        sy += row[i];
                        sx1q += i*i;
                        sx2q += j*j;
                        syq += row[i]*double(row[i]);
                }
        }
        // least-squares
        float dn = float(nsam)*float(nrow);
        double qyx1 = syx1 - sx1*sy / dn;
        double qyx2 = syx2 - sx2*sy / dn;
        double qx1x2 = 0.0;
        double qx1 = sx1q - sx1*sx1 / dn;
        double qx2 = sx2q - sx2*sx2 / dn;
        double qy = syq - sy*sy / dn;
        double c = qx1*qx2 - qx1x2*qx1x2;
        if ( c > FLT_EPSILON ) {
                double b1 = (qyx1*qx2 - qyx2*qx1x2) / c;
                double b2 = (qyx2*qx1 - qyx1*qx1x2) / c;
                double a = (sy - b1*sx1 - b2*sx2) / dn;
                double d = a + b1 + b2;
                for (int i=1; i<=nrow; i++) {
                        qy = d;
                        row = data + (i-1)*nsam - 1;
                        for (int k=1; k<=nsam; k++) {
                                row[k] -= static_cast<float>(qy);
                                qy += b1;
                        }
                        d += b2;
                }
        } // image not altered if c is zero

        image->update();
}

Member Data Documentation

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

Definition at line 3976 of file processor.h.

Referenced by get_name().


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