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

#include <processor.h>

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

Public Member Functions

virtual EMDataprocess (const EMData *const image)
 To proccess an image out-of-place. More...
 
virtual void process_inplace (EMData *image)
 To process an image in-place. More...
 
virtual string get_name () const
 Get the processor's name. More...
 
string get_desc () const
 Get the descrition of this specific processor. More...
 
virtual TypeDict get_param_types () const
 Get processor parameter information in a dictionary. More...
 
- Public Member Functions inherited from EMAN::Processor
virtual ~Processor ()
 
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 = "filter.convolution.kernel"
 

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

Member Function Documentation

◆ get_desc()

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

9354 {
9355 return "Filters an image with a convolution kernel in real space.";
9356 }

◆ get_name()

virtual string EMAN::ConvolutionKernelProcessor::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 9345 of file processor.h.

9346 {
9347 return NAME;
9348 }
static const string NAME
Definition: processor.h:9363

References NAME.

◆ get_param_types()

virtual TypeDict EMAN::ConvolutionKernelProcessor::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 9357 of file processor.h.

9358 {
9359 TypeDict d;
9360 d.put("kernel", EMObject::FLOATARRAY, "the convolution kernel");
9361 return d;
9362 }
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::FLOATARRAY, and EMAN::TypeDict::put().

◆ NEW()

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

Definition at line 9349 of file processor.h.

◆ process()

EMData * ConvolutionKernelProcessor::process ( const EMData *const  image)
virtual

To proccess an image out-of-place.

For those processors which can only be processed out-of-place, override this function to give the right behavior.

Parameters
imageThe image will be copied, actual process happen on copy of image.
Returns
the image processing result, may or may not be the same size of the input image

Reimplemented from EMAN::Processor.

Definition at line 14150 of file processor.cpp.

14151{
14152 if (image->get_zsize()!=1) throw ImageDimensionException("Only 2-D images supported");
14153 int nx = image->get_xsize();
14154 int ny = image->get_ysize();
14155
14156 EMData* conv = new EMData(image->get_xsize(),image->get_ysize(),1);
14157
14158 int ks;
14159 vector<float> kernel;
14160 kernel = params["kernel"];
14161 ks = int(sqrt(float(kernel.size())));
14162 if (ks*ks != kernel.size()) throw InvalidParameterException("Convolution kernel must be square!!");
14163
14164 float* data = image->get_data();
14165 float* cdata = conv->get_data(); // Yes I could use set_value_at_fast, but is still slower than this....
14166
14167 //I could do the edges by wrapping around, but this is not necessary(such functionality can be iplemented later)
14168 int n = (ks - 1)/2;
14169 for (int i = n; i < (nx - n); i++) {
14170 for (int j = n; j < (ny - n); j++) {
14171 //now do the convolution
14172 float cpixel = 0;
14173 int idx = 0;
14174 // Perahps I could use some form of Caching to speed things up?
14175 for (int cx = -n; cx <= n; cx++) {
14176 for (int cy = -n; cy <= n; cy++, idx++) {
14177 cpixel += data[(i+cx)+(j+cy)*nx]*kernel[idx];
14178 }
14179 }
14180 cdata[i + j * nx] = cpixel;
14181 }
14182 }
14183
14184 return conv;
14185}
EMData stores an image's data and defines core image processing routines.
Definition: emdata.h:82
EMData * sqrt() const
return square root of current image
#define InvalidParameterException(desc)
Definition: exception.h:361
#define ImageDimensionException(desc)
Definition: exception.h:166

References ImageDimensionException, InvalidParameterException, EMAN::Processor::params, and sqrt().

◆ process_inplace()

void ConvolutionKernelProcessor::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 14187 of file processor.cpp.

14188{
14189 throw UnexpectedBehaviorException("Not implemented yet");
14190
14191 return;
14192}
#define UnexpectedBehaviorException(desc)
Definition: exception.h:400

References UnexpectedBehaviorException.

Member Data Documentation

◆ NAME

const string ConvolutionKernelProcessor::NAME = "filter.convolution.kernel"
static

Definition at line 9363 of file processor.h.

Referenced by get_name().


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