EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes
EMAN::ConvolutionKernelProcessor Class Reference

#include <processor.h>

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

List of all members.

Public Member Functions

virtual EMDataprocess (const EMData *const image)
 To proccess an image out-of-place.
virtual void process_inplace (EMData *image)
 To process an image in-place.
virtual string get_name () const
 Get the processor's name.
string get_desc () const
 Get the descrition of this specific processor.
virtual TypeDict get_param_types () const
 Get processor parameter information in a dictionary.

Static Public Member Functions

static ProcessorNEW ()

Static Public Attributes

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

Detailed Description

Definition at line 7446 of file processor.h.


Member Function Documentation

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

                {
                        return "Filters an image with a convolution kernel in real space.";
                }
virtual string EMAN::ConvolutionKernelProcessor::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 7452 of file processor.h.

References NAME.

                {
                        return NAME;
                }
virtual TypeDict EMAN::ConvolutionKernelProcessor::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 7464 of file processor.h.

References EMAN::EMObject::FLOATARRAY, and EMAN::TypeDict::put().

                {
                        TypeDict d;
                        d.put("kernel", EMObject::FLOATARRAY, "the convolution kernel");
                        return d;
                }
static Processor* EMAN::ConvolutionKernelProcessor::NEW ( ) [inline, static]

Definition at line 7456 of file processor.h.

                {
                        return new ConvolutionKernelProcessor();
                }
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 10635 of file processor.cpp.

References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, InvalidParameterException, nx, EMAN::Processor::params, and sqrt().

{
        if (image->get_zsize()!=1) throw ImageDimensionException("Only 2-D images supported");

        EMData* conv = new EMData(image->get_xsize(),image->get_ysize(),1);
        vector<float>kernel = params["kernel"];

        if (fmod(sqrt((float)kernel.size()), 1.0f) != 0) throw InvalidParameterException("Convolution kernel must be square!!");

        float* data = image->get_data();
        float* cdata = conv->get_data();        // Yes I could use set_value_at_fast, but is still slower than this....

        //I could do the edges by wrapping around, but this is not necessary(such functionality can be iplemented later)
        int ks = int(sqrt(float(kernel.size())));
        int n = (ks - 1)/2;
        int nx = image->get_xsize();
        int ny = image->get_ysize();
        for (int i = n; i < (nx - n); i++) {
                for (int j = n; j < (ny - n); j++) {
                        //now do the convolution
                        float cpixel = 0;
                        int idx = 0;
                        // Perahps I could use some ofrm of Caching to speed things up?
                        for (int cx = -n; cx <= n; cx++) {
                                for (int cy = -n; cy <= n; cy++) {
                                        cpixel += data[(i+cx) + (j+cy) * nx]*kernel[idx];
                                        idx++;
                                }
                        }
                        cdata[i + j * nx] = cpixel;
                }
        }

        return conv;
}
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 10671 of file processor.cpp.

References UnexpectedBehaviorException.

{
        throw UnexpectedBehaviorException("Not implemented yet");

        return;
}

Member Data Documentation

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

Definition at line 7470 of file processor.h.

Referenced by get_name().


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