#include <processor.h>
Inheritance diagram for EMAN::WaveletProcessor:
Public Member Functions | |
virtual void | process_inplace (EMData *image) |
To process an image in-place. | |
virtual string | get_name () const |
Get the processor's name. | |
virtual TypeDict | get_param_types () const |
Get processor parameter information in a dictionary. | |
virtual string | get_desc () const |
Get the descrition of this specific processor. | |
Static Public Member Functions | |
static Processor * | NEW () |
Static Public Attributes | |
static const string | NAME = "basis.wavelet" |
type | "daub", "harr", or "bspl" | |
dir | 1 for forward transform, -1 for inverse transform | |
ord | for Daubechies (4,6,8,...,20), for Harr (2), for B-Splines (103, 105, 202, 204, 206, 208, 301, 303, 305 307, 309) |
Definition at line 6678 of file processor.h.
virtual string EMAN::WaveletProcessor::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 6702 of file processor.h.
06703 { 06704 return "Computes the DWT (discrete wavelet transform) of an image in one of 3 possible bases"; 06705 }
virtual string EMAN::WaveletProcessor::get_name | ( | ) | const [inline, virtual] |
Get the processor's name.
Each processor is identified by a unique name.
Implements EMAN::Processor.
Definition at line 6683 of file processor.h.
References NAME.
Referenced by process_inplace().
06684 { 06685 return NAME; 06686 }
virtual TypeDict EMAN::WaveletProcessor::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 6693 of file processor.h.
References EMAN::EMObject::INT, EMAN::TypeDict::put(), and EMAN::EMObject::STRING.
06694 { 06695 TypeDict d; 06696 d.put("type", EMObject::STRING, "'daub', 'harr' or 'bspl'"); 06697 d.put("dir", EMObject::INT, "1 for forward transform, -1 for inverse transform"); 06698 d.put("ord", EMObject::INT, "Daubechies (4,6,8,...,20), for Harr (2), for B-Splines (103, 105, 202, 204, 206, 208, 301, 303, 305 307, 309)"); 06699 return d; 06700 }
static Processor* EMAN::WaveletProcessor::NEW | ( | ) | [inline, static] |
void WaveletProcessor::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 8191 of file processor.cpp.
References get_name(), EMAN::EMData::get_value_at(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, InvalidStringException, EMAN::Util::IsPower2(), LOGERR, EMAN::Processor::params, and EMAN::EMData::set_value_at_fast().
08192 { 08193 if (image->get_zsize() != 1) { 08194 LOGERR("%s Processor doesn't support 3D", get_name().c_str()); 08195 throw ImageDimensionException("3D model not supported"); 08196 } 08197 08198 int i,nx,ny; 08199 const gsl_wavelet_type * T; 08200 nx=image->get_xsize(); 08201 ny=image->get_ysize(); 08202 08203 if (nx != ny && ny!=1) throw ImageDimensionException("Wavelet transform only supports square images"); 08204 // float l=log((float)nx)/log(2.0f); 08205 // if (l!=floor(l)) throw ImageDimensionException("Wavelet transform size must be power of 2"); 08206 if( !Util::IsPower2(nx) ) throw ImageDimensionException("Wavelet transform size must be power of 2"); 08207 08208 // Unfortunately GSL works only on double() arrays 08209 // eventually we should put our own wavelet code in here 08210 // but this will work for now 08211 double *cpy = (double *)malloc(nx*ny*sizeof(double)); 08212 08213 for (i=0; i<nx*ny; i++) cpy[i]=image->get_value_at(i,0,0); 08214 08215 string tp = (const char*)params["type"]; 08216 if (tp=="daub") T=gsl_wavelet_daubechies; 08217 else if (tp=="harr") T=gsl_wavelet_haar; 08218 else if (tp=="bspl") T=gsl_wavelet_bspline; 08219 else throw InvalidStringException(tp,"Invalid wavelet name, 'daub', 'harr' or 'bspl'"); 08220 08221 int K=(int)params["ord"]; 08222 gsl_wavelet_direction dir; 08223 if ((int)params["dir"]==1) dir=forward; 08224 else dir=backward; 08225 08226 gsl_wavelet *w = gsl_wavelet_alloc(T, K); 08227 gsl_wavelet_workspace *work = gsl_wavelet_workspace_alloc(nx); 08228 08229 if (ny==1) gsl_wavelet_transform (w,cpy, 1, nx, dir, work); 08230 else gsl_wavelet2d_transform (w, cpy, nx,nx,ny, dir, work); 08231 08232 gsl_wavelet_workspace_free (work); 08233 gsl_wavelet_free (w); 08234 08235 for (i=0; i<nx*ny; i++) image->set_value_at_fast(i,0,0,static_cast<float>(cpy[i])); 08236 08237 free(cpy); 08238 }
const string WaveletProcessor::NAME = "basis.wavelet" [static] |