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