1.1 diff -r 5edfbd3e7a46 -r 1204ebf9340d PTdecode/CImg-1.3.0/examples/use_skeleton.cpp 1.2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 +++ b/PTdecode/CImg-1.3.0/examples/use_skeleton.cpp Mon Aug 03 14:09:20 2009 +0100 1.4 @@ -0,0 +1,124 @@ 1.5 +/* 1.6 + # 1.7 + # File : use_skeleton.cpp 1.8 + # ( C++ source file ) 1.9 + # 1.10 + # Description : Example of use for the CImg plugin 'plugins/skeleton.h'. 1.11 + # This file is a part of the CImg Library project. 1.12 + # ( http://cimg.sourceforge.net ) 1.13 + # 1.14 + # Copyright : Francois-Xavier Dupe 1.15 + # ( http://www.greyc.ensicaen.fr/~fdupe/ ) 1.16 + # 1.17 + # License : CeCILL v2.0 1.18 + # ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) 1.19 + # 1.20 + # This software is governed by the CeCILL license under French law and 1.21 + # abiding by the rules of distribution of free software. You can use, 1.22 + # modify and/ or redistribute the software under the terms of the CeCILL 1.23 + # license as circulated by CEA, CNRS and INRIA at the following URL 1.24 + # "http://www.cecill.info". 1.25 + # 1.26 + # As a counterpart to the access to the source code and rights to copy, 1.27 + # modify and redistribute granted by the license, users are provided only 1.28 + # with a limited warranty and the software's author, the holder of the 1.29 + # economic rights, and the successive licensors have only limited 1.30 + # liability. 1.31 + # 1.32 + # In this respect, the user's attention is drawn to the risks associated 1.33 + # with loading, using, modifying and/or developing or reproducing the 1.34 + # software by the user in light of its specific status of free software, 1.35 + # that may mean that it is complicated to manipulate, and that also 1.36 + # therefore means that it is reserved for developers and experienced 1.37 + # professionals having in-depth computer knowledge. Users are therefore 1.38 + # encouraged to load and test the software's suitability as regards their 1.39 + # requirements in conditions enabling the security of their systems and/or 1.40 + # data to be ensured and, more generally, to use and operate it in the 1.41 + # same conditions as regards security. 1.42 + # 1.43 + # The fact that you are presently reading this means that you have had 1.44 + # knowledge of the CeCILL license and that you accept its terms. 1.45 + # 1.46 +*/ 1.47 + 1.48 +#include <queue> 1.49 +#define cimg_plugin "plugins/skeleton.h" 1.50 +#include "../CImg.h" 1.51 +using namespace cimg_library; 1.52 + 1.53 +#ifndef cimg_imagepath 1.54 +#define cimg_imagepath "img/" 1.55 +#endif 1.56 + 1.57 +int main (int argc, char **argv) { 1.58 + 1.59 + cimg_usage("Compute the skeleton of a shape, using Hamilton-Jacobi equations"); 1.60 + 1.61 + // Read command line arguments 1.62 + cimg_help("Input/Output options\n" 1.63 + "--------------------"); 1.64 + const char* file_i = cimg_option("-i",cimg_imagepath "milla.bmp","Input (black&white) image"); 1.65 + const int median = cimg_option("-median",0,"Apply median filter"); 1.66 + const bool invert = cimg_option("-inv",false,"Invert image values"); 1.67 + const char* file_o = cimg_option("-o",(char*)0,"Output skeleton image"); 1.68 + const bool display = cimg_option("-visu",true,"Display results"); 1.69 + 1.70 + cimg_help("Skeleton computation parameters\n" 1.71 + "-------------------------------"); 1.72 + const float thresh = cimg_option("-t",-0.3f,"Threshold"); 1.73 + const bool curve = cimg_option("-curve",false,"Create medial curve"); 1.74 + 1.75 + cimg_help("Torsello correction parameters\n" 1.76 + "------------------------------"); 1.77 + const bool correction = cimg_option("-corr",false,"Torsello correction"); 1.78 + const float dlt1 = 2; 1.79 + const float dlt2 = cimg_option("-dlt",1.0f,"Discrete step"); 1.80 + 1.81 + cimg_help("Sampling parameters\n" 1.82 + "-------------------"); 1.83 + const float sX = cimg_option("-sizeX",1.0f,"X-Size of the pixel/voxel"); 1.84 + const float sY = cimg_option("-sizeY",1.0f,"Y-Size of the pixel/voxel"); 1.85 + const float sZ = cimg_option("-sizeZ",1.0f,"Z-Size of the pixel/voxel"); 1.86 + 1.87 + // Load the image (forcing it to be scalar with 2 values { 0,1 }). 1.88 + CImg<unsigned int> image0(file_i), image = image0.get_pointwise_norm().quantize(2).normalize(0,1); 1.89 + if (median) image.blur_median(median); 1.90 + if (invert) (image-=1)*=-1; 1.91 + if (display) (image0.get_normalize(0,255)<<image.get_normalize(0,255)).display("Input image - Binary image"); 1.92 + 1.93 + // Compute distance map. 1.94 + CImgList<float> visu; 1.95 + CImg<float> distance = image.get_distance(0,sX,sY,sZ); 1.96 + if (display) visu.insert(distance); 1.97 + 1.98 + // Compute the gradient of the distance function, and the flux (divergence) of the gradient field. 1.99 + const CImgList<float> grad = distance.get_gradient("xyz"); 1.100 + CImg<float> flux = image.get_flux(grad,sY,sZ); 1.101 + if (display) visu.insert(flux); 1.102 + 1.103 + // Use the Torsello correction of the flux if necessary. 1.104 + if (correction) { 1.105 + CImg<float> 1.106 + logdensity = image.get_logdensity(distance,grad,flux,dlt1), 1.107 + nflux = image.get_corrected_flux(logdensity,grad,flux,dlt2); 1.108 + if (display) visu.insert(logdensity).insert(nflux); 1.109 + flux = nflux; 1.110 + } 1.111 + 1.112 + if (visu) { 1.113 + cimglist_apply(visu,normalize)(0,255); 1.114 + visu.display(visu.size==2?"Distance function - Flux":"Distance function - Flux - Log-density - Corrected flux"); 1.115 + } 1.116 + 1.117 + // Compute the skeleton 1.118 + const CImg<unsigned int> skel = image.get_skeleton(flux,distance,curve,thresh); 1.119 + if (display) { 1.120 + (image0.resize(-100,-100,1,3)*=0.7f).get_shared_channel(1)|=skel*255.0; 1.121 + image0.draw_image(0,0,0,0,image*255.0,0.5f).display("Image + Skeleton"); 1.122 + } 1.123 + 1.124 + // Save output image if necessary. 1.125 + if (file_o) skel.save(file_o); 1.126 + 1.127 + return 0; 1.128 +}