TarzaNN
TarzaNN neural network simulator
C:/Users/albertlr/projects/TarzaNN/TarzaNN/Filter.h
Go to the documentation of this file.
00001 #ifndef FILTER_H_INCLUDED
00002 #define FILTER_H_INCLUDED
00003 
00004 #include "common.h"
00005 #include "Matrix.h"
00006 #include <math.h>
00007 #include "nowarn.h"
00008 #include <QMutex>
00009 #include <QLinkedList>
00010 #include <QTextStream>
00011 
00012 #define EVEN_FILTERS
00013 
00014 class GatingUnits;
00015 
00016 /*how to extend images for convolution*/
00017 enum
00018 {
00019     convolutionMirror           =       2,      /* Mirror border pixels, width determined by filter size*/
00020     convolutionFill                     =       4,      /* Use the background color for missing pixels (?)*/
00021     convolutionEdgeExtend       =       8,      /* Repeat edge pixels*/
00022 };
00023 
00024 class FilterOperation {
00025 public:
00026         FilterOperation(QString theName,QString theValue) {
00027                 name = theName;
00028                 value = theValue;
00029         };
00030         FilterOperation() {};
00031         QString name;
00032         QString value;
00033 };
00034 
00036 class Filter: public Matrix {
00037         friend class UI_FilterProp;
00038         friend class UI_DesignerPropDisplay;
00039 public:
00041     Filter(int w, int h);
00042         Filter(QString fileName, int fileType); 
00044         float* getKernel();
00046     void _convolve( Matrix* input, Matrix* output);
00048     void convolve( Matrix* input, Matrix* output, bool scale=true);
00050     void STMconvolve( Matrix* input, GatingUnits* gu);
00052     void setFromConvolveWindow(int _x1,int _y1, int _w, int _h);
00053 
00055     static void _convolveRetinal( Matrix* input, Matrix* output, int padding, int distPixels);
00056     static void destroyRetinalImageFilters();
00057     static Filter* retinalImageFilters[1024];
00058     static int retinalImageFilterNo;
00059     static int retinalImageFilterSize;
00060     static QMutex retinalMutex;
00061     
00063     void setPaddingType(int _type);
00064     int getPaddingType();
00066     void separateKernel();
00068     static void svd(double **a, int m, int n, double w[], double **v);
00069     static double pythag(double a,double b) ;
00070     ~Filter();
00071 
00073         void addOperation(const QString &opName, const QString &opValue);
00074 
00075         void setParameters(paramMap params);
00076         void XMLSerialize(int tabs, QTextStream *buf);
00077         static int getType(const QString & name);
00078         static QString getType(int value);
00079         
00080 #ifdef ST_CONVOLVE
00081         static double compute_skip( int input, int output, int filter){
00082             return (double)(input-filter)/(double)(output-1);
00083         }
00084 #else
00085         static int computeSkip(int input, int output){
00086                 return (int)(input/output);
00087         }
00088 #endif//ST_CONVOLVE
00089 
00090     // should be protected, Gfilter friend, etc
00091     float l1_norm, l2_norm;
00092     int env_x, env_y;
00093     int pos_x, pos_y;
00094     void adjust_l(float l1, float l2);
00095         QImage* getPreviewImage();
00096 
00097     // filter type
00098     int fType;
00099         
00100 protected:
00102     int separable_status;
00103     enum {SEPARABLE_NOT_CHECKED, SEPARABLE_NO, SEPARABLE_YES};
00105     Filter **separated_filters; //for now only2
00106 
00107     void find_limits( int w, int h, float sigma, float aspect, float orientation, float& h_m_x, float& h_m_y);
00109     Filter* nextFilter;
00110         
00111         paramMap initParams;
00112         QLinkedList<FilterOperation> operations;
00113 
00114 private:
00115     Filter();
00117         float* kernel;
00120     bool useConvolveWindow;
00121     int convolve_x1, convolve_y1;
00122     int convolve_w, convolve_h;
00123 
00129     int padding_type;
00130 
00131 #ifdef VIMAGE_H
00132     void* tempConvBuffer;
00133         void* tempScaleBuffer;
00134 #endif  
00135 };
00136 
00137 #endif //FILTER_H_INCLUDED
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines