EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
EMAN::NormalizeToLeastSquareProcessor Class Reference

use least square method to normalize More...

#include <processor.h>

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

Public Member Functions

void process_inplace (EMData *image)
 To process an image in-place. More...
 
string get_name () const
 Get the processor's name. More...
 
TypeDict get_param_types () const
 Get processor parameter information in a dictionary. More...
 
string get_desc () const
 Get the descrition of this specific processor. More...
 
- Public Member Functions inherited from EMAN::Processor
virtual ~Processor ()
 
virtual EMDataprocess (const EMData *const image)
 To proccess an image out-of-place. More...
 
virtual void process_list_inplace (vector< EMData * > &images)
 To process multiple images using the same algorithm. More...
 
virtual Dict get_params () const
 Get the processor parameters in a key/value dictionary. More...
 
virtual void set_params (const Dict &new_params)
 Set the processor parameters using a key/value dictionary. More...
 

Static Public Member Functions

static ProcessorNEW ()
 
- Static Public Member Functions inherited from EMAN::Processor
static string get_group_desc ()
 Get the description of this group of processors. More...
 
static void EMFourierFilterInPlace (EMData *fimage, Dict params)
 Compute a Fourier-filter processed image in place. More...
 
static EMDataEMFourierFilter (EMData *fimage, Dict params)
 Compute a Fourier-processor processed image without altering the original image. More...
 

Static Public Attributes

static const string NAME = "normalize.toimage"
 

Additional Inherited Members

- Public Types inherited from EMAN::Processor
enum  fourier_filter_types {
  TOP_HAT_LOW_PASS , TOP_HAT_HIGH_PASS , TOP_HAT_BAND_PASS , TOP_HOMOMORPHIC ,
  GAUSS_LOW_PASS , GAUSS_HIGH_PASS , GAUSS_BAND_PASS , GAUSS_INVERSE ,
  GAUSS_HOMOMORPHIC , BUTTERWORTH_LOW_PASS , BUTTERWORTH_HIGH_PASS , BUTTERWORTH_HOMOMORPHIC ,
  KAISER_I0 , KAISER_SINH , KAISER_I0_INVERSE , KAISER_SINH_INVERSE ,
  SHIFT , TANH_LOW_PASS , TANH_HIGH_PASS , TANH_HOMOMORPHIC ,
  TANH_BAND_PASS , RADIAL_TABLE , CTF_
}
 Fourier filter Processor type enum. More...
 
- Protected Attributes inherited from EMAN::Processor
Dict params
 

Detailed Description

use least square method to normalize

Parameters
toreference image normalize to
low_thresholdonly take into account the reference image's pixel value between high and low threshold (zero is ignored)
high_thresholdonly take into account the reference image's pixel value between high and low threshold (zero is ignored)

Definition at line 6262 of file processor.h.

Member Function Documentation

◆ get_desc()

string EMAN::NormalizeToLeastSquareProcessor::get_desc ( ) const
inlinevirtual

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

6291 {
6292 return "This will use a pixel vs pixel least squares fit to normalize one image to optimally match a second image, with various options for excluding some pixels. norm_mult and norm_add will be set in the header of the result.";
6293 }

◆ get_name()

string EMAN::NormalizeToLeastSquareProcessor::get_name ( ) const
inlinevirtual

Get the processor's name.

Each processor is identified by a unique name.

Returns
The processor's name.

Implements EMAN::Processor.

Definition at line 6267 of file processor.h.

6268 {
6269 return NAME;
6270 }

References NAME.

◆ get_param_types()

TypeDict EMAN::NormalizeToLeastSquareProcessor::get_param_types ( ) const
inlinevirtual

Get processor parameter information in a dictionary.

Each parameter has one record in the dictionary. Each record contains its name, data-type, and description.

Returns
A dictionary containing the parameter info.

Reimplemented from EMAN::Processor.

Definition at line 6277 of file processor.h.

6278 {
6279 TypeDict d;
6280 d.put("to", EMObject::EMDATA, "reference image normalize to");
6281 d.put("fourieramp", EMObject::INT, "If set, performs normalization using Fourier amplitudes instead of real-space image. Default = False.");
6282 d.put("ignore_zero", EMObject::BOOL, "If set, ignores any pixels which are exactly zero in either image. Defaut = True.");
6283 d.put("ignore_lowsig", EMObject::FLOAT, "If >0, then any pixels closer to the mean than val*sigma in either image excluded");
6284 d.put("low_threshold", EMObject::FLOAT, "only take into account the reference image's pixel value between high and low threshold (zero is always ignored)");
6285 d.put("high_threshold", EMObject::FLOAT, "only take into account the reference image's pixel value between high and low threshold (zero is always ignored)");
6286 d.put("debug", EMObject::BOOL, "This is a debugging flag which will cause various diagnostic files to be written.");
6287 return d;
6288 }
TypeDict is a dictionary to store <string, EMObject::ObjectType> pair.
Definition: emobject.h:305
void put(const string &key, EMObject::ObjectType o, const string &desc="")
Definition: emobject.h:330

References EMAN::EMObject::BOOL, EMAN::EMObject::EMDATA, EMAN::EMObject::FLOAT, EMAN::EMObject::INT, and EMAN::TypeDict::put().

◆ NEW()

static Processor * EMAN::NormalizeToLeastSquareProcessor::NEW ( )
inlinestatic

Definition at line 6272 of file processor.h.

6273 {
6275 }
use least square method to normalize
Definition: processor.h:6263

◆ process_inplace()

void NormalizeToLeastSquareProcessor::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 5203 of file processor.cpp.

