File: image_types.hpp

package info (click to toggle)
gamera 1:3.4.2+git20160808.1725654-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 22,312 kB
  • ctags: 24,991
  • sloc: xml: 122,324; ansic: 52,869; cpp: 50,664; python: 35,034; makefile: 118; sh: 101
file content (325 lines) | stat: -rw-r--r-- 10,136 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/*
 *
 * Copyright (C) 2001-2005 Ichiro Fujinaga, Michael Droettboom, Karl MacMillan
 *               2009      Jonathan Koch
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#ifndef kwm03112002_image_types
#define kwm03112002_image_types

#include "pixel.hpp"
#include "image_data.hpp"
#include "image_view.hpp"
#include "rle_data.hpp"
#include "connected_components.hpp"

#include <list>

/*
  The standard image types.
*/

namespace Gamera {

  /*
    Image Data
   */
  typedef ImageData<GreyScalePixel> GreyScaleImageData;
  typedef ImageData<Grey16Pixel> Grey16ImageData;
  typedef ImageData<FloatPixel> FloatImageData;
  typedef ImageData<RGBPixel> RGBImageData;
  typedef ImageData<ComplexPixel> ComplexImageData;
  typedef ImageData<OneBitPixel> OneBitImageData;
  typedef RleImageData<OneBitPixel> OneBitRleImageData;

  /*
    ImageView
   */
  typedef ImageView<GreyScaleImageData> GreyScaleImageView;
  typedef ImageView<Grey16ImageData> Grey16ImageView;
  typedef ImageView<FloatImageData> FloatImageView;
  typedef ImageView<RGBImageData> RGBImageView;
  typedef ImageView<ComplexImageData> ComplexImageView;
  typedef ImageView<OneBitImageData> OneBitImageView;
  typedef ImageView<OneBitRleImageData> OneBitRleImageView;

  /*
    Connected-components
   */
  typedef ConnectedComponent<OneBitImageData> Cc;
  typedef ConnectedComponent<OneBitRleImageData> RleCc;
  typedef std::list<Cc*> ConnectedComponents;
  typedef std::list<RleCc*> RleConnectedComponents;
  typedef MultiLabelCC<OneBitImageData> MlCc;
  typedef std::list<MlCc*> MlCcs;

  /*
    Enumeration for all of the image types, pixel types, and storage
    types.
  */
  enum PixelTypes {
    ONEBIT,
    GREYSCALE,
    GREY16,
    RGB,
    FLOAT,
    COMPLEX
  };
  
  enum StorageTypes {
    DENSE,
    RLE
  };
  
  /*
    To make the wrapping code a little easier these are all of the
    combinations of pixel and storage types. The order is so that
    the non-compressed views correspond to the PixelTypes.
  */
  enum ImageCombinations {
    ONEBITIMAGEVIEW,
    GREYSCALEIMAGEVIEW,
    GREY16IMAGEVIEW,
    RGBIMAGEVIEW,
    FLOATIMAGEVIEW,
    COMPLEXIMAGEVIEW,
    ONEBITRLEIMAGEVIEW,
    CC,
    RLECC,
    MLCC
  };
  
  enum ClassificationStates {
    UNCLASSIFIED,
    AUTOMATIC,
    HEURISTIC,
    MANUAL
  };

  enum ConfidenceTypes {
    CONFIDENCE_DEFAULT,
    CONFIDENCE_KNNFRACTION,
    CONFIDENCE_INVERSEWEIGHT,
    CONFIDENCE_LINEARWEIGHT,
    CONFIDENCE_NUN,
    CONFIDENCE_NNDISTANCE,
    CONFIDENCE_AVGDISTANCE
  };

  /*
    Factory for types based on an existing image. This makes it easier
    to make a new view from an existing type without worrying whether
    it is a Cc, etc.
  */
  template<class T>
  struct ImageFactory {
    // data types
    typedef typename T::data_type data_type;
    typedef ImageData<typename T::value_type> dense_data_type;
    typedef RleImageData<typename T::value_type> rle_data_type;
    // view types
    typedef ImageView<data_type> view_type;
    typedef ImageView<dense_data_type> dense_view_type;
    typedef ImageView<rle_data_type> rle_view_type;
    // cc types
    typedef ConnectedComponent<data_type> cc_type;
    typedef ConnectedComponent<dense_data_type> dense_cc_type;
    typedef ConnectedComponent<rle_data_type> rle_cc_type;
    typedef std::list<cc_type*> ccs_type;
    typedef std::list<dense_cc_type*> dense_ccs_type;
    typedef std::list<rle_cc_type*> rle_ccs_type;
    // methods for creating new images and views
    static view_type* new_view(const T& view) {
      view_type* nview = new view_type(*((data_type*)view.data()),
				       view.origin(),
				       view.dim());
      return nview;
    }

    static view_type* new_view(const T& view, const Point& origin, const Dim& dim) {
      view_type* nview = new view_type(*((data_type*)view.data()),
				       origin, dim);
      return nview;
    }

    static view_type* new_image(const T& view) {
      data_type* data = new data_type(view.nrows(), view.ncols(),
				      view.offset_y(), view.offset_x());
      view_type* nview = new view_type(*data,
				      view.offset_y(), view.offset_x(),
				      view.nrows(), view.ncols());
      return nview;
    }
  };

