diff --git a/app/Algorithms/Pyramid.cpp b/app/Algorithms/Pyramid.cpp index ca113371d3127d932485a7cee0f9869230529b9d..d9ad535c02cdd9e5d8a6d6d61a1017aab93b576d 100644 --- a/app/Algorithms/Pyramid.cpp +++ b/app/Algorithms/Pyramid.cpp @@ -257,7 +257,7 @@ Image *Pyramid::pyram_g(const GrayscaleImage *im, int etage_f, Filtre &utile, st if( etage_f < 1 ) etage_f = 1; pyram_g_n(rep, etage_f, nbc, nbl, itab, utile); - to_print = entropie_p(rep, etage_f, nbc, nbl); + to_print = entropie_p(rep, etage_f, nbc, nbl); reconstruction(rep, etage_f, nbc, nbl); return resImg; @@ -265,7 +265,7 @@ Image *Pyramid::pyram_g(const GrayscaleImage *im, int etage_f, Filtre &utile, st /*--------------------------------------------------------------------------- Cration d'un tage de la pyramide Gaussienne ---------------------------------------------------------------------------*/ -Image *Pyramid::n_pyram_g(const Image *im, int etage_f, Filtre &utile ) +Image *Pyramid::n_pyram_g(const Image *im, int etage_f, Filtre &utile, std::string &to_print) { if(!( im != NULL )) { throw "Error in Pyramid::pyram_g:\nim = NULL"; @@ -305,6 +305,7 @@ Image *Pyramid::n_pyram_g(const Image *im, int etage_f, Filtre &utile ) rep[i] = tab[i+k]; } delete[] tab; + to_print = n_entropie_p(rep, etage_f, nbc, nbl); return resImg; } /*--------------------------------------------------------------------------- @@ -334,7 +335,7 @@ Image *Pyramid::pyram_l (const Image *im, int etage_f, Filtre &utile, string &to if( etage_f < 1 ) etage_f = 1; pyram_l_n(rep,etage_f,nbc,nbl,itab,utile); - to_print = entropie_p(rep,etage_f,nbc,nbl); + to_print = entropie_p(rep, etage_f, nbc, nbl); reconstruction(rep,etage_f,nbc,nbl); return resImg; @@ -343,7 +344,7 @@ Image *Pyramid::pyram_l (const Image *im, int etage_f, Filtre &utile, string &to /*--------------------------------------------------------------------------- Cration d'un tage de la pyramide Laplacienne ---------------------------------------------------------------------------*/ -Image *Pyramid::n_pyram_l(const Image *im, int etage_f, Filtre &utile) +Image *Pyramid::n_pyram_l(const Image *im, int etage_f, Filtre &utile, std::string &to_print) { if(!( im != NULL )) { throw "Error in Pyramid::pyram_g:\nim = NULL"; @@ -383,6 +384,7 @@ Image *Pyramid::n_pyram_l(const Image *im, int etage_f, Filtre &utile) { rep[i] = tab[i+k]; } + to_print = n_entropie_p(rep, etage_f, nbc, nbl); delete[] tab; return resImg; } @@ -665,6 +667,24 @@ string Pyramid::entropie_p(const uint8_t *pyra,int etage_f,int nbc,int nbl) return returnval; } +string Pyramid::n_entropie_p(const uint8_t *pyra,int etage_f,int nbc,int nbl) +{ + int i; + float h; + int taille_c=nbc; + int taille_l=nbl; + for(i=0;i<etage_f;i++) + { + taille_c=taille_c/2; + taille_l=taille_l/2; + } + char buffer[255]; + string returnval; + h=entropie2(pyra,taille_c,taille_l); + sprintf(buffer, QString(qApp->translate("Operations","L'entropie de l'etage %d est %1f\n")).toUtf8(),i,h); + returnval = returnval + buffer; + return returnval; +} Image *Pyramid::rebuild_interface( const Image *pyramid, int etage_f, int pyramid_to, Filtre &utile ) { // rebuilds from an image that was saved diff --git a/app/Algorithms/Pyramid.h b/app/Algorithms/Pyramid.h index 3a213df77814939799b2a96bc9100e99e1985ce5..f62dfb519801e27c3782e291faae0de3f49a001c 100644 --- a/app/Algorithms/Pyramid.h +++ b/app/Algorithms/Pyramid.h @@ -24,49 +24,282 @@ #include <GrayscaleImage.h> #include <string> + +/*! + * \brief + * + * \param + * \return +*/ + namespace Pyramid -{ +{ + /*! + * \brief return if a number is a Powerof2 or not + * \param n the number to test + * \return true if n is a power of2 false otherwise + */ inline bool isPowerOf2(int n) { return ( ( n > 0 ) && ( (n & (n - 1) ) == 0) ); } + /*! + * \struct Filtre + * \Brief A stucture reprensenting a filter + * + * Coefficients are given to only one side of the filter, we use symetry for the others + * example : if coeff_f = {1, 0.5 , 0.25, ...}, the filter really applied is {..., 0.25, 0.5, 1, 0.5, 0.25, ..} + * Size is the maximum index to search for coefficient in the coeff_f[] + */ struct Filtre { - char nom_f[30]; - float coeff_f[10]; - int taille_f; + char nom_f[30]; //!< Name of the filter + float coeff_f[10]; //!< Coefficient of the filter + int taille_f; //!< Size of the filter }; + /*! + * \Class Filters + * \Brief A class used for pyramid operation + * + * This class regroup all all the filters possible in a tab + */ class Filters { public: Filters(); virtual ~Filters(); + /** + * @brief Retrieve a filter in the filters array with its position + * + * @param pos the position of the filter in the array + * @param to_fill the pointer where the filter will be return + * @return true if the filter was found + * @return false if the filter was not found + */ bool getFromPos( int pos, Filtre &to_fill ); + + /** + * @brief Retrieve a filter in the filters array with its name + * + * @param name the name of the filter + * @param to_fill the pointer to return the found filter in + * @return true if the filter was found + * @return false if the filter was not found + */ bool getFromName( const char *name, Filtre &to_fill ); + /** + * @brief Get the Default filter + * + * @param to_fill the pointer to return the filter in + */ void getDefault( Filtre &to_fill ); + /** + * @brief get the number of filter in the filters array + * + * @return int the number of filter + */ int size(); private: - const Filtre *filters; - int num_filters; - void copy_filter( const Filtre &source, Filtre &dest ); + const Filtre *filters; //!< Array keeping every filter available + int num_filters; //!< Number of available filter + /** + * @brief Copy a filter + * + * @param source filter to copy + * @param dest destination filter + */ + void copy_filter( const Filtre &source, Filtre &dest ); }; + /** + * @brief Create the next level of a gaussian pyramid + * + * @param srcTab previous level data + * @param dstTab new level data + * @param srcWidth Width of the previous level + * @param srcHeight hegiht of the previous level + * @param utile the filter to use + */ void etage_suiv_g(const uint8_t *srcTab, uint8_t *dstTab, int srcWidth, int srcHeight, Filtre &utile); + + /** + * @brief Create a gaussian pyramid + * + * @param rep the created pyramid + * @param nStage number of level wanted in the pyramid + * @param nbc width of the original image + * @param nbl height of the original image + * @param itab source image + * @param utile filter to use + */ void pyram_g_n(uint8_t *rep, int nStage, long nbc, long nbl, const uint8_t *itab, Filtre &utile); + + /** + * @brief Create a laplacian pyramid + * + * @param rep the created pyramid + * @param nStage number of level wanted in the pyramid + * @param nbc width of the original image + * @param nbl height of the original image + * @param itab source image + * @param utile filter to use + */ void pyram_l_n (uint8_t *rep,int n, long nbc, long nbl, const uint8_t *itab, Filtre &utile); + + /** + * @brief Create a gaussian pyramid and return an image of it + * + * @param im the to build pyramid from + * @param etage_f number of level in the pyramid + * @param utile filter to use + * @param to_print text to print in the log window + * @return imagein::Image* the image of the new pyramid + */ imagein::Image *pyram_g(const imagein::GrayscaleImage *im, int etage_f, Filtre &utile, std::string &to_print); - imagein::Image *n_pyram_g(const imagein::Image *im, int etage_f, Filtre &utile ); + + /** + * @brief Create a level of a gaussian pyramid and return an image of it + * + * @param im the to build pyramid from + * @param etage_f number of the level to create + * @param utile filter to use + * @return imagein::Image* the image of the new pyramid + */ + imagein::Image *n_pyram_g(const imagein::Image *im, int etage_f, Filtre &utile, std::string &to_print); + + /** + * @brief Create a Laplacian pyramid and return an image of it + * + * @param im the to build pyramid from + * @param etage_f number of level in the pyramid + * @param utile filter to use + * @param to_print text to print in the log window + * @return imagein::Image* the image of the new pyramid + */ imagein::Image *pyram_l (const imagein::Image *im, int etage_f, Filtre &utile, std::string &to_print); - imagein::Image *n_pyram_l(const imagein::Image *im, int etage_f, Filtre &utile); + + /** + * @brief Create a level of a gaussian pyramid and return an image of it + * + * @param im the to build pyramid from + * @param etage_f number of the level to create + * @param utile filter to use + * @return imagein::Image* the image of the new pyramid + */ + imagein::Image *n_pyram_l(const imagein::Image *im, int etage_f, Filtre &utile, std::string &to_print); + + /** + * @brief Proccess the value by applying filter on lign + * + * @param tab data of the lign + * @param cl number of column + * @param x position of the pixel + * @param y position of the pixel + * @param utile filter to apply + * @return uint8_t the value of the pixel + */ uint8_t filt_point_1d_lg(const uint8_t *tab,int cl, int x, int y, Filtre &utile); + /** + * @brief Proccess the value by applying filter on column + * + * @param tab data of the column + * @param cl number of lign + * @param x position of the pixel + * @param y position of the pixel + * @param utile filter to apply + * @return uint8_t the value of the pixel + */ uint8_t filt_point_1d_cl(const uint8_t *tab,int lg,int cl, int x, int y, Filtre &utile); + + /** + * @brief apply filtering on a lign + * + * @param ligne the data of the lign + * @param taille_c number of column + * @param utile filter to apply + */ void filt_ligne(uint8_t *ligne,int taille_c, Filtre &utile); + + /** + * @brief apply filtering on a c + * + * @param tab the data of the column + * @param taille_c number of column + * @param taille_l number of lign + * @param utile filter to apply + */ void filt_tab_cl(uint8_t *tab,int taille_c,int taille_l, Filtre &utile); + + /** + * @brief Enlarging an image (with filtering) + * + * @param petit the input image + * @param grand the output image + * @param taille_c number of column + * @param taille_l number of lign + * @param utile filter to apply + */ void agrandir(uint8_t *petit,uint8_t *grand,int taille_c,int taille_l, Filtre &utile); + /** + * @brief + * + * @param pyra the pyramide + * @param n the number of level + * @param nbc number of column + * @param nbl number of lign + */ void reconstruction(uint8_t *pyra,int n, long nbc, long nbl); + + /** + * @brief process the maximum number of level for an image + * + * @param im input image + * @return int the maximum number of level + */ int etage_max(const imagein::Image *im); + + /** + * @brief proccess the entropy of an image + * + * @param tab data from the image + * @param taille_c number of column + * @param taille_l number of lign + * @return float the entropy + */ float entropie2(const uint8_t *tab,int taille_c,int taille_l); - std::string entropie_p(const uint8_t *pyra,int etage_f,int nbc,int nbl); + + /** + * @brief Return a directly printable string of the entropy + * + * @param pyra data to proccess entropy + * @param etage_f the level of entropy + * @param nbc number of column + * @param nbl number of lign + * @return std::string the printable entropy + */ + std::string entropie_p(const uint8_t *pyra,int etage_f, int nbc, int nbl); + + /** + * @brief Return a directly printable string of the entropy for only one level + * + * @param pyra data to proccess entropy + * @param etage_f the level of entropy + * @param nbc number of column + * @param nbl number of lign + * @return std::string the printable entropy + */ + std::string n_entropie_p(const uint8_t *pyra, int etage_f,int nbc,int nbl); + + + /** + * @brief Return the image reconstructed from a pyramide + * + * @param to_rebuild pyramid to rebuild + * @param etage_f number of level in the pyramid + * @param to_rebuild_to level to reconstruct + * @param utile filter to use + * @return imagein::Image* the output reconstructed image + */ imagein::Image* rebuild_interface(const imagein::Image *to_rebuild, int etage_f, int to_rebuild_to, Filtre &utile ); }