5204{
5205 if (!image) {
5206 LOGWARN("NULL Image");
5207 return;
5208 }
5209
5210 EMData *to = params["to"];
5211
5212 bool ignore_zero = params.set_default("ignore_zero",true);
5213 bool fourieramp = params.set_default("fourieramp",false);
5214 bool debug = params.set_default("debug",false);
5215 float ignore_lowsig = params.set_default("ignore_lowsig",-1.0);
5216 float low_threshold = params.set_default("low_threshold",-FLT_MAX);
5217 float high_threshold = params.set_default("high_threshold",FLT_MAX);
5218
5219 int nx = image->get_xsize();
5220 int ny = image->get_ysize();
5221 int nz = image->get_zsize();
5222 size_t size = (size_t)nx * ny * nz;
5223 size_t size2 = 0;
5224
5225 EMData *fim = NULL;
5226 EMData *fto = NULL;
5227 float *dimage; // unthresholded image data
5228 float *dto;
5229 int step=1; // used in Fourier mode
5230
5231 float meani=(float)image->get_attr("mean");
5232 float meant=(float)to->get_attr("mean");
5233 float sigi=(float)image->get_attr("sigma")*ignore_lowsig;
5234 float sigt=(float)to->get_attr("sigma")*ignore_lowsig;
5235
5236 if (fourieramp) {
5237 fim=image->do_fft();
5238 fto=to->do_fft();
5239 fim->ri2ap();
5240 fto->ri2ap();
5241 dimage=fim->get_data();
5242 dto=fto->get_data();
5243 step=2;
5244 size2=(size_t)(nx+2) * ny * nz;
5245
5246 // sigma for thresholding
5247 meani=meant=0; // Fourier amplitude >=0, so we reference everything to this point
5248 sigi=sigt=0;
5249 for (size_t i=0; i<size2; i+=2) { sigi+=pow(dimage[i],2.0f); sigt+=pow(dto[i],2.0f); }
5250 sigi=ignore_lowsig*sqrt(sigi/(size2/2));
5251 sigt=ignore_lowsig*sqrt(sigt/(size2/2));
5252 }
5253 else {
5254 dimage = image->get_data();
5255 dto = to->get_data();
5256 size2=size;
5257 }
5258
5259
5260 // rewrote this to just use GSL and get rid of David's old code.
5261 // The two passes are just to make sure we don't eat too much RAM if we do 3D
5262 if (ignore_lowsig<0) ignore_lowsig=0;
5263
5264 size_t count=0;
5265 for (size_t i = 0; i < size2; i+=step) {
5266 if (dto[i] >= low_threshold && dto[i] <= high_threshold
5267 && (dto[i]>=meant+sigt || dto[i]<=meant-sigt)
5268 && (dimage[i]>=meani+sigi || dimage[i]<=meani-sigi)
5269 && (!ignore_zero ||(dto[i] != 0.0f && dimage[i] != 0.0f))) {
5270 count++;
5271 }
5272 }
5273
5274
5275 double *x=(double *)malloc(count*sizeof(double));
5276 double *y=(double *)malloc(count*sizeof(double));
5277 count=0;
5278 for (size_t i = 0; i < size2; i+=step) {
5279 if (dto[i] >= low_threshold && dto[i] <= high_threshold
5280 && (dto[i]>=meant+sigt || dto[i]<=meant-sigt)
5281 && (dimage[i]>=meani+sigi || dimage[i]<=meani-sigi)
5282 && (!ignore_zero ||(dto[i] != 0.0f && dimage[i] != 0.0f))) {
5283 x[count]=dimage[i];
5284 y[count]=dto[i];
5285 count++;
5286 }
5287 }
5288 double c0,c1;
5289 double cov00,cov01,cov11,sumsq;
5290 gsl_fit_linear (x, 1, y, 1, count, &c0, &c1, &cov00, &cov01, &cov11, &sumsq);
5291
5292 if (debug) {
5293 FILE*out=fopen("debug.txt","w");
5294 for (size_t i = 0; i < count; i++) {
5295 fprintf(out,"%lf\t%lf\n",x[i],y[i]);
5296 }
5297 fclose(out);
5298 printf("add %lf\tmul %lf\t%lf\t%lf\t%lf\t%lf\n",c0,c1,cov00,cov01,cov11,sumsq);
5299 }
5300
5301 free(x);
5302 free(y);
5303 if (fim!=NULL) delete fim;
5304 if (fto!=NULL) delete fto;
5305
5306 if (fourieramp) c0=0; // c0 makes no sense in this context. Really just a measure of noise
5307 dimage = image->get_data();
5308 for (size_t i = 0; i < size; ++i) dimage[i]=dimage[i]*c1+c0;
5309 image->update();
5310 image->set_attr("norm_mult",c1);
5311 image->set_attr("norm_add",c0);
5312}
type set_default(const string &key, type val)
Default setting behavior This can be achieved using a template - d.woolford Jan 2008 (before there wa...
Definition: emobject.h:569
EMData stores an image's data and defines core image processing routines.
Definition: emdata.h:82
EMData * sqrt() const
return square root of current image
#define LOGWARN
Definition: log.h:53
#define y(i, j)
Definition: projector.cpp:1516
#define x(i)
Definition: projector.cpp:1517

References LOGWARN, EMAN::Processor::params, EMAN::Dict::set_default(), sqrt(), x, and y.

Member Data Documentation

◆ NAME

const string NormalizeToLeastSquareProcessor::NAME = "normalize.toimage"
static

Definition at line 6295 of file processor.h.

Referenced by get_name().


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