#ifndef DSP2D_H #define DSP2D_H using namespace std; #include #include #include #include #include #include #include #include #include #include class KERNEL_MANAGER; // Forward declarations class KERNEL2D; class CACHE2D; class DSP2D; class DSP2D { public: DSP2D(unsigned int width=0, unsigned int height=0); ~DSP2D(); void getMinMax (int&,int&); void resize (unsigned int width, unsigned int height); unsigned int width (); unsigned int height (); double get (int, int); void set (int, int, double); double & operator[](unsigned int); void operator *=(double); // Multiply with gray values void operator +=(double); // Add to gray values void resetPixelCounter(); double getNextPixel(); void setNextPixel(double); private: string x; unsigned int w,h; unsigned long pixelCounter; unsigned long top; double *data; friend class CACHE2D; friend class KERNEL2D; }; class KERNEL_MANAGER { // Delivers kernel information public: // The manager is needed to resolve the recursive definitions inside of the kernel files // It stores kernels according to their names KERNEL2D* resolve (const string); // Deliver the kernel with this name or NULL if not found void resolveAll (); // Call resolve() on all known kernels void checkin (string &, KERNEL2D*); // Store a kernel void checkout (string &); // Remove kernel from storage void deleteAll (); // Delete all pointers - checkoutAll is called first void clearCaches(); // Clear all filter caches private: map kernels; // Kernel store bool changed; // True if checkin/out since last resolveAll() }; class KFactor { // Kernel factor class public: // krn==NULL means 'take the input data' all other settings will use recursion to other kernels KFactor(); KFactor(string); // Constructor - name=="" will set krn to NULL void ins (int,int); // Insert new volterra parameter double get (DSP2D&,int,int); void res (KERNEL_MANAGER*); // Resolve kernel name using this manager void save (ofstream&); int size (); void clear(); private: KERNEL2D* krn; // Pointer to recursion - if NULL,this kernel will take the input, if not it will take the output of another kernel multiset > volterra; // Volterra factors string name; // Filter name }; class CACHE2D { // The cache works automagically - it stores up to three results (whole images) public: // Every kernel gets one CACHE2D(); ~CACHE2D(); // It avoids pixel recalculations in case of filter-of filters definitions (P 1.0 0 0 KERNEL 0 0 KERNEL ....) void set (DSP2D&,long,double ); // Set value for DSP2D% source image at posiiton long bool get (DSP2D&,long,double&); // Returns true and value if value was cached void clear(); // Reset cache private: map > cdata; // Cached data }; class KERNEL2D { public: KERNEL2D(KERNEL_MANAGER*); // Constructor KERNEL2D(const char*,KERNEL_MANAGER*); ~KERNEL2D(); // The volterra product is generated by calling insert(x,y) many times // after all coefficients were defined, the prduct is closed with weight() double getFilter (DSP2D&, int, int); void filter (DSP2D&, DSP2D&, int, int); // Filter at position x,y void filter (DSP2D&, DSP2D&); // Filter the whole image void save (const char*); // Save filter void load (const char*); // Load filter void clear (); void resolve (); // Resolves the names of the kernels to pointers void insert (int,int); void weight (double); bool isHidden (); // True if the filter should not be visible in the user menus void clearCache(); string getName (); private: double getConv (DSP2D&, int, int); // Convolution void convolve(DSP2D&, DSP2D&, int, int); void convolve(DSP2D&, DSP2D&); double getMorph(DSP2D&, int, int); // Math. morphology void morph (DSP2D&, DSP2D&, int, int); void morph (DSP2D&, DSP2D&); double getRank (DSP2D&, int, int); // Ranking filter void rank (DSP2D&, DSP2D&, int, int); void rank (DSP2D&, DSP2D&); void clean (); // Only if !morph_on: remove zero-weighted summands void calcSel (); // Calculates some parameters used in morphology mode bool morph_on, // Marks a morphologic filter rank_on; // Marks a rank filter double morph_select, // Selection [0;1] - used in morphologic filters (morph_on==true) rank_scale; // Scaling of the rank filter's output int morph_select1, morph_select2; // Weighted integer selection - generated by calcSel double morph_weight1, morph_weight2; KFactor buffer; map,double> FDescriptor; // The filter description string name; // Name of this filter KERNEL_MANAGER *manager; // The kernel manager is needed to resolve kernel names to pointers CACHE2D *ch; // The result cache }; #endif