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

EMAN::ConvolutionKernalProcessor Class Reference

#include <processor.h>

Inheritance diagram for EMAN::ConvolutionKernalProcessor:

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

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

ProcessorNEW ()

Static Public Attributes

const string NAME = "convkernal"

Member Function Documentation

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

06934                 {
06935                         return "Filters an image with a convolution kernal.";
06936                 }

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

06926                 {
06927                         return NAME;
06928                 }

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

References EMAN::TypeDict::put().

06938                 {
06939                         TypeDict d;
06940                         d.put("kernal", EMObject::FLOATARRAY, "the convolution kernal");
06941                         return d;
06942                 }

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

Definition at line 6929 of file processor.h.

06930                 {
06931                         return new ConvolutionKernalProcessor();
06932                 }

EMData * ConvolutionKernalProcessor::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:
image The 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 9731 of file processor.cpp.

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

09732 {
09733         if (image->get_zsize()!=1) throw ImageDimensionException("Only 2-D images supported");
09734         
09735         EMData* conv = new EMData(image->get_xsize(),image->get_ysize(),1);
09736         vector<float>kernal = params["kernal"];
09737 
09738         if (fmod(sqrt((float)kernal.size()), 1.0f) != 0) throw InvalidParameterException("Convolution kernal must be square!!");
09739         
09740         float* data = image->get_data();
09741         float* cdata = conv->get_data();        // Yes I could use set_value_at_fast, but is still slower than this....
09742         
09743         //I could do the edges by wrapping around, but this is not necessary(such functionality can be iplemented later)
09744         int ks = sqrt((float)kernal.size());
09745         int n = (ks - 1)/2;
09746         int nx = image->get_xsize();
09747         int ny = image->get_ysize();
09748         for (int i = n; i < (nx - n); i++) {
09749                 for (int j = n; j < (ny - n); j++) {
09750                         //now do the convolution
09751                         float cpixel = 0;
09752                         int idx = 0;
09753                         // Perahps I could use some ofrm of Caching to speed things up?
09754                         for (int cx = -n; cx <= n; cx++) {
09755                                 for (int cy = -n; cy <= n; cy++) {
09756                                         cpixel += data[(i+cx) + (j+cy) * nx]*kernal[idx];
09757                                         idx++;
09758                                 }
09759                         }
09760                         cdata[i + j * nx] = cpixel;
09761                 }
09762         }
09763         
09764         return conv;
09765 }

void ConvolutionKernalProcessor::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 9767 of file processor.cpp.

References UnexpectedBehaviorException.

09768 {
09769         throw UnexpectedBehaviorException("Not implemented yet");
09770         
09771         return;
09772 }


Member Data Documentation

const string ConvolutionKernalProcessor::NAME = "convkernal" [static]
 

Definition at line 243 of file processor.cpp.


The documentation for this class was generated from the following files:
Generated on Mon May 2 13:30:58 2011 for EMAN2 by  doxygen 1.3.9.1