PARP Research Group University of Murcia, Spain


examples/inpaint/inpaint.cpp

Go to the documentation of this file.
00001 /*
00002  *      Copyright (C) 2007, 2008, 2009. PARP Research Group.
00003  *      <http://perception.inf.um.es>
00004  *      University of Murcia, Spain.
00005  *
00006  *      This file is part of the QVision library.
00007  *
00008  *      QVision is free software: you can redistribute it and/or modify
00009  *      it under the terms of the GNU Lesser General Public License as
00010  *      published by the Free Software Foundation, version 3 of the License.
00011  *
00012  *      QVision is distributed in the hope that it will be useful,
00013  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *      GNU Lesser General Public License for more details.
00016  *
00017  *      You should have received a copy of the GNU Lesser General Public
00018  *      License along with QVision. If not, see <http://www.gnu.org/licenses/>.
00019  */
00020 
00040 #include <stdio.h>
00041 #include <stdlib.h>
00042 #include <iostream>
00043 #include <QDebug>
00044 
00045 #include <qvipp.h>
00046 #include <qvio.h>
00047 
00048 #include <QVApplication>
00049 #include <QVMPlayerCamera>
00050 #include <QVDefaultGUI>
00051 #include <QVImageCanvas>
00052 
00053 #ifndef DOXYGEN_IGNORE_THIS
00054 class MyWorker: public QVWorker
00055         {
00056         private:
00057                 QVImage<uChar> mask;
00058 
00059         public:
00060                 MyWorker(QString name): QVWorker(name)
00061                         {
00062                         addProperty<QString>("Mask", inputFlag, "mask.gif", "Image file for mask");
00063                         addProperty<double>("Radius", inputFlag, 4.0, "Mask radius", 1.0, 30.0);
00064                         addProperty<bool>("Use Telea", inputFlag, false, "Use Telea versus NS");
00065                         addProperty< QVImage<uChar,3> >("Input image", inputFlag|outputFlag);
00066                         addProperty< QVImage<uChar,1> >("Mask image", outputFlag);
00067                         addProperty< QVImage<uChar,3> >("Restored image", outputFlag);
00068 
00069                         const QString maskFilePath = getPropertyValue<QString>("Mask");
00070                         QVImage<uChar, 3> temp;
00071                         // Here we try to open mask file. If it can't be opened, we finish.
00072                         if(!readQVImageFromFile(maskFilePath, temp) )
00073                                 setLastError("Error, can't find mask image file");
00074                         else
00075                                 mask = temp;
00076                         }
00077 
00078                 void iterate()
00079                         {
00080                         bool useTelea = getPropertyValue<bool>("Use Telea");
00081                         double radius = getPropertyValue<double>("Radius");
00082                 
00083                         QVImage<uChar,3> image = getPropertyValue< QVImage<uChar,3> >("Input image");
00084                         timeFlag("init");
00085                 
00087                         // Obtain mask image of size equal to image
00088                         QVImage<uChar> maskForImage(image.getCols(), image.getRows());
00089                         Resize(mask, maskForImage);
00090                 
00091                         for (uInt col = 0; col < image.getCols(); col++)
00092                                 for (uInt row = 0; row < image.getRows(); row++)
00093                                         if (maskForImage(col, row) < 128)
00094                                                 maskForImage(col, row) = 0;
00095                                         else
00096                                                 maskForImage(col, row) = 255;
00097                 
00098                         timeFlag("Obtain mask image of size equal to image");
00099                 
00101                         // Get distances using fast marching algorithm
00102                         QVImage<uChar> buffer;
00103                         FastMarchingGetBufferSize(maskForImage, buffer);
00104                 
00105                         QVImage<sFloat> distances(image.getCols(), image.getRows());
00106                         Set(0, distances);
00107 
00108                         FastMarching(maskForImage, distances, radius, buffer);
00109                         timeFlag("Get distances using fast marching algorithm");
00110                 
00112                         // Inpainting
00113                         IppiInpaintState_8u_C3R * pState;
00114                         InpaintInitAllocC3(&pState, distances, maskForImage, radius, useTelea?IPP_INPAINT_TELEA:IPP_INPAINT_NS);
00115 
00116                         QVImage<uChar,3> inpaint(image.getCols(),image.getRows());
00117                         Inpaint(image, inpaint, * pState, QPoint(0,0));
00118 
00119                         InpaintFreeC3(pState);
00120                         timeFlag("Inpainting");
00121                                                 
00123                         // Showing results
00124                         setPropertyValue< QVImage<uChar,1> >("Mask image", maskForImage);
00125                         setPropertyValue< QVImage<uChar,3> >("Restored image", inpaint);
00126                         timeFlag("Showing results");
00127                         }
00128         };
00129 
00130 int main(int argc, char *argv[])
00131         {
00132         QVApplication app(argc, argv,
00133                 "Example program for QVision library. Does inpaint reconstruction from an artificialy damaged source video.");
00134 
00135         QVMPlayerCamera camera("Video");
00136         MyWorker worker("Inpaint worker");
00137         camera.linkProperty(&worker,"Input image");
00138 
00139         QVDefaultGUI interface;
00140 
00141         QVImageCanvas inputImage("Input image");
00142         worker.linkProperty("Input image", inputImage);
00143 
00144         QVImageCanvas maskImage("Mask image");
00145         worker.linkProperty("Mask image", maskImage);
00146 
00147         QVImageCanvas restoredImage("Restored image");
00148         worker.linkProperty("Restored image", restoredImage);
00149 
00150         return app.exec();
00151         }
00152 
00153 #endif
00154 



QVision framework. PARP research group, copyright 2007, 2008.