1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
/************************************************************************/
/* */
/* vspline - a set of generic tools for creation and evaluation */
/* of uniform b-splines */
/* */
/* Copyright 2015 - 2022 by Kay F. Jahnke */
/* */
/* Permission is hereby granted, free of charge, to any person */
/* obtaining a copy of this software and associated documentation */
/* files (the "Software"), to deal in the Software without */
/* restriction, including without limitation the rights to use, */
/* copy, modify, merge, publish, distribute, sublicense, and/or */
/* sell copies of the Software, and to permit persons to whom the */
/* Software is furnished to do so, subject to the following */
/* conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the */
/* Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES */
/* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND */
/* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT */
/* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */
/* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING */
/* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR */
/* OTHER DEALINGS IN THE SOFTWARE. */
/* */
/************************************************************************/
/// \file iir.cc
///
/// \brief apply a forward/backward n-pole recursive filter to an image
///
/// vspline has some code which isn't useful only for b-splines.
/// One example is the application of a filter to a MultiArrayView.
/// With vspline's multithreaded SIMD code, this is done efficiently.
/// This example program will apply an n-pole forward/backward
/// recursive filter with the given pole values along the horizontal
/// and vertical. You can pass an arbitrarily long sequence of pole
/// values after an image file name, but bear in mind that some pole
/// values can lead to infinite results.
///
/// compile with:
/// ./examples.sh iir.cc
///
/// invoke passing an image file and the pole values. the result
/// will be written to 'iir.tif'
///
/// positive pole values will blur the image. Don't exceed 1.0.
/// Negative values will sharpen the image. blurring with a single
/// positive pole value close to 1.0 is a very efficient way to affect
/// a strong blur quickly.
///
/// TODO: compare the result of this filter with a standard gaussian
#include <iostream>
#include <stdlib.h>
#include <vspline/general_filter.h>
#include <vigra/stdimage.hxx>
#include <vigra/imageinfo.hxx>
#include <vigra/impex.hxx>
// we silently assume we have a colour image
typedef vigra::RGBValue < float , 0 , 1 , 2 > pixel_type;
// target_type is a 2D array of pixels
typedef vigra::MultiArray < 2 , pixel_type > target_type ;
int main ( int argc , char * argv[] )
{
if ( argc < 2 )
{
std::cerr << "pass a colour image file as argument," << std::endl ;
std::cerr << "followed by the pole value(s)" << std::endl ;
exit( -1 ) ;
}
// get the image file name
vigra::ImageImportInfo imageInfo ( argv[1] ) ;
std::vector < vspline::xlf_type > kernel ;
char * end ;
for ( int i = 2 ; i < argc ; i++ )
kernel.push_back ( vspline::xlf_type ( strtold ( argv [ i ] , &end ) ) ) ;
// create an array for the image data
target_type image ( imageInfo.shape() ) ;
// load the image data
vigra::importImage ( imageInfo , image ) ;
// apply the filter
vspline::forward_backward_recursive_filter
( image ,
image ,
{ vspline::MIRROR , vspline::MIRROR } ,
kernel ,
kernel.size() / 2 ) ;
// store the result with vigra impex
vigra::ImageExportInfo eximageInfo ( "iir.tif" );
std::cout << "storing the target image as 'iir.tif'" << std::endl ;
vigra::exportImage ( image ,
eximageInfo
.setPixelType("UINT8") ) ;
exit ( 0 ) ;
}
|