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

#include <processor.h>

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

Public Member Functions

string get_name () const
 Get the processor's name. More...
 
void process_inplace (EMData *image)
 To process an image in-place. 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 = "math.setbits"
 

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

Definition at line 2755 of file processor.h.

Member Function Documentation

◆ get_desc()

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

2779 {
2780 return "Converts each pixel value to an integer using the specified number of total bits. This will make the data more compressible, and allows you to handle conversion to integer data modes.\
2781The data itself will remain stored in single precision floating point format, so using >23 bits would be a bad idea.";
2782 }

◆ get_name()

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

2759 {
2760 return NAME;
2761 }
static const string NAME
Definition: processor.h:2784

References NAME.

◆ get_param_types()

TypeDict EMAN::SetBitsProcessor::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 2769 of file processor.h.

2770 {
2771 TypeDict d;
2772 d.put("bits", EMObject::INT, "Number of bits to retain (default 5)");
2773 d.put("nsigma", EMObject::FLOAT, "Number of standard deviations to include in the n bit mapping. eg - max=min(mean+nsigma*sigma,max)");
2774 d.put("floatbits", EMObject::INT, "If set to a >0 number, alters the algorithm, so the specified number of significant floating point bits is retained. The floating point exponent is not modified. This will produce less compressible data, but the values will be less perturbed.");
2775 return d;
2776 }
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::FLOAT, EMAN::EMObject::INT, and EMAN::TypeDict::put().

◆ NEW()

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

Definition at line 2762 of file processor.h.

2763 {
2764 return new SetBitsProcessor();
2765 }

◆ process_inplace()

void SetBitsProcessor::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 2599 of file processor.cpp.

2600{
2601 if (!image) return;
2602
2603 float nsigma = params.set_default("nsigma",3.0f);
2604 int bits = params.set_default("bits",5);
2605 int floatbits = params.set_default("floatbits",-1);
2606 float sigma = image->get_attr("sigma");
2607 float mean = image->get_attr("mean");
2608 float bitmax=pow(2.,bits);
2609
2610 int nx = image->get_xsize();
2611 int ny = image->get_ysize();
2612 int nz = image->get_zsize();
2613 size_t total_size = (size_t)nx * (size_t)ny * (size_t)nz;
2614
2615 if (floatbits<=0) {
2616 float min=image->get_attr("minimum");
2617 float max=image->get_attr("maximum");
2618
2619 // our max/min are either the actual max/min, or mean+-nsigma*sigma
2620 // whichever produces the smaller range. That way by specifying a large
2621 // nsigma you can get the actual min/max of the image easily
2622 if (mean-nsigma*sigma>min) min=mean-nsigma*sigma;
2623 if (mean+nsigma*sigma<max) max=mean+nsigma*sigma;
2624
2625
2626 for (size_t i=0; i<total_size; i++) {
2627 float newval=floor((image->get_value_at_index(i)-min)*bitmax/(max-min)
2628
2629 );
2630 if (newval<0) newval=0;
2631 if (newval>=bitmax) newval=bitmax-1.0f;
2632 image->set_value_at_index(i,newval);
2633 }
2634 }
2635 else {
2636 // In this version, we keep a specified number of significant bits in the floating point significand, leaving the exponent and sign alone
2637 if (floatbits>22) throw InvalidValueException(floatbits,"floatbits must be <23");
2638 unsigned int bitmask= 0xffffffff << (23-floatbits); // this will leave 1 in the sign and exponent bits, along with the specified number of significand bits
2639 for (size_t i=0; i<total_size; i++) {
2640 float newval=image->get_value_at_index(i);
2641 unsigned int *newvali = (unsigned int*)&newval;
2642 *newvali&=bitmask;
2643 image->set_value_at_index(i,newval);
2644 }
2645 }
2646}
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
#define InvalidValueException(val, desc)
Definition: exception.h:285

References InvalidValueException, EMAN::Processor::params, and EMAN::Dict::set_default().

Member Data Documentation

◆ NAME

const string SetBitsProcessor::NAME = "math.setbits"
static

Definition at line 2784 of file processor.h.

Referenced by get_name().


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