Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
CensusTransform.cpp
1 /*
2  This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4  Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10  BIAS is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation; either version 2.1 of the License, or
13  (at your option) any later version.
14 
15  BIAS is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with BIAS; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  */
24 
25 #include "CensusTransform.hh"
26 
27 #include <Base/Image/ImageBase.hh>
28 #include <Base/Image/ImageIO.hh>
29 #include <Base/Image/ImageConvert.hh>
30 #include <Base/Common/BIASpragma.hh>
31 
32 using namespace BIAS;
33 using namespace std;
34 
35 namespace BIAS {
36 
37  //////////////////////////////////////////////////////////////////////////
38  // implementation
39  //////////////////////////////////////////////////////////////////////////
40 
41  template<class InputStorageType, class OutputStorageType>
43  : FilterNToN<InputStorageType,OutputStorageType>()
44  {
45  }
46 
47  template<class InputStorageType, class OutputStorageType>
50  : FilterNToN<InputStorageType, OutputStorageType>(other)
51  {
52  }
53 
54  template<class InputStorageType, class OutputStorageType>
56  {
57  }
58 
59  template<class InputStorageType, class OutputStorageType>
62  {
63  if (src.GetColorModel() != ImageBase::CM_Grey) {
64  BIASERR("Source Image is not grey scaled");
65  BIASABORT;
66  return 0;
67  }
68 
69  if (src.GetChannelCount() != 1) {
70  BIASERR("Source Image is not grey scaled");
71  BIASABORT;
72  return -1;
73  }
74 
75  unsigned int width = src.GetWidth();
76  unsigned int height = src.GetHeight();
77 
78  if (dst.GetWidth() != width || dst.GetHeight() != height ||
79  dst.GetChannelCount() != 1)
80  {
81  BIASERR("Source and Destination Image dimension mismatch");
82  BIASABORT;
83  }
84 
85  const InputStorageType **in = src.GetImageDataArray();
86  OutputStorageType **out = dst.GetImageDataArray();
87 
88  for (unsigned int y=1; y<height-1;y++) {
89  for (unsigned int x=1; x<width-1;x++) {
90  // walk 3x3 window
91  out[y][x] = (in[y-1][x-1] < in[y][x]) ? (1 << 7) : 0;
92  out[y][x] += (in[y-1][x] < in[y][x]) ? (1 << 6) : 0;
93  out[y][x] += (in[y-1][x+1] < in[y][x]) ? (1 << 5) : 0;
94  out[y][x] += (in[y][x-1] < in[y][x]) ? (1 << 4) : 0;
95  out[y][x] += (in[y][x+1] < in[y][x]) ? (1 << 3) : 0;
96  out[y][x] += (in[y+1][x-1] < in[y][x]) ? (1 << 2) : 0;
97  out[y][x] += (in[y+1][x] < in[y][x]) ? (1 << 1) : 0;
98  out[y][x] += (in[y+1][x+1] < in[y][x]) ? 1 : 0;
99  }
100  }
101 
102  return 0;
103  }
104 
105  template <class InputStorageType, class OutputStorageType>
108  {
109  BIASERR("FilterInt makes no sense here, using general Filter interface.");
110  return Filter(src, dst);
111  }
112 
113  template <class InputStorageType, class OutputStorageType>
116  {
117  BIASERR("FilterFloat makes no sense here, using general Filter interface.");
118  return Filter(src, dst);
119  }
120 
121  template <class InputStorageType, class OutputStorageType>
123  GetBordersValid_(int& border_x, int& border_y) const
124  {
125  BIASERR("No parameter support");
126  BIASABORT;
127  }
128 
129 
130 //////////////////////////////////////////////////////////////////////////
131 // instantiation
132 //////////////////////////////////////////////////////////////////////////
133 #define FILTER_INSTANTIATION_CLASS CensusTransform
134 #include "Filterinst.hh"
135 
136 } // namespace BIAS
virtual int Filter(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
virtual function for interface definition
gray values, 1 channel
Definition: ImageBase.hh:130
virtual int FilterFloat(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
unsigned int GetWidth() const
Definition: ImageBase.hh:312
3x3 Census Transform of greyscale image
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
Definition: ImageBase.hh:382
base class for simple n-&gt;n filter implementations
Definition: FilterNToN.hh:43
unsigned int GetHeight() const
Definition: ImageBase.hh:319
enum EColorModel GetColorModel() const
Definition: ImageBase.hh:407
virtual void GetBordersValid_(int &border_x, int &border_y) const
virtual int FilterInt(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase
Definition: Image.hh:153