Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TukeyWindow.cpp
1 /*
2  This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4  Copyright (C) 2003, 2004 (see file CONTACTS 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 "TukeyWindow.hh"
26 
27 namespace BIAS {
28  template <class InputStorageType, class OutputStorageType>
30  : FilterNToN<InputStorageType,OutputStorageType>()
31  {
32  ratio_ = 0.5f;
33  zeropad_ = 0;
34  }
35 
36  template <class InputStorageType, class OutputStorageType>
38  TukeyWindow(float ratio, unsigned int zeropad)
39  : FilterNToN<InputStorageType,OutputStorageType>()
40  {
41  ratio_ = ratio;
42  zeropad_ = zeropad;
43  }
44 
45  template <class InputStorageType, class OutputStorageType>
48  : FilterNToN<InputStorageType, OutputStorageType>(other)
49  {
50  ratio_ = other.ratio_;
51  }
52 
53  template <class InputStorageType, class OutputStorageType>
55  // TODO
56  }
57 
58  template <class InputStorageType, class OutputStorageType>
61  return FilterFloat(src, dst);
62  }
63 
64  template <class InputStorageType, class OutputStorageType>
67  return FilterFloat(src, dst);
68  }
69 
70  template <class InputStorageType, class OutputStorageType>
73  if (ratio_ == 0.0) {
74  if (src.GetStorageType() != dst.GetStorageType()) {
75  BIASWARN("implicit type conversion");
76  }
77  dst = src;
78  return 0;
79  }
80  unsigned int w = src.GetWidth();
81  unsigned int h = src.GetHeight();
82  unsigned int ch = src.GetChannelCount();
83  if (dst.IsEmpty()) {
84  dst.Init(w+2*zeropad_,h+2*zeropad_,ch);
85  } else {
86  dst.ReInit(w+2*zeropad_,h+2*zeropad_,ch);
87  }
88  if (zeropad_ != 0) {
89  dst.FillImageWithConstValue((OutputStorageType)0);
90  }
91  if (ratio_ == 1.0) {
92  // hmm TODO
93  BIASERR("Not implemented!");
94  } else {
95  // compute idxes tapper, one, tapper
96  float per = ratio_ / 2.0f;
97  unsigned int wtl = (unsigned int)floor(per*(w-1));
98  unsigned int wth = w-wtl-1;
99  unsigned int htl = (unsigned int)floor(per*(h-1));
100  unsigned int hth = h-htl-1;
101 
102  const InputStorageType **idaIn = src.GetImageDataArray();
103  OutputStorageType **idaOut = dst.GetImageDataArray();
104 
105  for (unsigned int y=0;y<h;y++) {
106  for (unsigned int x=0;x<w;x++) {
107  for (unsigned int c=0;c<ch;c++) {
108  OutputStorageType curval = (OutputStorageType) idaIn[y][x*ch+c];
109  // [0 .. tl] .. [tl+1 ..th-tl-1] .. [th-tl .. th]
110  if (x < wtl) {
111  float idx = float(x)/float(wtl);
112  curval = curval * (OutputStorageType)((1+cos((1.0f - idx) * M_PI)) / 2.0f);
113  }
114  if (x >= wth) {
115  float idx = float(x-wth)/float(w-wth-1);
116  curval = curval * (OutputStorageType)((1+cos(idx * M_PI)) / 2.0f);
117  }
118  if (y < htl) {
119  float idx = float(y)/float(htl);
120  curval = curval * (OutputStorageType)((1+cos((1.0f - idx) * M_PI)) / 2.0f);
121  }
122  if (y >= hth) {
123  float idx = float(y-hth)/float(h-hth-1);
124  curval = curval * (OutputStorageType)((1+cos(idx * M_PI)) / 2.0f);
125  }
126  idaOut[y+zeropad_][(x+zeropad_)*ch+c] = curval;
127  }
128  }
129  }
130 
131 
132  }
133  return 0;
134  }
135 
136  #define FILTER_INSTANTIATION_CLASS TukeyWindow
137  #include "Filterinst.hh"
138 }
Multiplies an image with a full image size tukey window.
Definition: TukeyWindow.hh:38
virtual int Filter(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
virtual function for interface definition
Definition: TukeyWindow.cpp:59
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
Definition: ImageBase.hh:245
virtual int FilterFloat(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
Definition: TukeyWindow.cpp:71
virtual ~TukeyWindow()
Definition: TukeyWindow.cpp:54
unsigned int GetWidth() const
Definition: ImageBase.hh:312
void ReInit(const unsigned int &width, const unsigned int &height, const unsigned int nChannels=1, const enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true, const EColorModel colormodel=CM_Grey)
(Re-)Initialize Image data if required.
Definition: ImageBase.cpp:131
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
void FillImageWithConstValue(StorageType Value)
fill grey images
Definition: Image.cpp:456
virtual int FilterInt(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
Definition: TukeyWindow.cpp:65
void Init(unsigned int Width, unsigned int Height, unsigned int channels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
calls Init from ImageBase storageType is ignored, just dummy argument
Definition: Image.cpp:421
enum EStorageType GetStorageType() const
Definition: ImageBase.hh:414
TukeyWindow()
Default Constructor, ratio 0.5, zeropad 0.
Definition: TukeyWindow.cpp:29
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase
Definition: Image.hh:153