EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes
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:
nbinsThe number of bins the pixel values will be compressed into
debugOutputs debugging information (number of pixels per bin)

Definition at line 7308 of file processor.h.


Constructor & Destructor Documentation

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

Definition at line 7311 of file processor.h.

Referenced by NEW().

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

                        {
                                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";
                        }
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 7315 of file processor.h.

References NAME.

                        {
                                return NAME;
                        }
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 7325 of file processor.h.

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

                        {
                                TypeDict d;
                                d.put("nbins", EMObject::INT, "The number of bins the pixel values will be compressed into");
                                d.put("debug", EMObject::BOOL, "Outputs debugging information (number of pixels per bin)");
                                return d;
                        }
static Processor* EMAN::HistogramBin::NEW ( ) [inline, static]

Definition at line 7320 of file processor.h.

References HistogramBin().

                        {
                                return new HistogramBin();
                        }
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:
imageThe image to be processed.

Implements EMAN::Processor.

Definition at line 10038 of file processor.cpp.

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

{
        float min = image->get_attr("minimum");
        float max = image->get_attr("maximum");
        float nbins = (float)params.set_default("nbins",default_bins);
        bool debug = params.set_default("debug",false);

        vector<int> debugscores;
        if ( debug ) {
                debugscores = vector<int>((int)nbins, 0);
        }

        if ( nbins < 0 ) throw InvalidParameterException("nbins must be greater than 0");

        float bin_width = (max-min)/nbins;
        float bin_val_offset = bin_width/2.0f;

        size_t size = image->get_size();
        float* dat = image->get_data();

        for(size_t i = 0; i < size; ++i ) {
                float val = dat[i];
                val -= min;
                int bin = (int) (val/bin_width);

                // This makes the last interval [] and not [)
                if (bin == nbins) bin -= 1;

                dat[i] = min + bin*bin_width + bin_val_offset;
                if ( debug ) {
                        debugscores[bin]++;
                }
        }

        if ( debug ) {
                int i = 0;
                for( vector<int>::const_iterator it = debugscores.begin(); it != debugscores.end(); ++it, ++i)
                        cout << "Bin " << i << " has " << *it << " pixels in it" << endl;
        }

}

Member Data Documentation

Definition at line 7341 of file processor.h.

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

Definition at line 7338 of file processor.h.

Referenced by get_name().


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