#include <processor.h>
Inheritance diagram for EMAN::ConvolutionKernelProcessor:
Public Member Functions | |
virtual EMData * | process (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 Processor * | NEW () |
Static Public Attributes | |
static const string | NAME = "filter.convolution.kernel" |
Definition at line 7033 of file processor.h.
string EMAN::ConvolutionKernelProcessor::get_desc | ( | ) | const [inline, virtual] |
Get the descrition of this specific processor.
This function must be overwritten by a subclass.
Implements EMAN::Processor.
Definition at line 7047 of file processor.h.
virtual string EMAN::ConvolutionKernelProcessor::get_name | ( | ) | const [inline, virtual] |
Get the processor's name.
Each processor is identified by a unique name.
Implements EMAN::Processor.
Definition at line 7039 of file processor.h.
References NAME.
07040 { 07041 return NAME; 07042 }
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.
Reimplemented from EMAN::Processor.
Definition at line 7051 of file processor.h.
References EMAN::EMObject::FLOATARRAY, and EMAN::TypeDict::put().
07052 { 07053 TypeDict d; 07054 d.put("kernel", EMObject::FLOATARRAY, "the convolution kernel"); 07055 return d; 07056 }
static Processor* EMAN::ConvolutionKernelProcessor::NEW | ( | ) | [inline, static] |
Definition at line 7043 of file processor.h.
07044 { 07045 return new ConvolutionKernelProcessor(); 07046 }
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.
image | The image will be copied, actual process happen on copy of image. |
Reimplemented from EMAN::Processor.
Definition at line 9921 of file processor.cpp.
References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, InvalidParameterException, EMAN::Processor::params, and sqrt().
09922 { 09923 if (image->get_zsize()!=1) throw ImageDimensionException("Only 2-D images supported"); 09924 09925 EMData* conv = new EMData(image->get_xsize(),image->get_ysize(),1); 09926 vector<float>kernel = params["kernel"]; 09927 09928 if (fmod(sqrt((float)kernel.size()), 1.0f) != 0) throw InvalidParameterException("Convolution kernel must be square!!"); 09929 09930 float* data = image->get_data(); 09931 float* cdata = conv->get_data(); // Yes I could use set_value_at_fast, but is still slower than this.... 09932 09933 //I could do the edges by wrapping around, but this is not necessary(such functionality can be iplemented later) 09934 int ks = int(sqrt(float(kernel.size()))); 09935 int n = (ks - 1)/2; 09936 int nx = image->get_xsize(); 09937 int ny = image->get_ysize(); 09938 for (int i = n; i < (nx - n); i++) { 09939 for (int j = n; j < (ny - n); j++) { 09940 //now do the convolution 09941 float cpixel = 0; 09942 int idx = 0; 09943 // Perahps I could use some ofrm of Caching to speed things up? 09944 for (int cx = -n; cx <= n; cx++) { 09945 for (int cy = -n; cy <= n; cy++) { 09946 cpixel += data[(i+cx) + (j+cy) * nx]*kernel[idx]; 09947 idx++; 09948 } 09949 } 09950 cdata[i + j * nx] = cpixel; 09951 } 09952 } 09953 09954 return conv; 09955 }
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.
image | The image to be processed. |
Implements EMAN::Processor.
Definition at line 9957 of file processor.cpp.
References UnexpectedBehaviorException.
09958 { 09959 throw UnexpectedBehaviorException("Not implemented yet"); 09960 09961 return; 09962 }
const string ConvolutionKernelProcessor::NAME = "filter.convolution.kernel" [static] |