vspline 1.1.0
Generic C++11 Code for Uniform B-Splines
fir.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 fir.cc
33///
34/// \brief apply an FIR 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 FIR filter to a MultiArrayView.
38/// With vspline's multithreaded SIMD code, this is done efficiently.
39/// This example program will apply a 1D kernel along the horizontal
40/// and vertical. You can pass an arbitrarily long sequence of filter
41/// coefficients after an image file name.
42///
43/// compile with:
44/// ./examples.sh fir.cc
45///
46/// invoke passing an image file and the filter's coefficients. the result
47/// will be written to 'fir.tif'
48
49#include <iostream>
50#include <stdlib.h>
51
53
54#include <vigra/stdimage.hxx>
55#include <vigra/imageinfo.hxx>
56#include <vigra/impex.hxx>
57
58// we silently assume we have a colour image
59
60typedef vigra::RGBValue < float , 0 , 1 , 2 > pixel_type;
61
62// target_type is a 2D array of pixels
63
64typedef vigra::MultiArray < 2 , pixel_type > target_type ;
65
66int main ( int argc , char * argv[] )
67{
68 if ( argc < 2 )
69 {
70 std::cerr << "pass a colour image file as argument," << std::endl ;
71 std::cerr << "followed by the filter's coefficients" << std::endl ;
72 exit( -1 ) ;
73 }
74
75 // get the image file name
76
77 vigra::ImageImportInfo imageInfo ( argv[1] ) ;
78
79 std::vector < vspline::xlf_type > kernel ;
80 char * end ;
81
82 for ( int i = 2 ; i < argc ; i++ )
83 kernel.push_back ( vspline::xlf_type ( strtold ( argv [ i ] , &end ) ) ) ;
84
85 // create an array for the image data
86
87 target_type image ( imageInfo.shape() ) ;
88
89 // load the image data
90
91 vigra::importImage ( imageInfo , image ) ;
92
93 // apply the filter
94
96 ( image ,
97 image ,
99 kernel ,
100 kernel.size() / 2 ) ;
101
102 // store the result with vigra impex
103
104 vigra::ImageExportInfo eximageInfo ( "fir.tif" );
105
106 std::cout << "storing the target image as 'fir.tif'" << std::endl ;
107
108 vigra::exportImage ( image ,
109 eximageInfo
110 .setPixelType("UINT8") ) ;
111
112 exit ( 0 ) ;
113}
vigra::MultiArray< 2, pixel_type > target_type
Definition: ca_correct.cc:115
int main(int argc, char *argv[])
Definition: fir.cc:66
vigra::RGBValue< float, 0, 1, 2 > pixel_type
Definition: fir.cc:60
vigra::MultiArray< 2, pixel_type > target_type
Definition: fir.cc:64
provides vspline's digital filtering capabilities without the b-spline-specific aspects.
void convolution_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 > kv, int headroom, int axis=-1, int njobs=default_njobs)
convolution_filter implements convolution of the input with a fixed-size convolution kernel....
long double xlf_type
Definition: common.h:102
@ MIRROR
Definition: common.h:72