Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

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

ProcessorNEW ()

Static Public Attributes

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

03525                 {
03526                         return "Ramp processor -- Fits a least-squares plane "
03527                                    "to the picture, and subtracts the plane from "
03528                                    "the picture.  A wedge-shaped overall density "
03529                                    "profile can thus be removed from the picture.";
03530                 }

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

Referenced by process_inplace().

03516                 {
03517                         return NAME;
03518                 }

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

Definition at line 3519 of file processor.h.

03520                 {
03521                         return new RampProcessor();
03522                 }

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 7761 of file processor.cpp.

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

07762 {
07763         if (!image) {
07764                 return;
07765         }
07766 
07767         int nz = image->get_zsize();
07768         if (nz > 1) {
07769                 LOGERR("%s Processor doesn't support 3D model", get_name().c_str());
07770                 throw ImageDimensionException("3D model not supported");
07771         }
07772 
07773         int nsam = image->get_xsize();
07774         int nrow = image->get_ysize();
07775         int n1 = nsam / 2;
07776         double sx1 = double(n1)*double(nsam+1);
07777         if ( nsam % 2 == 1 )
07778                 sx1 += 1 + n1;
07779         sx1 *= nrow;
07780         int n2 = nrow / 2;
07781         double sx2 = double(n2)*double(nrow+1);
07782         if ( nrow % 2 == 1 )
07783                 sx2 += 1 + n2;
07784         sx2 *= nsam;
07785         float *data = image->get_data();
07786         float *row = NULL; // handy pointer for values in a specific row of the data
07787         // statistical sums
07788         double syx1 = 0, syx2 = 0, sy = 0, sx1q = 0, sx2q = 0, syq = 0;
07789         for (int j=1; j <= nrow; j++) {
07790                 row = data + (j-1)*nsam - 1; // "-1" so that we can start counting at 1
07791                 for (int i=1; i<=nsam; i++) {
07792                         syx1 += row[i]*i;
07793                         syx2 += row[i]*j;
07794                         sy += row[i];
07795                         sx1q += i*i;
07796                         sx2q += j*j;
07797                         syq += row[i]*double(row[i]);
07798                 }
07799         }
07800         // least-squares
07801         float dn = float(nsam)*float(nrow);
07802         double qyx1 = syx1 - sx1*sy / dn;
07803         double qyx2 = syx2 - sx2*sy / dn;
07804         double qx1x2 = 0.0;
07805         double qx1 = sx1q - sx1*sx1 / dn;
07806         double qx2 = sx2q - sx2*sx2 / dn;
07807         double qy = syq - sy*sy / dn;
07808         double c = qx1*qx2 - qx1x2*qx1x2;
07809         if ( c > FLT_EPSILON ) {
07810                 double b1 = (qyx1*qx2 - qyx2*qx1x2) / c;
07811                 double b2 = (qyx2*qx1 - qyx1*qx1x2) / c;
07812                 double a = (sy - b1*sx1 - b2*sx2) / dn;
07813                 double d = a + b1 + b2;
07814                 for (int i=1; i<=nrow; i++) {
07815                         qy = d;
07816                         row = data + (i-1)*nsam - 1;
07817                         for (int k=1; k<=nsam; k++) {
07818                                 row[k] -= static_cast<float>(qy);
07819                                 qy += b1;
07820                         }
07821                         d += b2;
07822                 }
07823         } // image not altered if c is zero
07824 
07825         image->update();
07826 }


Member Data Documentation

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

Definition at line 126 of file processor.cpp.


The documentation for this class was generated from the following files:
Generated on Thu Dec 9 13:48:00 2010 for EMAN2 by  doxygen 1.3.9.1