#include <processor.h>
Inheritance diagram for EMAN::RampProcessor:
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 Processor * | NEW () |
Static Public Attributes | |
static const string | NAME = "filter.ramp" |
A wedge-shaped overall density profile can thus be removed from the picture.
Definition at line 3689 of file processor.h.
string EMAN::RampProcessor::get_desc | ( | ) | const [inline, virtual] |
Get the descrition of this specific processor.
This function must be overwritten by a subclass.
Implements EMAN::Processor.
Definition at line 3703 of file processor.h.
03704 { 03705 return "Ramp processor -- Fits a least-squares plane " 03706 "to the picture, and subtracts the plane from " 03707 "the picture. A wedge-shaped overall density " 03708 "profile can thus be removed from the picture."; 03709 }
string EMAN::RampProcessor::get_name | ( | ) | const [inline, virtual] |
Get the processor's name.
Each processor is identified by a unique name.
Implements EMAN::Processor.
Definition at line 3694 of file processor.h.
References NAME.
Referenced by process_inplace().
03695 { 03696 return NAME; 03697 }
static Processor* EMAN::RampProcessor::NEW | ( | ) | [inline, static] |
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.
image | The image to be processed. |
Implements EMAN::Processor.
Definition at line 7858 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().
07859 { 07860 if (!image) { 07861 return; 07862 } 07863 07864 int nz = image->get_zsize(); 07865 if (nz > 1) { 07866 LOGERR("%s Processor doesn't support 3D model", get_name().c_str()); 07867 throw ImageDimensionException("3D model not supported"); 07868 } 07869 07870 int nsam = image->get_xsize(); 07871 int nrow = image->get_ysize(); 07872 int n1 = nsam / 2; 07873 double sx1 = double(n1)*double(nsam+1); 07874 if ( nsam % 2 == 1 ) 07875 sx1 += 1 + n1; 07876 sx1 *= nrow; 07877 int n2 = nrow / 2; 07878 double sx2 = double(n2)*double(nrow+1); 07879 if ( nrow % 2 == 1 ) 07880 sx2 += 1 + n2; 07881 sx2 *= nsam; 07882 float *data = image->get_data(); 07883 float *row = NULL; // handy pointer for values in a specific row of the data 07884 // statistical sums 07885 double syx1 = 0, syx2 = 0, sy = 0, sx1q = 0, sx2q = 0, syq = 0; 07886 for (int j=1; j <= nrow; j++) { 07887 row = data + (j-1)*nsam - 1; // "-1" so that we can start counting at 1 07888 for (int i=1; i<=nsam; i++) { 07889 syx1 += row[i]*i; 07890 syx2 += row[i]*j; 07891 sy += row[i]; 07892 sx1q += i*i; 07893 sx2q += j*j; 07894 syq += row[i]*double(row[i]); 07895 } 07896 } 07897 // least-squares 07898 float dn = float(nsam)*float(nrow); 07899 double qyx1 = syx1 - sx1*sy / dn; 07900 double qyx2 = syx2 - sx2*sy / dn; 07901 double qx1x2 = 0.0; 07902 double qx1 = sx1q - sx1*sx1 / dn; 07903 double qx2 = sx2q - sx2*sx2 / dn; 07904 double qy = syq - sy*sy / dn; 07905 double c = qx1*qx2 - qx1x2*qx1x2; 07906 if ( c > FLT_EPSILON ) { 07907 double b1 = (qyx1*qx2 - qyx2*qx1x2) / c; 07908 double b2 = (qyx2*qx1 - qyx1*qx1x2) / c; 07909 double a = (sy - b1*sx1 - b2*sx2) / dn; 07910 double d = a + b1 + b2; 07911 for (int i=1; i<=nrow; i++) { 07912 qy = d; 07913 row = data + (i-1)*nsam - 1; 07914 for (int k=1; k<=nsam; k++) { 07915 row[k] -= static_cast<float>(qy); 07916 qy += b1; 07917 } 07918 d += b2; 07919 } 07920 } // image not altered if c is zero 07921 07922 image->update(); 07923 }
const string RampProcessor::NAME = "filter.ramp" [static] |