  template<>
  struct ImageFactory<RGBImageView> {
    // data types
    typedef RGBImageView::data_type data_type;
    typedef ImageData<RGBImageView::value_type> dense_data_type;
    typedef ImageData<RGBImageView::value_type> rle_data_type;
    // view types
    typedef ImageView<data_type> view_type;
    typedef ImageView<dense_data_type> dense_view_type;
    typedef ImageView<rle_data_type> rle_view_type;
    // cc types
    typedef ConnectedComponent<data_type> cc_type;
    typedef ConnectedComponent<dense_data_type> dense_cc_type;
    typedef ConnectedComponent<rle_data_type> rle_cc_type;
    typedef std::list<cc_type*> ccs_type;
    typedef std::list<dense_cc_type*> dense_ccs_type;
    typedef std::list<rle_cc_type*> rle_ccs_type;
    static view_type* new_view(const RGBImageView& view) {
      view_type* nview = new view_type(*((data_type*)view.data()),
				       view.origin(), view.dim());
      return nview;
    }
    static view_type* new_view(const RGBImageView& view, const Point& origin,
			       const Dim& dim) {
      view_type* nview = new view_type(*((data_type*)view.data()),
				       origin, dim);
      return nview;
    }

    static view_type* new_image(const RGBImageView& view) {
      data_type* data = new data_type(view.dim(), view.origin());
      view_type* nview = new view_type(*data, view.origin(), view.dim());
      return nview;
    }
  };

  template<>
  struct ImageFactory<ComplexImageView> {
    // data types
    typedef ComplexImageView::data_type data_type;
    typedef ImageData<ComplexImageView::value_type> dense_data_type;
    typedef ImageData<ComplexImageView::value_type> rle_data_type;
    // view types
    typedef ImageView<data_type> view_type;
    typedef ImageView<dense_data_type> dense_view_type;
    typedef ImageView<rle_data_type> rle_view_type;
    // cc types
    typedef ConnectedComponent<data_type> cc_type;
    typedef ConnectedComponent<dense_data_type> dense_cc_type;
    typedef ConnectedComponent<rle_data_type> rle_cc_type;
    typedef std::list<cc_type*> ccs_type;
    typedef std::list<dense_cc_type*> dense_ccs_type;
    typedef std::list<rle_cc_type*> rle_ccs_type;
    static view_type* new_view(const ComplexImageView& view) {
      view_type* nview = new view_type(*((data_type*)view.data()),
				       view.origin(), view.dim());
      return nview;
    }
    static view_type* new_view(const ComplexImageView& view, const Point& origin, const Dim& dim) {
      view_type* nview = new view_type(*((data_type*)view.data()),
				       origin, dim);
      return nview;
    }

    static view_type* new_image(const ComplexImageView& view) {
      data_type* data = new data_type(view.dim(), view.origin());
      view_type* nview = new view_type(*data, view.origin(), view.dim());
      return nview;
    }
  };

  /*
    TypeIdImageFactory

    This factory type can be used to easily create new images using the
    enums above.
  */
  template<int Pixel, int Storage>
  struct TypeIdImageFactory {

  };
  
  template<>
  struct TypeIdImageFactory<ONEBIT, DENSE> {
    typedef OneBitImageData data_type;
    typedef OneBitImageView image_type;
    static image_type* create(const Point& origin, const Dim& dim) {
      data_type* data = new data_type(dim, origin);
      return new image_type(*data, origin, dim);
    }
  };

  template<>
  struct TypeIdImageFactory<ONEBIT, RLE> {
    typedef OneBitRleImageData data_type;
    typedef OneBitRleImageView image_type;
    static image_type* create(const Point& origin, const Dim& dim) {
      data_type* data = new data_type(dim, origin);
      return new image_type(*data, origin, dim);
    }
  };

  template<>
  struct TypeIdImageFactory<GREYSCALE, DENSE> {
    typedef GreyScaleImageData data_type;
    typedef GreyScaleImageView image_type;
    static image_type* create(const Point& origin, const Dim& dim) {
      data_type* data = new data_type(dim, origin);
      return new image_type(*data, origin, dim);
    }
  };

  template<>
  struct TypeIdImageFactory<GREY16, DENSE> {
    typedef Grey16ImageData data_type;
    typedef Grey16ImageView image_type;
    static image_type* create(const Point& origin, const Dim& dim) {
      data_type* data = new data_type(dim, origin);
      return new image_type(*data, origin, dim);
    }
  };

  template<>
  struct TypeIdImageFactory<RGB, DENSE> {
    typedef RGBImageData data_type;
    typedef RGBImageView image_type;
    static image_type* create(const Point& origin, const Dim& dim) {
      data_type* data = new data_type(dim, origin);
      return new image_type(*data, origin, dim);
    }
  };


  template<>
  struct TypeIdImageFactory<COMPLEX, DENSE> {
    typedef ComplexImageData data_type;
    typedef ComplexImageView image_type;
    static image_type* create(const Point& origin, const Dim& dim) {
      data_type* data = new data_type(dim, origin);
      return new image_type(*data, origin, dim);
    }
  };

  template<>
  struct TypeIdImageFactory<FLOAT, DENSE> {
    typedef FloatImageData data_type;
    typedef FloatImageView image_type;
    static image_type* create(const Point& origin, const Dim& dim) {
      data_type* data = new data_type(dim, origin);
      return new image_type(*data, origin, dim);
    }
  };

}


#endif