|
| 1 | +/*--------------------------- MegaWave2 Module -----------------------------*/ |
| 2 | +/* mwcommand |
| 3 | + name = {fgrain_side}; |
| 4 | + version = {"1.2"}; |
| 5 | + author = {"Pascal Monasse, Frederic Guichard, G. Facciolo"}; |
| 6 | + function = {"Grain filter of an image"}; |
| 7 | + usage = { |
| 8 | + 'a': [min_area=20]-> pMinArea "Min area of grains we keep", |
| 9 | + image_in -> pFloatImageInput "Input fimage", |
| 10 | + image_out <- pFloatImageOutput "Output fimage" |
| 11 | + }; |
| 12 | +*/ |
| 13 | +/*---------------------------------------------------------------------- |
| 14 | + v1.2 (04/2007): simplified header (LM) |
| 15 | + v1.3 (2013): portable version (GF) |
| 16 | + v1.4 (2014): fgrain_side: removes only upper (bright) or lower (dark) courves |
| 17 | +----------------------------------------------------------------------*/ |
| 18 | + |
| 19 | +#ifndef ABSTRACTIONGRAINPROCESS_H |
| 20 | +#define ABSTRACTIONGRAINPROCESS_H |
| 21 | + |
| 22 | +#include <QImage> |
| 23 | + |
| 24 | +#include "mw3.h" |
| 25 | +#include "mw3-modules.h" |
| 26 | +#include "stdio.h" |
| 27 | +#include "stdlib.h" |
| 28 | +#include "tree_of_shapes.h" |
| 29 | +#include <cfloat> |
| 30 | +#include "TreeOfShapes.h" |
| 31 | + |
| 32 | +enum Abstraction_Mode { COLOR_SKETCH=0, FILTER_COLOR=1, SHOW_TREE=2, SYNTEXTURE_COLOR=3, SYNTEXTURE_COLOR_WA=4, |
| 33 | + SYNTEXTURE_COLOR_DICT=5, SYNTEXTURE_COLOR_DICT2=6, SYNTEXTURE_COLOR_V2=7, |
| 34 | + SYNTEXTURE_COLOR_V3=8, SYNTEXTURE_COLOR_V4=9, |
| 35 | + SYNTEXTURE_COLOR_DICT2_OUTPUT=10, SYNTEXTURE_COLOR_DICT3=11, SYNTEXTURE_COLOR_MULT=12, |
| 36 | + SYNTEXTURE_COLOR_TT=13}; |
| 37 | + |
| 38 | +class AbstractionProcess |
| 39 | +{ |
| 40 | +public: |
| 41 | + AbstractionProcess(){ _image_loaded = false; } |
| 42 | + AbstractionProcess( std::string fileNameIn ); |
| 43 | + AbstractionProcess( const QImage &imageIn ); |
| 44 | + ~AbstractionProcess(); |
| 45 | + |
| 46 | + QImage run (int process, char* dictionnary_name); |
| 47 | + QImage render(TOSParameters tosParameters, bool &tree_recomputed, DictionaryParameters dictionaryParameters = getDefaultDictionaryParameters(), TreeOfShapes * dictionnary=NULL); |
| 48 | + std::vector<QImage> render_shape_by_shape(TOSParameters tosParameters, DictionaryParameters dictionaryParameters, TreeOfShapes * dictionnary); |
| 49 | + void addDictionnary( TreeOfShapes * dictionary ); |
| 50 | + |
| 51 | + void save_shapes( QString folder_name, bool average_color ){ _treeOfShapes->save_shapes(folder_name, average_color); } |
| 52 | + void save_shapes( QString folder_name, TOSParameters tosParameters, DictionaryParameters dictionaryParameters = getDefaultDictionaryParameters(), TreeOfShapes * dictionnary=NULL ); |
| 53 | + TOSParameters getParameters(){return _tosParameters;} |
| 54 | + int getMaxArea(){return _treeOfShapes->getMaxArea();} |
| 55 | + void getTreeInfo(std::vector<QPoint> &positions, std::vector<QColor> &colors, |
| 56 | + std::vector< std::vector< std::pair<int, int> > > &pixels, std::vector<int> & heights, std::vector<std::pair<int, int> > &edges){ |
| 57 | + _treeOfShapes->getTreeInfo(positions, colors, pixels, heights, edges); |
| 58 | + } |
| 59 | +protected: |
| 60 | + bool _tree_computed; |
| 61 | + Cfimage _imgin; |
| 62 | + bool _image_loaded; |
| 63 | + |
| 64 | + TreeOfShapes *_treeOfShapes; |
| 65 | + TreeOfShapes *_dictionnary; |
| 66 | + |
| 67 | + Shapes _pTree; |
| 68 | + |
| 69 | + Fimage _NormOfDu; |
| 70 | + |
| 71 | + TOSParameters _tosParameters; |
| 72 | + |
| 73 | + void init(Cfimage inputImg, Shapes &pTree); |
| 74 | + |
| 75 | + Cfimage cfimageread(const char* name); |
| 76 | + |
| 77 | + Cfimage cfimages_from_qimage( const QImage &input_image ); |
| 78 | + |
| 79 | + QImage qimages_from_cfimage( Cfimage input_img ); |
| 80 | + |
| 81 | + QImage qimages_from_ccimage( Ccimage input_img ); |
| 82 | + |
| 83 | + /* This removes the shapes from the tree associated to pFloatImageInput |
| 84 | + that are too small (threshold *pMinArea). As a consequence all the remaining |
| 85 | + shapes of pFloatImageOutput are of area larger or equal than *pMinArea */ |
| 86 | + |
| 87 | + void mw_fgrain_side(int *pMinArea, Fimage pFloatImageInput, Fimage pFloatImageOutput, int sideflag); |
| 88 | + |
| 89 | + |
| 90 | + /*in and out must be allocated*/ |
| 91 | + void fgrain_side(int MinArea, float *in, int nx, int ny, float *out, int sideflag); |
| 92 | + |
| 93 | + Shape m_order_parent(Shape pShape, |
| 94 | + int *mn, |
| 95 | + bool dict = false); |
| 96 | + void Order(Fsignal t2b_index, |
| 97 | + int *p, int *q); |
| 98 | + void Bubble( Fsignal t2b_index); |
| 99 | + |
| 100 | + void shape_orilam(Shape pShape,float *out_ori, float *out_e, float *out_k); |
| 101 | + void shape_orilam(Shape pShape, float *out_ori, float *out_e, float *out_k, float *pX0, float *pY0); |
| 102 | + void compute_shape_attribute(); |
| 103 | + |
| 104 | + float min_contrast(Shape pShape); |
| 105 | + |
| 106 | + void synshapeEllipse(Shape pShape, |
| 107 | + Ccimage imgsyn, |
| 108 | + float *alpha, |
| 109 | + int *relief, |
| 110 | + float *reliefOrentation, float *reliefHeight); |
| 111 | + void synshapeRect(Shape pShape, |
| 112 | + Ccimage imgsyn, |
| 113 | + float *alpha, |
| 114 | + int *relief, |
| 115 | + float *reliefOrentation, float *reliefHeight); |
| 116 | + void synshapeOriginal(Shape pShape, |
| 117 | + Ccimage imgsyn, |
| 118 | + Cimage imgShapeLabelSyn, |
| 119 | + Fimage imgShapeBlurSyn, |
| 120 | + Fsignal gaussKernel, |
| 121 | + int *median, |
| 122 | + float *alpha, |
| 123 | + int *relief, |
| 124 | + float *reliefOrentation, float *reliefHeight); |
| 125 | + void synshapeOriginal( Shape pShape, |
| 126 | + Ccimage imgsyn, |
| 127 | + float *alpha); |
| 128 | + |
| 129 | + void top2bottom_index_tree(Fsignal t2b_index); |
| 130 | + void random_tree_order(Fsignal t2b_index); |
| 131 | + |
| 132 | + void random_leaf(Fsignal leaf, |
| 133 | + Fsignal t2b_index, |
| 134 | + int *k_ind); |
| 135 | + |
| 136 | + void random_shift_shape(float *shift); |
| 137 | + void adaptive_shift_shape(float *shift, |
| 138 | + float *theta); |
| 139 | + float mean_contrast(Shape pShape); |
| 140 | + |
| 141 | + Fsignal sgauss(float *std, |
| 142 | + Fsignal out, |
| 143 | + int *size); |
| 144 | + Fsignal Sgauss(float *std, Fsignal out, int *size); |
| 145 | + |
| 146 | + float peri_shape(Shape pShape); |
| 147 | + |
| 148 | + void compute_shape_attribute(int *ns); |
| 149 | + void filter_image(int *ns, |
| 150 | + float *alpha, |
| 151 | + int *mpixel); |
| 152 | + void filter_shapes( Fimage sketch, |
| 153 | + Cfimage out, |
| 154 | + char *local, |
| 155 | + float *eps); |
| 156 | + void get_shapes_truearea(Shape s, Shape root, |
| 157 | + int *truearea); |
| 158 | + |
| 159 | + Shape selectShapeDict(Shapes pTreeDict, |
| 160 | + Shape pShape, |
| 161 | + float *paDict, |
| 162 | + int *randS); |
| 163 | + int random_number(int *M); |
| 164 | +}; |
| 165 | + |
| 166 | +#endif // ABSTRACTIONGRAINPROCESS_H |
0 commit comments