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

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

ProcessorNEW ()

Static Public Attributes

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


Constructor & Destructor Documentation

EMAN::HistogramBin::HistogramBin  )  [inline]
 

Definition at line 6643 of file processor.h.

References default_bins.

Referenced by NEW().

06643 : 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 6665 of file processor.h.

06666                         {
06667                                 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";
06668                         }

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

06648                         {
06649                                 return NAME;
06650                         }

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

References EMAN::TypeDict::put().

06658                         {
06659                                 TypeDict d;
06660                                 d.put("nbins", EMObject::INT, "The number of bins the pixel values will be compressed into");
06661                                 d.put("debug", EMObject::BOOL, "Outputs debugging information (number of pixels per bin)");
06662                                 return d;
06663                         }

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

Definition at line 6652 of file processor.h.

References HistogramBin().

06653                         {
06654                                 return new HistogramBin();
06655                         }

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

References default_bins, EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::EMData::get_size(), InvalidParameterException, max, min, and EMAN::Dict::set_default().

09090 {
09091         float min = image->get_attr("minimum");
09092         float max = image->get_attr("maximum");
09093         float nbins = (float)params.set_default("nbins",default_bins);
09094         bool debug = params.set_default("debug",false);
09095 
09096         vector<int> debugscores;
09097         if ( debug ) {
09098                 debugscores = vector<int>((int)nbins, 0);
09099         }
09100 
09101         if ( nbins < 0 ) throw InvalidParameterException("nbins must be greater than 0");
09102 
09103         float bin_width = (max-min)/nbins;
09104         float bin_val_offset = bin_width/2.0f;
09105 
09106         size_t size = image->get_size();
09107         float* dat = image->get_data();
09108 
09109         for(size_t i = 0; i < size; ++i ) {
09110                 float val = dat[i];
09111                 val -= min;
09112                 int bin = (int) (val/bin_width);
09113 
09114                 // This makes the last interval [] and not [)
09115                 if (bin == nbins) bin -= 1;
09116 
09117                 dat[i] = min + bin*bin_width + bin_val_offset;
09118                 if ( debug ) {
09119                         debugscores[bin]++;
09120                 }
09121         }
09122 
09123         if ( debug ) {
09124                 int i = 0;
09125                 for( vector<int>::const_iterator it = debugscores.begin(); it != debugscores.end(); ++it, ++i)
09126                         cout << "Bin " << i << " has " << *it << " pixels in it" << endl;
09127         }
09128 
09129 }


Member Data Documentation

int EMAN::HistogramBin::default_bins [protected]
 

Definition at line 6673 of file processor.h.

Referenced by HistogramBin(), and process_inplace().

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

Definition at line 211 of file processor.cpp.


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