libelas
filter.h
Go to the documentation of this file.
1 /*
2 Copyright 2011. All rights reserved.
3 Institute of Measurement and Control Systems
4 Karlsruhe Institute of Technology, Germany
5 
6 This file is part of libelas.
7 Authors: Julius Ziegler, Andreas Geiger
8 
9 libelas is free software; you can redistribute it and/or modify it under the
10 terms of the GNU General Public License as published by the Free Software
11 Foundation; either version 3 of the License, or any later version.
12 
13 libelas is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15 PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License along with
18 libelas; if not, write to the Free Software Foundation, Inc., 51 Franklin
19 Street, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21 
22 #ifndef __FILTER_H__
23 #define __FILTER_H__
24 
25 #include <emmintrin.h>
26 #include <pmmintrin.h>
27 
28 // define fixed-width datatypes for Visual Studio projects
29 #ifndef _MSC_VER
30  #include <stdint.h>
31 #else
32  typedef __int8 int8_t;
33  typedef __int16 int16_t;
34  typedef __int32 int32_t;
35  typedef __int64 int64_t;
36  typedef unsigned __int8 uint8_t;
37  typedef unsigned __int16 uint16_t;
38  typedef unsigned __int32 uint32_t;
39  typedef unsigned __int64 uint64_t;
40 #endif
41 
42 // fast filters: implements 3x3 and 5x5 sobel filters and
43 // 5x5 blob and corner filters based on SSE2/3 instructions
44 namespace filter {
45 
46  // private namespace, public user functions at the bottom of this file
47  namespace detail {
48  void integral_image( const uint8_t* in, int32_t* out, int w, int h );
49  void unpack_8bit_to_16bit( const __m128i a, __m128i& b0, __m128i& b1 );
50  void pack_16bit_to_8bit_saturate( const __m128i a0, const __m128i a1, __m128i& b );
51 
52  // convolve image with a (1,4,6,4,1) row vector. Result is accumulated into output.
53  // output is scaled by 1/128, then clamped to [-128,128], and finally shifted to [0,255].
54  void convolve_14641_row_5x5_16bit( const int16_t* in, uint8_t* out, int w, int h );
55 
56  // convolve image with a (1,2,0,-2,-1) row vector. Result is accumulated into output.
57  // This one works on 16bit input and 8bit output.
58  // output is scaled by 1/128, then clamped to [-128,128], and finally shifted to [0,255].
59  void convolve_12021_row_5x5_16bit( const int16_t* in, uint8_t* out, int w, int h );
60 
61  // convolve image with a (1,2,1) row vector. Result is accumulated into output.
62  // This one works on 16bit input and 8bit output.
63  // output is scaled by 1/4, then clamped to [-128,128], and finally shifted to [0,255].
64  void convolve_121_row_3x3_16bit( const int16_t* in, uint8_t* out, int w, int h );
65 
66  // convolve image with a (1,0,-1) row vector. Result is accumulated into output.
67  // This one works on 16bit input and 8bit output.
68  // output is scaled by 1/4, then clamped to [-128,128], and finally shifted to [0,255].
69  void convolve_101_row_3x3_16bit( const int16_t* in, uint8_t* out, int w, int h );
70 
71  void convolve_cols_5x5( const unsigned char* in, int16_t* out_v, int16_t* out_h, int w, int h );
72 
73  void convolve_col_p1p1p0m1m1_5x5( const unsigned char* in, int16_t* out, int w, int h );
74 
75  void convolve_row_p1p1p0m1m1_5x5( const int16_t* in, int16_t* out, int w, int h );
76 
77  void convolve_cols_3x3( const unsigned char* in, int16_t* out_v, int16_t* out_h, int w, int h );
78  }
79 
80  void sobel3x3( const uint8_t* in, uint8_t* out_v, uint8_t* out_h, int w, int h );
81 
82  void sobel5x5( const uint8_t* in, uint8_t* out_v, uint8_t* out_h, int w, int h );
83 
84  // -1 -1 0 1 1
85  // -1 -1 0 1 1
86  // 0 0 0 0 0
87  // 1 1 0 -1 -1
88  // 1 1 0 -1 -1
89  void checkerboard5x5( const uint8_t* in, int16_t* out, int w, int h );
90 
91  // -1 -1 -1 -1 -1
92  // -1 1 1 1 -1
93  // -1 1 8 1 -1
94  // -1 1 1 1 -1
95  // -1 -1 -1 -1 -1
96  void blob5x5( const uint8_t* in, int16_t* out, int w, int h );
97 };
98 
99 #endif
void convolve_12021_row_5x5_16bit(const int16_t *in, uint8_t *out, int w, int h)
Definition: filter.cpp:132
void integral_image(const uint8_t *in, int32_t *out, int w, int h)
Definition: filter.cpp:48
void checkerboard5x5(const uint8_t *in, int16_t *out, int w, int h)
Definition: filter.cpp:433
void sobel3x3(const uint8_t *in, uint8_t *out_v, uint8_t *out_h, int w, int h)
Definition: filter.cpp:408
void convolve_row_p1p1p0m1m1_5x5(const int16_t *in, int16_t *out, int w, int h)
Definition: filter.cpp:351
void pack_16bit_to_8bit_saturate(const __m128i a0, const __m128i a1, __m128i &b)
Definition: filter.cpp:73
void blob5x5(const uint8_t *in, int16_t *out, int w, int h)
Definition: filter.cpp:445
void convolve_cols_5x5(const unsigned char *in, int16_t *out_v, int16_t *out_h, int w, int h)
Definition: filter.cpp:269
void convolve_101_row_3x3_16bit(const int16_t *in, uint8_t *out, int w, int h)
Definition: filter.cpp:227
void sobel5x5(const uint8_t *in, uint8_t *out_v, uint8_t *out_h, int w, int h)
Definition: filter.cpp:418
void convolve_121_row_3x3_16bit(const int16_t *in, uint8_t *out, int w, int h)
Definition: filter.cpp:176
void convolve_col_p1p1p0m1m1_5x5(const unsigned char *in, int16_t *out, int w, int h)
Definition: filter.cpp:323
void unpack_8bit_to_16bit(const __m128i a, __m128i &b0, __m128i &b1)
Definition: filter.cpp:67
void convolve_cols_3x3(const unsigned char *in, int16_t *out_v, int16_t *out_h, int w, int h)
Definition: filter.cpp:372
void convolve_14641_row_5x5_16bit(const int16_t *in, uint8_t *out, int w, int h)
Definition: filter.cpp:79