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