PTdecode/CImg-1.3.0/examples/use_greycstoration.cpp

Wed, 05 Aug 2009 15:02:31 +0100

author
Philip Pemberton <philpem@philpem.me.uk>
date
Wed, 05 Aug 2009 15:02:31 +0100
changeset 13
a933b13e087f
parent 5
1204ebf9340d
permissions
-rwxr-xr-x

PTdecode: add support for uncompressed data (NOTE: *NOT* supported by the PT-2450DX)

     1 /*
     2  #
     3  #  File        : use_greycstoration.cpp
     4  #                ( C++ source file )
     5  #
     6  #  Description : Example of use for the CImg plugin 'plugins/greycstoration.h'.
     7  #                ( http://www.greyc.ensicaen.fr/~dtschump/greycstoration/ )
     8  #                This file is a part of the CImg Library project.
     9  #                ( http://cimg.sourceforge.net )
    10  #
    11  #   THIS VERSION IS FOR DEVELOPERS ONLY. IT SHOWS AN EXAMPLE OF HOW THE
    12  #   INTEGRATION OF THE GREYCSTORATION ALGORITHM CAN BE DONE IN
    13  #   THIRD PARTIES SOFTWARES. IF YOU ARE A "USER" OF GREYCSTORATION,
    14  #   PLEASE RATHER LOOK AT THE FILE 'greycstoration.cpp' WHICH IS THE
    15  #   SOURCE OF THE COMPLETE COMMAND LINE GREYCSTORATION TOOL.
    16  #   THE EXAMPLE FOCUS ON THE DENOISING ALGORITHM. FOR INPAINTING AND
    17  #   IMAGE RESIZING, PLEASE LOOK AT THE COMPLETE GREYCSTORATION SOURCE CODE
    18  #   (FILE 'greycstoration.cpp')
    19  #
    20  #  Copyright   : David Tschumperle
    21  #                ( http://www.greyc.ensicaen.fr/~dtschump/ )
    22  #
    23  #  License     : CeCILL v2.0
    24  #                ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html )
    25  #
    26  #  This software is governed by the CeCILL  license under French law and
    27  #  abiding by the rules of distribution of free software.  You can  use,
    28  #  modify and/ or redistribute the software under the terms of the CeCILL
    29  #  license as circulated by CEA, CNRS and INRIA at the following URL
    30  #  "http://www.cecill.info".
    31  #
    32  #  As a counterpart to the access to the source code and  rights to copy,
    33  #  modify and redistribute granted by the license, users are provided only
    34  #  with a limited warranty  and the software's author,  the holder of the
    35  #  economic rights,  and the successive licensors  have only  limited
    36  #  liability.
    37  #
    38  #  In this respect, the user's attention is drawn to the risks associated
    39  #  with loading,  using,  modifying and/or developing or reproducing the
    40  #  software by the user in light of its specific status of free software,
    41  #  that may mean  that it is complicated to manipulate,  and  that  also
    42  #  therefore means  that it is reserved for developers  and  experienced
    43  #  professionals having in-depth computer knowledge. Users are therefore
    44  #  encouraged to load and test the software's suitability as regards their
    45  #  requirements in conditions enabling the security of their systems and/or
    46  #  data to be ensured and,  more generally, to use and operate it in the
    47  #  same conditions as regards security.
    48  #
    49  #  The fact that you are presently reading this means that you have had
    50  #  knowledge of the CeCILL license and that you accept its terms.
    51  #
    52 */
    54 // Include the CImg Library, with the GREYCstoration plugin included
    55 #define cimg_plugin "plugins/greycstoration.h"
    56 #include "CImg.h"
    57 using namespace cimg_library;
    58 #if cimg_OS!=2
    59 #include <pthread.h>
    60 #endif
    62 // The lines below is necessary when using a non-standard compiler as visualcpp6.
    63 #ifdef cimg_use_visualcpp6
    64 #define std
    65 #endif
    66 #ifdef min
    67 #undef min
    68 #undef max
    69 #endif
    71 #ifndef cimg_imagepath
    72 #define cimg_imagepath "img/"
    73 #endif
    75 // Main procedure
    76 //----------------
    77 int main(int argc,char **argv) {
    79   // Read algorithm parameters from the command line
    80   const char *file_i          = cimg_option("-i",cimg_imagepath "milla.bmp","Input file");
    81   const float amplitude       = cimg_option("-dt",40.0f,"Regularization strength for one iteration (>=0)");
    82   const unsigned int nb_iter  = cimg_option("-iter",3,"Number of regularization iterations (>0)");
    83   const float sharpness       = cimg_option("-p",0.8f,"Contour preservation for regularization (>=0)");
    84   const float anisotropy      = cimg_option("-a",0.8f,"Regularization anisotropy (0<=a<=1)");
    85   const float alpha           = cimg_option("-alpha",0.6f,"Noise scale(>=0)");
    86   const float sigma           = cimg_option("-sigma",1.1f,"Geometry regularity (>=0)");
    87   const bool fast_approx      = cimg_option("-fast",true,"Use fast approximation for regularization (0 or 1)");
    88   const float gauss_prec      = cimg_option("-prec",2.0f,"Precision of the gaussian function for regularization (>0)");
    89   const float dl              = cimg_option("-dl",0.8f,"Spatial integration step for regularization (0<=dl<=1)");
    90   const float da              = cimg_option("-da",30.0f,"Angular integration step for regulatization (0<=da<=90)");
    91   const unsigned int interp   = cimg_option("-interp",0,"Interpolation type (0=Nearest-neighbor, 1=Linear, 2=Runge-Kutta)");
    92   const unsigned int tile     = cimg_option("-tile",0,"Use tiled mode (reduce memory usage");
    93   const unsigned int btile    = cimg_option("-btile",4,"Size of tile overlapping regions");
    94   const unsigned int threads  = cimg_option("-threads",1,"Number of threads used");
    96   // Load input image (replace 'unsigned char' by 'unsigned short' to be able to process 16-bits/pixels).
    97   CImg<unsigned char> img(file_i);
    99   // Create display window
   100   CImgDisplay disp(img,"GREYCstoration");
   102   // Begin iteration loop
   103   //---------------------
   104   for (unsigned int iter=0; iter<nb_iter; iter++) {
   106     // This function will start a thread running one iteration of the GREYCstoration filter.
   107     // It returns immediately, so you can do what you want after (update a progress bar for instance).
   108     img.greycstoration_run(amplitude,sharpness,anisotropy,alpha,sigma,1.0f,dl,da,gauss_prec,interp,fast_approx,tile,btile,threads);
   110     // Here, we print the overall progress percentage.
   111     do {
   112       // pr_iteration is the progress percentage for the current iteration
   113       const float pr_iteration = img.greycstoration_progress();
   115       // This simply computes the global progression indice (including all iterations)
   116       const unsigned int pr_global = (unsigned int)((iter*100 + pr_iteration)/nb_iter);
   118       // Display progress on window title and console.
   119       std::fprintf(stderr,"\rProgress : %u%%\t",pr_global);
   120       disp.set_title("GREYCstoration (%u%%)",pr_global);
   122       // Wait a little bit
   123       cimg::wait(100);
   125       // If the display window is closed, stop the algorithm
   126       if (disp.is_closed) img.greycstoration_stop();
   128     } while (img.greycstoration_is_running());
   130     img.display(disp);
   131   }
   132   std::fprintf(stderr,"\rDone !                         \n\n");
   134   disp.close();
   135   img.display("GREYCstoration - Result");
   137   return 0;
   138 }