#include <processor.h>
Inheritance diagram for EMAN::HistogramBin:
Public Member Functions | |
HistogramBin () | |
void | process_inplace (EMData *image) |
To process an image in-place. | |
string | get_name () const |
Get the processor's name. | |
TypeDict | get_param_types () const |
Get processor parameter information in a dictionary. | |
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 = "histogram.bin" |
Protected Attributes | |
int | default_bins |
The histogram is comprised of 'nbins' bins, and the value assigned to each pixel in the bin is the midpoint of the bin's upper and lower limits. Defaults to 256 bins
nbins | The number of bins the pixel values will be compressed into | |
debug | Outputs debugging information (number of pixels per bin) |
Definition at line 6936 of file processor.h.
EMAN::HistogramBin::HistogramBin | ( | ) | [inline] |
string EMAN::HistogramBin::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 6961 of file processor.h.
06962 { 06963 return "Bins pixel values, similar to calculating a histogram. The histogram is comprised of 'nbins' bins, and the value assigned to each pixel in the bin is the midpoint of the bin's upper and lower limits. Defaults to 256 bins"; 06964 }
string EMAN::HistogramBin::get_name | ( | ) | const [inline, virtual] |
Get the processor's name.
Each processor is identified by a unique name.
Implements EMAN::Processor.
Definition at line 6943 of file processor.h.
References NAME.
06944 { 06945 return NAME; 06946 }
TypeDict EMAN::HistogramBin::get_param_types | ( | ) | const [inline, virtual] |
Get processor parameter information in a dictionary.
Each parameter has one record in the dictionary. Each record contains its name, data-type, and description.
Reimplemented from EMAN::Processor.
Definition at line 6953 of file processor.h.
References EMAN::EMObject::BOOL, EMAN::EMObject::INT, and EMAN::TypeDict::put().
06954 { 06955 TypeDict d; 06956 d.put("nbins", EMObject::INT, "The number of bins the pixel values will be compressed into"); 06957 d.put("debug", EMObject::BOOL, "Outputs debugging information (number of pixels per bin)"); 06958 return d; 06959 }
static Processor* EMAN::HistogramBin::NEW | ( | ) | [inline, static] |
Definition at line 6948 of file processor.h.
References HistogramBin().
06949 { 06950 return new HistogramBin(); 06951 }
void HistogramBin::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 9404 of file processor.cpp.
References default_bins, EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::EMData::get_size(), InvalidParameterException, max, min, EMAN::Processor::params, and EMAN::Dict::set_default().
09405 { 09406 float min = image->get_attr("minimum"); 09407 float max = image->get_attr("maximum"); 09408 float nbins = (float)params.set_default("nbins",default_bins); 09409 bool debug = params.set_default("debug",false); 09410 09411 vector<int> debugscores; 09412 if ( debug ) { 09413 debugscores = vector<int>((int)nbins, 0); 09414 } 09415 09416 if ( nbins < 0 ) throw InvalidParameterException("nbins must be greater than 0"); 09417 09418 float bin_width = (max-min)/nbins; 09419 float bin_val_offset = bin_width/2.0f; 09420 09421 size_t size = image->get_size(); 09422 float* dat = image->get_data(); 09423 09424 for(size_t i = 0; i < size; ++i ) { 09425 float val = dat[i]; 09426 val -= min; 09427 int bin = (int) (val/bin_width); 09428 09429 // This makes the last interval [] and not [) 09430 if (bin == nbins) bin -= 1; 09431 09432 dat[i] = min + bin*bin_width + bin_val_offset; 09433 if ( debug ) { 09434 debugscores[bin]++; 09435 } 09436 } 09437 09438 if ( debug ) { 09439 int i = 0; 09440 for( vector<int>::const_iterator it = debugscores.begin(); it != debugscores.end(); ++it, ++i) 09441 cout << "Bin " << i << " has " << *it << " pixels in it" << endl; 09442 } 09443 09444 }
int EMAN::HistogramBin::default_bins [protected] |
const string HistogramBin::NAME = "histogram.bin" [static] |