-
Notifications
You must be signed in to change notification settings - Fork 0
ipol-journal/135
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> <head><title>Roussos–Maragos Tensor-Driven Diffusion Interpolation</title> <style> th { padding:3px; padding-left:8px; padding-right:8px; font-weight:normal; background:#E8F0F8; } #t1 td { padding:3px; padding-left:8px; padding-right:8px; border-bottom:1px solid #F0F0F0; } pre.code { margin-left:18px; padding:8px; border-left:4px solid #bfd6ed; background:#E8F0F8; } span.comment { color:#404040; font-style:italic; } span.lineno { font-size:80%; color:#6D9ACE; } span.change { font-weight:bold; color:black; } span.param { font-family:helvetica,arial; font-style:italic; color:#3465A4; } </style> </head> <body> <div style="width:800px;margin-left:30px;"> <h1>Roussos–Maragos Tensor-Driven Diffusion Interpolation</h1> <p>Pascal Getreuer</p> <p>This software was written by <a href="mailto:[email protected]">Pascal Getreuer</a> and is distributed under the terms of the simplified BSD licence.</p> <h3>Contents</h3> <ol> <li><a href="#overview">Overview</a></li> <li><a href="#compiling">Compiling</a></li> <li><a href="#demo">Program Demo</a></li> <li><a href="#usage">Program Usage</a></li> <li><a href="#license">Simplified BSD License</a></li> </ol> <h2 id="overview">1. Overview</h2> <p>This package implements linear interpolation methods as described in the accompanying IPOL demo “Roussos–Maragos Tensor-Driven Diffusion Interpolation.” The methods are implemented in C as a command line program <tt>tdinterp</tt>.</p> <p>Also included are sources for building <tt>imcoarsen</tt>, <tt>imdiff</tt>, and <tt>nninterp</tt> command line tools for coarsening and comparing images and nearest-neighbor interpolation.</p> <p>If Doxygen and Graphviz are installed, HTML documentation of the project source code is generated by</p> <pre class="code"> doxygen doxygen.conf </pre> <h2 id="compiling">2. Compiling</h2> <p>The compilation is configurable. At a minimum, the <a href="http://www.fftw.org">FFTW library</a> is needed to compile. Support for reading and writing with additional image formats can be added by compiling with the libaries as summarized in the table: </p> <table id="t1" border="0" cellspacing="0" style="text-align:center;margin-left:30px"> <tr><th>Format</th><th>Library</th><th>Add preprocessor flag</th></tr> <tr><td>JPEG</td><td><a href="http://www.ijg.org">libjpeg</a></td><td><tt>LIBJPEG_SUPPORT</tt></td></tr> <tr><td>PNG</td><td><a href="http://www.libpng.org/pub/png/libpng.html">libpng</a></td><td><tt>LIBPNG_SUPPORT</tt></td></tr> <tr><td>TIFF</td><td><a href="http://www.remotesensing.org/libtiff">libtiff</a></td><td><tt>LIBTIFF_SUPPORT</tt></td></tr> <tr><td>BMP</td><td>(native)</td><td>—</td></tr> </table> <h3>2.1. Compiling on Linux or Mac OSX</h3> <h4>Installing Libraries</h4> <p>On Ubuntu and other Debian-based Linux systems, the libraries can be installed by running the following line in a terminal:</p> <pre class="code"> sudo apt-get install build-essential libfftw3-dev libjpeg8-dev libpng3-dev libtiff4-dev </pre> <p>On Fedora:</p> <pre class="code"> sudo yum install gcc fftw-devel libjpeg-devel libpng-devel libtiff-devel </pre> <p>On Mac OSX, the libraries can be installed with <a href="http://www.finkproject.org">Fink</a>: <pre class="code"> sudo fink install fftw libjpeg libpng libtiff </pre> <h4>Compiling</h4> <p>To compile, extract the package, <tt>cd</tt> into the <tt>tdinterp</tt> folder, and run <tt>make</tt>:</p> <pre class="code"> tar -xf tdinterp.tar.gz cd tdinterp make -f makefile.gcc </pre> <p>This should produce four executables <tt>tdinterp</tt>, <tt>imcoarsen</tt>, <tt>imdiff</tt>, and <tt>nninterp</tt>.</p> <h4>Troubleshooting</h4> <p>The included makefile will try to use libjpeg, libpng, and libtiff. If linking with these libraries is a problem, they can be disabled by commenting their line at the top of the makefile.</p> <pre class="code"> <span class="comment">## # The following three statements determine the build configuration. # For handling different image formats, the program can be linked with # the libjpeg, libpng, and libtiff libraries. For each library, set # the flags needed for linking. To disable use of a library, comment # its statement. You can disable all three (BMP is always supported).</span> LDLIBJPEG=-ljpeg LDLIBPNG=-lpng LDLIBTIFF=-ltiff </pre> <p>The makefile will automatically set the corresponding preprocessor symbols; only these lines need to be changed. For example, to disable libjpeg and libtiff but to keep libpng support, comment the first and third lines</p> <pre class="code"> <span class="comment"><span class="change">#LDLIBJPEG=-ljpeg</span></span> LDLIBPNG=-lpng <span class="comment"><span class="change">#LDLIBTIFF=-ltiff</span></span> </pre> <h3>2.2. Compiling on Windows</h3> <p>The code can be compiled using Microsoft Visual C++ (MSVC). <a href="http://www.microsoft.com/express/windows">Microsoft Visual Studio Express</a> can be downloaded for free. Since libraries are problematic under Windows, no libraries are used by default and the program will only support BMP images.</p> <p>These instructions assume familiarity with the MS-DOS Command Prompt. See for example <a href="http://www.c3scripts.com/tutorials/msdos/open-window.html">How to use DOS</a>.</p> <h4>FFTW</h4> <p>The FFTW single precision library is required to compile. To obtain FFTW, download the precompiled Windows DLL files from</p> <p style="margin:30px"><a href="http://www.fftw.org/install/windows.html">http://www.fftw.org/install/windows.html</a></p> <p>In order for MSVC to link with FFTW, we must create the LIB import library. Open a Visual Studio Command Prompt by selecting Start Menu → Programs → Microsoft Visual Studio → Visual Studio Tools → Visual Studio Command Prompt. (Alternatively, open a regular command prompt and run <tt>vcvarsall.bat</tt>.) Then, navigate to the FFTW DLL files and run the command</p> <pre class="code"> lib /def:libfftw3f-3.def </pre> <p>This should produce the LIB file <tt>libfftw3f-3.lib</tt>.</p> <h4>Building tdinterp</h4> <ol> <li>Copy DLL file <tt>libfftw3f-3.dll</tt> to the tdinterp folder.</li> <li>Edit makefile.vc to specify where the header file <tt>fftw3.h</tt> and the lib file <tt>libfftw3f-3.lib</tt> are: <pre class="code"> # Please specify the locations of fftw3.h and the FFTW libs FFTW_DIR = "D:/libs/fftw-3.2.2.pl1-dll32" FFTW_INCLUDE = -I(FFTW_DIR) FFTW_LIB = $(FFTW_DIR)/libfftw3-3.lib $(FFTW_DIR)/libfftw3f-3.lib </pre></li> <li> In a Visual Studio Command Prompt, run <pre class="code"> nmake -f makefile.vc </pre> This should produce four executables <tt>tdinterp.exe</tt>, <tt>imcoarsen.exe</tt>, <tt>imdiff.exe</tt>, and <tt>nninterp .exe</tt>.</li> </ol> <h4>libjpeg and libpng (optional)</h4> <p>It is possible under Windows to compile the program with libjpeg and libpng to add support for JPEG and PNG images (libtiff should be possible as well, but it is not explored here). To avoid incompatibility problems, the reliable way to compile with a library is to build that library from source using the same compiler.</p> <p>First, download the libjpeg, libpng, and also the zlib library sources. The zlib library is needed to compile libpng.</p> <ul> <li>libjpeg sources: <a href="http://www.ijg.org/files/jpegsr8b.zip">http://www.ijg.org/files/jpegsr8b.zip</a></li> <li>libpng sources: <a href="http://download.sourceforge.net/libpng/lpng143.zip">http://download.sourceforge.net/libpng/lpng143.zip</a></li> <li>zlib sources: <a href="http://gnuwin32.sourceforge.net/downlinks/zlib-src-zip.php">http://gnuwin32.sourceforge.net/downlinks/zlib-src-zip.php</a></li> </ul> <p>Create a folder to contain the libraries, <tt>C:\libs</tt> for instance. Unzip the library sources into the libs folder so that they are structured as</p> <table cellspacing="0" style="font-size:50%;margin-left:30px"> <tr><td colspan="2" style="font-size:230%"><tt>libs</tt></td><td> </td></tr> <tr><td> </td> <td style="border-left:1px solid gray;border-bottom:1px solid gray;"> </td> <td rowspan="2" valign="middle" style="font-size:230%"><tt>jpeg-8b</tt></td></tr> <tr><td> </td> <td style="border-left:1px solid gray;"> </td></tr> <tr><td> </td> <td style="border-left:1px solid gray;border-bottom:1px solid gray;"> </td> <td rowspan="2" valign="middle" style="font-size:230%"><tt>lpng143</tt></td></tr> <tr><td> </td><td style="border-left:1px solid gray;"> </td></tr> <tr><td> </td> <td style="border-left:1px solid gray;border-bottom:1px solid gray;"> </td> <td rowspan="2" valign="middle" style="font-size:230%"><tt>zlib</tt></td></tr> <tr><td> </td><td> </td></tr> </table> <p>This structure will help keep the code organized. Take care to rename the folder for zlib to “<tt>zlib</tt>” since libpng will look for it. Below are the steps to build each library. If you want JPEG support, build libjpeg. For PNG support, build zlib first and then build libpng.</p> <p><b>Building libjpeg</b></p> <ol> <li>Rename <tt>jconfig.vc</tt> to <tt>jconfig.h</tt>.</li> <li>Open a Visual Studio Command Prompt by clicking Start Menu → Microsoft Visual Studio → Visual Studio Tools → Visual Studio Command Prompt, or open a regular command prompt and run the <tt>vcvarsall.bat</tt>. Navigate into <tt>libs\jpeg-8b</tt> and run <pre class="code"> nmake -f makefile.vc libjpeg.lib </pre> This should produce <tt>libjpeg.lib</tt>.</li> </ol> <p><b>Building zlib</b></p> <ol> <li>Change <tt>zconf.h</tt> line 287 to “<tt>#if 0</tt>,” <pre class="code"> <span class="lineno">287</span> <span class="change">#if 0</span> <span class="comment">/* HAVE_UNISTD_H -- this line is updated by ./configure */</span> <span class="lineno">288</span> # include <sys/types.h> <span class="comment">/* for off_t */</span> <span class="lineno">289</span> # include <unistd.h> <span class="comment">/* for SEEK_* and off_t */</span> </pre></li> <li>Open a Visual Studio Command Prompt (see step 2 for libjpeg), go into <tt>zlib\projects\visualc6</tt>, and run <pre class="code"> vcbuild -upgrade zlib.dsp vcbuild zlib.vcproj "LIB Release|Win32" </pre> This should produce a folder “<tt>Win32_LIB_Release</tt>” containing <tt>zlib.lib</tt>.</li> <li>Copy <tt>zconf.h</tt>, <tt>zlib.h</tt>, and <tt>zlib.lib</tt> to <tt>libs\zlib</tt> (libpng will look here).</li> </ol> <p><b>Building libpng</b></p> <ol> <li>First build zlib.</li> <li>Change <tt>-MD</tt> to <tt>-MT</tt> in CFLAGS in <tt>lpng143\scripts\makefile.vcwin32</tt> <pre class="code"> CFLAGS = -nologo -DPNG_NO_MMX_CODE <span class="change">-MT</span> -O2 -W3 -I..\zlib </pre> </li> <li>From a Visual Studio Command Prompt, go into <tt>lpng143</tt> and run <pre class="code"> nmake -f scripts\makefile.vcwin32 </pre> This should produce <tt>libpng.lib</tt>.</li> </ol> <p>Once the libraries are built, <tt>tdinterp</tt> can be compiled with JPEG and/or PNG support by adjusting its makefile. Uncomment and edit the lines at the top of <tt>tdinterp\makefile.vc</tt> to reflect the locations of libjpeg, libpng, and zlib:</p> <pre class="code"> <span class="comment"># # Uncomment and edit the following lines for JPEG support. #</span> LIBJPEG_DIR = "C:/libs/jpeg-8b" LIBJPEG_INCLUDE = -I$(LIBJPEG_DIR) LIBJPEG_LIB = $(LIBJPEG_DIR)/libjpeg.lib <span class="comment"># # Uncomment and edit the following lines for PNG support. #</span> ZLIB_DIR = "C:/libs/zlib" ZLIB_INCLUDE = -I$(ZLIB_DIR) ZLIB_LIB = $(ZLIB_DIR)/zlib.lib LIBPNG_DIR = "C:/libs/lpng143" LIBPNG_INCLUDE = -I$(LIBPNG_DIR) LIBPNG_LIB = $(LIBPNG_DIR)/libpng.lib </pre> <p>The makefile will automatically add the corresponding preprocessor symbols based on which libraries are defined. Then from a Visual Studio Command Prompt, compile with</p> <pre class="code"> nmake -f makefile.vc </pre> <p>This should produce <tt>tdinterp.exe</tt>, <tt>imcoarsen.exe</tt>, <tt>imdiff.exe</tt>, and <tt>nninterp.exe</tt>.</p> <h2 id="demo">3. Program Demo</h2> <p>A script called “demo” is included to run an example interpolation with the program. There is also an equivalent BAT program for MS-DOS.</p> <table border="0px" style="margin-left:30px"> <tr><td><tt>demo</tt></td><td> </td><td>sh script</td></tr> <tr><td><tt>demo.bat</tt></td><td> </td><td>MS-DOS batch script</td></tr> </table> <p>Image credits: the demo test image is by <a href="http://armi.usgs.gov/gallery/detail.php?search=Genus&subsearch=Bufo&id=323">John D. Willson, USGS Amphibian Research and Monitoring Initiative</a>.</p> <h2 id="usage">4. Program Usage</h2> <p>The usage syntax for <tt>tdinterp</tt> is</p> <pre class="code"> tdinterp [options] <span class="param">input-file</span> <span class="param">output-file</span> </pre> <p>where <tt><span class="param">input-file</span></tt> is the file name of the image to be interpolated, and <tt><span class="param">output-file</span></tt> is the file name to use for saving the interpolated image.</p> <p><b>Sorry, only BMP/JPEG/PNG/TIFF images are supported.</b></p> <p>The program only supports BMP, JPEG, PNG, and TIFF images. If you disabled some of the libraries when compiling, the support for the corresponding formats will be disabled. Regardless of compilation settings, the program always supports Windows Bitmap BMP images.</p> <p>To use an image that is in an unsupported format, please convert it to a supported format. Images can be conveniently converted using the command line program <tt>convert</tt> from <a href="http://www.imagemagick.org">ImageMagick</a>. Alternatively, an image can be converted by opening the image in an image editor, selecting “Save As...,” and setting “Type” to a supported format.</p> <p>The program has several option arguments</p> <table border="0px" style="margin-left:30px"> <tr><td style="width:100px"><tt>-x <span class="param">number</span></tt></td><td> </td><td colspan="2">the scale factor (must be integer)</tr> <tr><td><tt>-p <span class="param">number</span></tt></td><td> </td><td colspan="2"><i>σ<sub>h</sub></i>, the blur size of the point spread function</td></tr> <tr><td><tt>-K <span class="param">number</span></tt></td><td> </td><td colspan="2"><i>K</i>, parameter in constructing the tensor (default 1/255)</td></tr> <tr><td><tt>-t <span class="param">number</span></tt></td><td> </td><td colspan="2"><i>tol</i>, convergence tolerance (default 1e-4)</td></tr> <tr><td><tt>-N <span class="param">number</span></tt></td><td> </td><td colspan="2"><i>N</i>, maximum number of method iterations (default 50)</td></tr> <tr><td><tt>-n <span class="param">number</span></tt></td><td> </td><td colspan="2"><i>n</i>, number of diffusion steps per method iteration (default 5)</td></tr> <tr><td valign="top"><tt>-q <span class="param">number</span></tt></td><td> </td><td colspan="2">quality for saving JPEG images (0 to 100). This option has no effect on<br>other image formats and is only present if compiled with libjpeg.</td></tr> </table> <p>For example, to run the program on “frog.bmp” with factor-4 scaling and PSF standard deviation σ<sub><i>h</i></sub> = 0.5, run</p> <pre class="code"> tdinterp -x 4 -p 0.5 frog.bmp frog-4x.bmp </pre> <p>This package also includes two tools, <tt>imcoarsen</tt> and <tt>imdiff</tt>. The imcoarsen tool coarsens an input image by convolving with a Gaussian followed by downsampling. The imdiff tool compares two images with various image metrics. These tools are useful for interpolation experiments: a high-resolution image is given to <tt>imcoarsen</tt> to create a coarse image, the coarse image is interpolated by <tt>linterp</tt>, and the interpolation is compared to the original using <tt>imdiff</tt>.</p> <p>The usage syntax of <tt>imcoarsen</tt> is</p> <pre class="code"> imcoarsen [options] <span class="param">input-file</span> <span class="param">output-file</span> </pre> <p>Options:</p> <table border="0px" style="margin-left:30px"> <tr><td><tt>-x <span class="param">number</span></tt></td><td> </td><td colspan="2">the coarsening factor (≥1.0, may be non-integer)</tr> <tr><td><tt>-p <span class="param">number</span></tt></td><td> </td><td colspan="2"><i>σ<sub>h</sub></i>, the blur size of the point spread function</tr> <tr><td><tt>-b <span class="param">ext</span></tt></td><td> </td><td colspan="2">extension to use for boundary handling, choices for <tt><span class="param">ext</span></tt> are</tr> <tr><td colspan="2"> </td><td><tt>const</tt></td><td>constant extension</td></tr> <tr><td colspan="2"> </td><td><tt>hsym</tt></td><td>half-sample symmetric</td></tr> <tr><td colspan="2"> </td><td><tt>wsym</tt></td><td>whole-sample symmetric</td></tr> <tr><td><tt>-g <span class="param">grid</span></tt></td><td> </td><td colspan="2">grid to use for resampling, choices for <tt><span class="param">grid</span></tt> are</td></tr> <tr><td colspan="2"> </td><td><tt>centered</tt></td><td>grid with centered alignment (default)</td></tr> <tr><td colspan="2"> </td><td><tt>topleft</tt></td><td>the top-left anchored grid</td></tr> <tr><td valign="top"><tt>-q <span class="param">number</span></tt></td><td> </td><td colspan="2">quality for saving JPEG images (0 to 100).</td></tr> </table> <p>Note that the <tt>-x</tt> and <tt>-p</tt> options are analogous to the same options in <tt>tdinterp</tt>. The coarsening factor given with option <tt>-x</tt> may be non-integer. The size of the output image is determined by dividing the input image size by the coarsening factor and rounding up.</p> <p>The usage syntax of <tt>imdiff</tt> is</p> <pre class="code"> imdiff [options] <span class="param">exact-file</span> <span class="param">distorted-file</span> </pre> <p>Options:</p> <table border="0px" style="margin-left:30px"> <tr><td><tt>-m <span class="param">metric</span></tt></td><td> </td><td colspan="2">metric to use for comparison, choices are</tr> <tr><td colspan="2"> </td><td><tt>max</tt></td><td>maximum absolute difference, max<sub><i>n</i></sub> |<i>A<sub>n</sub></i> − <i>B<sub>n</sub></i>|</td></tr> <tr><td colspan="2"> </td><td><tt>mse</tt></td><td>mean squared error, 1/<i>N</i> sum |<i>A<sub>n</sub></i> − <i>B<sub>n</sub></i>|<sup>2</sup></td></tr> <tr><td colspan="2"> </td><td><tt>rmse</tt></td><td>root mean squared error, (MSE)<sup>½</sup></td></tr> <tr><td colspan="2"> </td><td><tt>psnr</tt></td><td>peak signal-to-noise ratio, −10 log<sub>10</sub>(MSE/255<sup>2</sup>)</td></tr> <tr><td colspan="2"> </td><td><tt>mssim</tt> </td><td>mean structural similarity index</td></tr> <tr><td><tt>-s</tt></td><td> </td><td colspan="2">compute metric separately for each channel</tr> <tr><td><tt>-p <span class="param">pad</span></tt></td><td> </td><td colspan="2">remove a margin of <tt><span class="param">pad</span></tt> pixels before comparison</tr> <tr><td><tt>-D <span class="param">number</span></tt></td><td> </td><td colspan="2"><i>D</i> parameter for difference image (explained below)</tr> <tr><td valign="top"><tt>-q <span class="param">number</span></tt></td><td> </td><td colspan="2">quality for saving JPEG images (0 to 100)</td></tr> </table> <p>Alternatively, a difference image is generated by the syntax</p> <pre class="code"> imdiff [-D <span class="param">number</span>] <span class="param">exact-file</span> <span class="param">distorted-file</span> <span class="param">output-file</span> </pre> <p>The difference image is computed as <i>D<sub>n</sub></i> = 255/<i>D</i> (<i>A<sub>n</sub></i> − <i>B<sub>n</sub></i>) + 255/2. Values outside of the range [0,255] are saturated.</p> <p>The usage information for these programs is also displayed when executing them without arguments.</p> <h2 id="license">5. Simplified BSD License</h2> <p>Copyright © 2010–2011, Pascal Getreuer<br> All rights reserved.</p> <p>Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:</p> <ul> <li>Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.</li> <li>Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.</li> </ul> <p>THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</p> <p> </p> <p style="font-size:80%">This material is based upon work supported by the National Science Foundation under Award No. DMS-1004694. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation.</p> </div> </body> </html>
About
No description, website, or topics provided.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published