EMAN::HistogramBin Class Reference

Bins pixel values, similar to calculating a histogram. More...

#include <processor.h>

Inheritance diagram for EMAN::HistogramBin:

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

Collaboration graph
[legend]
List of all members.

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 ProcessorNEW ()

Static Public Attributes

static const string NAME = "histogram.bin"

Protected Attributes

int default_bins

Detailed Description

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

Parameters:
nbins The number of bins the pixel values will be compressed into
debug Outputs debugging information (number of pixels per bin)

Definition at line 6725 of file processor.h.


Constructor & Destructor Documentation

EMAN::HistogramBin::HistogramBin (  )  [inline]

Definition at line 6728 of file processor.h.

Referenced by NEW().

06728 : default_bins(1024) {}


Member Function Documentation

string EMAN::HistogramBin::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 6750 of file processor.h.

06751                         {
06752                                 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";
06753                         }

string EMAN::HistogramBin::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 6732 of file processor.h.

References NAME.

06733                         {
06734                                 return NAME;
06735                         }

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.

Returns:
A dictionary containing the parameter info.

Reimplemented from EMAN::Processor.

Definition at line 6742 of file processor.h.

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

06743                         {
06744                                 TypeDict d;
06745                                 d.put("nbins", EMObject::INT, "The number of bins the pixel values will be compressed into");
06746                                 d.put("debug", EMObject::BOOL, "Outputs debugging information (number of pixels per bin)");
06747                                 return d;
06748                         }

static Processor* EMAN::HistogramBin::NEW (  )  [inline, static]

Definition at line 6737 of file processor.h.

References HistogramBin().

06738                         {
06739                                 return new HistogramBin();
06740                         }

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.

Parameters:
image The image to be processed.

Implements EMAN::Processor.

Definition at line 9139 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().

09140 {
09141         float min = image->get_attr("minimum");
09142         float max = image->get_attr("maximum");
09143         float nbins = (float)params.set_default("nbins",default_bins);
09144         bool debug = params.set_default("debug",false);
09145 
09146         vector<int> debugscores;
09147         if ( debug ) {
09148                 debugscores = vector<int>((int)nbins, 0);
09149         }
09150 
09151         if ( nbins < 0 ) throw InvalidParameterException("nbins must be greater than 0");
09152 
09153         float bin_width = (max-min)/nbins;
09154         float bin_val_offset = bin_width/2.0f;
09155 
09156         size_t size = image->get_size();
09157         float* dat = image->get_data();
09158 
09159         for(size_t i = 0; i < size; ++i ) {
09160                 float val = dat[i];
09161                 val -= min;
09162                 int bin = (int) (val/bin_width);
09163 
09164                 // This makes the last interval [] and not [)
09165                 if (bin == nbins) bin -= 1;
09166 
09167                 dat[i] = min + bin*bin_width + bin_val_offset;
09168                 if ( debug ) {
09169                         debugscores[bin]++;
09170                 }
09171         }
09172 
09173         if ( debug ) {
09174                 int i = 0;
09175                 for( vector<int>::const_iterator it = debugscores.begin(); it != debugscores.end(); ++it, ++i)
09176                         cout << "Bin " << i << " has " << *it << " pixels in it" << endl;
09177         }
09178 
09179 }


Member Data Documentation

int EMAN::HistogramBin::default_bins [protected]

Definition at line 6758 of file processor.h.

Referenced by process_inplace().

const string HistogramBin::NAME = "histogram.bin" [static]

Definition at line 6755 of file processor.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Mon Mar 7 18:03:30 2011 for EMAN2 by  doxygen 1.4.7