PTdecode/CImg-1.3.0/examples/use_greycstoration.cpp

changeset 5
1204ebf9340d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/PTdecode/CImg-1.3.0/examples/use_greycstoration.cpp	Mon Aug 03 14:09:20 2009 +0100
     1.3 @@ -0,0 +1,138 @@
     1.4 +/*
     1.5 + #
     1.6 + #  File        : use_greycstoration.cpp
     1.7 + #                ( C++ source file )
     1.8 + #
     1.9 + #  Description : Example of use for the CImg plugin 'plugins/greycstoration.h'.
    1.10 + #                ( http://www.greyc.ensicaen.fr/~dtschump/greycstoration/ )
    1.11 + #                This file is a part of the CImg Library project.
    1.12 + #                ( http://cimg.sourceforge.net )
    1.13 + #
    1.14 + #   THIS VERSION IS FOR DEVELOPERS ONLY. IT SHOWS AN EXAMPLE OF HOW THE
    1.15 + #   INTEGRATION OF THE GREYCSTORATION ALGORITHM CAN BE DONE IN
    1.16 + #   THIRD PARTIES SOFTWARES. IF YOU ARE A "USER" OF GREYCSTORATION,
    1.17 + #   PLEASE RATHER LOOK AT THE FILE 'greycstoration.cpp' WHICH IS THE
    1.18 + #   SOURCE OF THE COMPLETE COMMAND LINE GREYCSTORATION TOOL.
    1.19 + #   THE EXAMPLE FOCUS ON THE DENOISING ALGORITHM. FOR INPAINTING AND
    1.20 + #   IMAGE RESIZING, PLEASE LOOK AT THE COMPLETE GREYCSTORATION SOURCE CODE
    1.21 + #   (FILE 'greycstoration.cpp')
    1.22 + #
    1.23 + #  Copyright   : David Tschumperle
    1.24 + #                ( http://www.greyc.ensicaen.fr/~dtschump/ )
    1.25 + #
    1.26 + #  License     : CeCILL v2.0
    1.27 + #                ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html )
    1.28 + #
    1.29 + #  This software is governed by the CeCILL  license under French law and
    1.30 + #  abiding by the rules of distribution of free software.  You can  use,
    1.31 + #  modify and/ or redistribute the software under the terms of the CeCILL
    1.32 + #  license as circulated by CEA, CNRS and INRIA at the following URL
    1.33 + #  "http://www.cecill.info".
    1.34 + #
    1.35 + #  As a counterpart to the access to the source code and  rights to copy,
    1.36 + #  modify and redistribute granted by the license, users are provided only
    1.37 + #  with a limited warranty  and the software's author,  the holder of the
    1.38 + #  economic rights,  and the successive licensors  have only  limited
    1.39 + #  liability.
    1.40 + #
    1.41 + #  In this respect, the user's attention is drawn to the risks associated
    1.42 + #  with loading,  using,  modifying and/or developing or reproducing the
    1.43 + #  software by the user in light of its specific status of free software,
    1.44 + #  that may mean  that it is complicated to manipulate,  and  that  also
    1.45 + #  therefore means  that it is reserved for developers  and  experienced
    1.46 + #  professionals having in-depth computer knowledge. Users are therefore
    1.47 + #  encouraged to load and test the software's suitability as regards their
    1.48 + #  requirements in conditions enabling the security of their systems and/or
    1.49 + #  data to be ensured and,  more generally, to use and operate it in the
    1.50 + #  same conditions as regards security.
    1.51 + #
    1.52 + #  The fact that you are presently reading this means that you have had
    1.53 + #  knowledge of the CeCILL license and that you accept its terms.
    1.54 + #
    1.55 +*/
    1.56 +
    1.57 +// Include the CImg Library, with the GREYCstoration plugin included
    1.58 +#define cimg_plugin "plugins/greycstoration.h"
    1.59 +#include "CImg.h"
    1.60 +using namespace cimg_library;
    1.61 +#if cimg_OS!=2
    1.62 +#include <pthread.h>
    1.63 +#endif
    1.64 +
    1.65 +// The lines below is necessary when using a non-standard compiler as visualcpp6.
    1.66 +#ifdef cimg_use_visualcpp6
    1.67 +#define std
    1.68 +#endif
    1.69 +#ifdef min
    1.70 +#undef min
    1.71 +#undef max
    1.72 +#endif
    1.73 +
    1.74 +#ifndef cimg_imagepath
    1.75 +#define cimg_imagepath "img/"
    1.76 +#endif
    1.77 +
    1.78 +// Main procedure
    1.79 +//----------------
    1.80 +int main(int argc,char **argv) {
    1.81 +
    1.82 +  // Read algorithm parameters from the command line
    1.83 +  const char *file_i          = cimg_option("-i",cimg_imagepath "milla.bmp","Input file");
    1.84 +  const float amplitude       = cimg_option("-dt",40.0f,"Regularization strength for one iteration (>=0)");
    1.85 +  const unsigned int nb_iter  = cimg_option("-iter",3,"Number of regularization iterations (>0)");
    1.86 +  const float sharpness       = cimg_option("-p",0.8f,"Contour preservation for regularization (>=0)");
    1.87 +  const float anisotropy      = cimg_option("-a",0.8f,"Regularization anisotropy (0<=a<=1)");
    1.88 +  const float alpha           = cimg_option("-alpha",0.6f,"Noise scale(>=0)");
    1.89 +  const float sigma           = cimg_option("-sigma",1.1f,"Geometry regularity (>=0)");
    1.90 +  const bool fast_approx      = cimg_option("-fast",true,"Use fast approximation for regularization (0 or 1)");
    1.91 +  const float gauss_prec      = cimg_option("-prec",2.0f,"Precision of the gaussian function for regularization (>0)");
    1.92 +  const float dl              = cimg_option("-dl",0.8f,"Spatial integration step for regularization (0<=dl<=1)");
    1.93 +  const float da              = cimg_option("-da",30.0f,"Angular integration step for regulatization (0<=da<=90)");
    1.94 +  const unsigned int interp   = cimg_option("-interp",0,"Interpolation type (0=Nearest-neighbor, 1=Linear, 2=Runge-Kutta)");
    1.95 +  const unsigned int tile     = cimg_option("-tile",0,"Use tiled mode (reduce memory usage");
    1.96 +  const unsigned int btile    = cimg_option("-btile",4,"Size of tile overlapping regions");
    1.97 +  const unsigned int threads  = cimg_option("-threads",1,"Number of threads used");
    1.98 +
    1.99 +  // Load input image (replace 'unsigned char' by 'unsigned short' to be able to process 16-bits/pixels).
   1.100 +  CImg<unsigned char> img(file_i);
   1.101 +
   1.102 +  // Create display window
   1.103 +  CImgDisplay disp(img,"GREYCstoration");
   1.104 +
   1.105 +  // Begin iteration loop
   1.106 +  //---------------------
   1.107 +  for (unsigned int iter=0; iter<nb_iter; iter++) {
   1.108 +
   1.109 +    // This function will start a thread running one iteration of the GREYCstoration filter.
   1.110 +    // It returns immediately, so you can do what you want after (update a progress bar for instance).
   1.111 +    img.greycstoration_run(amplitude,sharpness,anisotropy,alpha,sigma,1.0f,dl,da,gauss_prec,interp,fast_approx,tile,btile,threads);
   1.112 +
   1.113 +    // Here, we print the overall progress percentage.
   1.114 +    do {
   1.115 +      // pr_iteration is the progress percentage for the current iteration
   1.116 +      const float pr_iteration = img.greycstoration_progress();
   1.117 +
   1.118 +      // This simply computes the global progression indice (including all iterations)
   1.119 +      const unsigned int pr_global = (unsigned int)((iter*100 + pr_iteration)/nb_iter);
   1.120 +
   1.121 +      // Display progress on window title and console.
   1.122 +      std::fprintf(stderr,"\rProgress : %u%%\t",pr_global);
   1.123 +      disp.set_title("GREYCstoration (%u%%)",pr_global);
   1.124 +
   1.125 +      // Wait a little bit
   1.126 +      cimg::wait(100);
   1.127 +
   1.128 +      // If the display window is closed, stop the algorithm
   1.129 +      if (disp.is_closed) img.greycstoration_stop();
   1.130 +
   1.131 +    } while (img.greycstoration_is_running());
   1.132 +
   1.133 +    img.display(disp);
   1.134 +  }
   1.135 +  std::fprintf(stderr,"\rDone !                         \n\n");
   1.136 +
   1.137 +  disp.close();
   1.138 +  img.display("GREYCstoration - Result");
   1.139 +
   1.140 +  return 0;
   1.141 +}