/* # # File : wavelet_atrous.cpp # ( C++ source file ) # # Description : Performs a 2D or 3D 'a trous' wavelet transform # (using a cubic spline) on an image or a video sequence. # This file is a part of the CImg Library project. # ( http://cimg.eu ) # # Author : Renaud Peteri # ( Renaud.Peteri(at)mines-paris.org ) # Andrea Onofri # ( Andrea.Onofri(at)teletu.it ) # # Institution : CWI, Amsterdam # # Date : February 2005 # # References : Starck, J.-L., Murtagh, F. and Bijaoui, A., # Image Processing and Data Analysis: The Multiscale Approach, # Cambridge University Press, 1998. # (Hardback and softback, ISBN 0-521-59084-1 and 0-521-59914-8.) # # License : CeCILL v2.0 # ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) # # This software is governed by the CeCILL license under French law and # abiding by the rules of distribution of free software. You can use, # modify and/ or redistribute the software under the terms of the CeCILL # license as circulated by CEA, CNRS and INRIA at the following URL # "http://www.cecill.info". # # As a counterpart to the access to the source code and rights to copy, # modify and redistribute granted by the license, users are provided only # with a limited warranty and the software's author, the holder of the # economic rights, and the successive licensors have only limited # liability. # # In this respect, the user's attention is drawn to the risks associated # with loading, using, modifying and/or developing or reproducing the # software by the user in light of its specific status of free software, # that may mean that it is complicated to manipulate, and that also # therefore means that it is reserved for developers and experienced # professionals having in-depth computer knowledge. Users are therefore # encouraged to load and test the software's suitability as regards their # requirements in conditions enabling the security of their systems and/or # data to be ensured and, more generally, to use and operate it in the # same conditions as regards security. # # The fact that you are presently reading this means that you have had # knowledge of the CeCILL license and that you accept its terms. # */ #include "CImg.h" using namespace cimg_library; #ifndef cimg_imagepath #define cimg_imagepath "img/" #endif // Define convolution mask. CImg mask(const unsigned char dirIdx, const unsigned char scale) { const int d1 = 1 << (scale-1), d2 = 1 << scale, c = d2, vecLen = (1 << (scale + 1)) + 1; const float valC = 0.375f, // 6/16 valD1 = 0.25f, // 4/16 valD2 = 0.0625f; // 1/16 switch(dirIdx) { case 0 : { // x CImg m(vecLen,1,1,1,0); m(c) = valC; m(c - d1) = m(c + d1) = valD1; m(c - d2) = m(c + d2) = valD2; return m; } case 1: { // y CImg m(1,vecLen,1,1,0); m(0,c) = valC; m(0,c - d1) = m(0,c + d1) = valD1; m(0,c - d2) = m(0,c + d2) = valD2; return m; } case 2: { // t CImg m(1,1,vecLen,1,0); m(0,0,c) = valC; m(0,0,c - d1) = m(0,0,c + d1) = valD1; m(0,0,c - d2) = m(0,0,c + d2) = valD2; return m; } default: throw CImgException("Error, unknow decompostion axe, dirIdx = '%c'.",dirIdx); } } /*------------------ Main procedure ----------------*/ int main(int argc,char **argv) { cimg_usage("Perform an 'a trous' wavelet transform (using a cubic spline) on an image or on a video sequence.\n" "This wavelet transform is undecimated and produces 2 images/videos at each scale. For an example of\n" "decomposition on a video, try -i img/trees.inr (sequence from the MIT).\n" "\t(Type -h for help)"); // Read command line parameters const char *name_i = cimg_option("-i",cimg_imagepath "parrot.ppm","Input image or video"), *name_o = cimg_option("-o","","Name of the multiscale analysis output"), *axe_dec = cimg_option("-axe",(char*)0, "Perform the multiscale decomposition in just one direction ('x', 'y' or 't')"); const unsigned int s = cimg_option("-s",3,"Scale of decomposition"); const bool help = cimg_option("-h",false,"Display Help"); if (help) std::exit(0); // Initialize Image Data std::fprintf(stderr," - Load image sequence '%s'...\n",cimg::basename(name_i)); const CImg texture_in(name_i); CImg mask_conv; CImgList res(s,texture_in.width(),texture_in.height(),texture_in.depth()); CImgList wav(s,texture_in.width(),texture_in.height(),texture_in.depth()); cimglist_for(res,l) { res(l).fill(0.0); wav(l).fill(0.0); } unsigned int i; int firstDirIdx = 0,lastDirIdx = 2; if (axe_dec) { // The multiscale decomposition will be performed in just one direction char c = cimg::lowercase(axe_dec[0]); switch(c) { case 'x': firstDirIdx = 0; break; case 'y': firstDirIdx = 1; break; case 't': firstDirIdx = 2; break; default: throw CImgException("Error, unknow decompostion axe '%c', try 'x', 'y' or 't'",c); } lastDirIdx = firstDirIdx; // Only one direction } for (i = 0; i