[go: up one dir, main page]

Menu

[r999]: / libmona / libmona / 3DImage.hh  Maximize  Restore  History

Download this file

288 lines (212 with data), 8.2 kB

  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
/* -*- mona-c++ -*-
* Copyright (c) Leipzig, Madrid 2004 - 2008
* Max-Planck-Institute for Human Cognitive and Brain Science
* Max-Planck-Institute for Evolutionary Anthropology
* BIT, ETSI Telecomunicacion, UPM
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
// $Id: 3DImage.hh 981 2007-12-04 11:56:53Z wollny $
/*! \brief A 3D templated image class
2A fully templated class for 3D images
\file 3DImage.hh
\author Gert Wollny <wollny@cbs.mpg.de>
*/
#ifndef __MONA_3DIMAGE_HH
#define __MONA_3DIMAGE_HH 1
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <memory>
// MONA specific
#include <libmona/3DDatafield.hh>
#ifdef ENABLE_PTHREAD
#include <mona/parallel.hh>
#endif
namespace mona {
template <class T>
class T3DImage: public T3DDatafield<T> {
public:
//@{
/*! some shortcut datatype
*/
/// a shortcut data type
typedef typename T3DDatafield<T>::iterator iterator;
typedef typename T3DDatafield<T>::const_iterator const_iterator;
typedef typename T3DDatafield<T>::const_reference const_reference;
typedef typename T3DDatafield<T>::reference reference;
typedef typename T3DDatafield<T>::const_pointer const_pointer;
typedef typename T3DDatafield<T>::pointer pointer;
typedef typename T3DDatafield<T>::value_type value_type;
typedef typename T3DDatafield<T>::size_type size_type;
typedef typename T3DDatafield<T>::difference_type difference_type;
//@}
/// The pixel type of the image
typedef T Pixel;
//@{
T3DImage();
/*! copy constructor
The resulting image only contains a reference to the original data.
To change this data {\em make_single_ref} has to be called.
*/
T3DImage(const T3DImage& org);
//@}
//@{
/*! A Constructor to create an empty image.
\param Size the size of the new image
\param attr introduce an attribute list
*/
T3DImage(const C3DBounds& Size, const CAttributeList *attr = NULL);
~T3DImage();
//@}
//@{
/*! A constructor to create an image of given size from raw data.
\param Size the size of the new image
\param Data raw pixel data to initialize the image with
*/
T3DImage(const C3DBounds& Size, T *Data);
//@}
//@{
/*! Calculate the cuboid region, where the image contens is above a given threshold.
\param thresh threshold of values of interest
\param Start here the start coordinates of the resulting cuboid is returned
\param End here the end coordinates of the resulting cuboid is returned
*/
void get_region_of_interest(C3DBounds *Start,C3DBounds *End,const T thresh)const;
//@}
/** Calculate a difference image. The new image contains the absolute values of the differences
\param Ref the reference to which the difference is calculated.
\retval the image if absolute values of differences
\todo This function will be moved out of the class soon
*/
T3DImage<T> *get_delta(const T3DImage<T>& Ref) const;
/** Calculate the 1-norm difference between two images
\param Ref the reference to which the difference is calculated.
\retval the 1-norm of the difference
\todo This function will be moved out of the class soon
*/
double get_mismatch(const T3DImage<T>& Ref) const;
/** Get the minimal and maximal value of the data
\param min returns the minimal pixel value
\param max returns the maximal pixel value
\todo This function will be moved out of the class soon
*/
void get_min_max(T *min, T *max)const;
/** calculate a gradient field from the image data.
\todo This function will be moved out of the class soon
*/
template <class GradientField>
GradientField get_gradient_field()const;
};
/// special type_traints instaniation since the image is constructed on a fixed coordiante system
template <class T>
class data_type_traits< T3DImage<T> > {
typedef __mona_true_type is_grid_based_tag;
};
/// an image with doubles as pixel values
typedef T3DImage<double> C3DDImage;
/// an image with floats as pixel values
typedef T3DImage<float> C3DFImage;
/// an image with long ints as pixel values
typedef T3DImage<unsigned long> C3DULImage;
/// an image with long ints as pixel values
typedef T3DImage<long> C3DSLImage;
/// an image with long ints as pixel values
typedef T3DImage<unsigned int> C3DUIImage;
/// an image with long ints as pixel values
typedef T3DImage<int> C3DSIImage;
/// an image with short ints as pixel values
typedef T3DImage<short> C3DSSImage;
/// an image with unsigned short ints as pixel values
typedef T3DImage<unsigned short> C3DUSImage;
/// an image with unsigned bytes as pixel values
typedef T3DImage<uint8> C3DUBImage;
/// an image with signed bytes as pixel values
typedef T3DImage<int8> C3DSBImage;
/// an image with bits as pixel values
typedef T3DImage<bit> C3DBitImage;
// some implementations
template <class T>
template <class GradientField>
GradientField
T3DImage<T>::get_gradient_field()const
{
GradientField result(this->get_size());
typename GradientField::iterator r_result = result.begin();
for (unsigned int z=0; z < this->get_size().z-1; z++){
for (unsigned int y=0; y < this->get_size().y-1; y++){
for (unsigned int x=0; x < this->get_size().x-1; x++,r_result++) {
const T *H000 = &(*this)[x + this->get_size().x * (y + this->get_size().y * z)];
// Lookup all neccessary Values
const T H_100 = H000[-this->get_plane_size_xy()];
const T H0_10 = H000[-this->get_size().x];
const T H00_1 = H000[-1];
const T H001 = H000[ 1];
const T H010 = H000[this->get_size().x];
const T H100 = H000[this->get_plane_size_xy()];
*r_result = typename GradientField::value_type( H001 - H00_1,
H010 - H0_10,
H100 - H_100);
}
}
}
return result;
}
} // namespace mona
#endif
/* CVS LOG
$Log$
Revision 1.17 2005/06/29 13:22:20 wollny
switch to version 0.7
Revision 1.3 2005/05/31 19:21:12 gerddie
dont use namespace std, write it long
Revision 1.2 2005/04/07 16:40:15 gerddie
move to new wrapper paradicma, and bump up version
Revision 1.1.1.1 2005/03/17 13:44:18 gerddie
initial import
Revision 1.16 2005/02/16 15:05:37 wollny
versioning replaced
Revision 1.15 2005/01/25 14:01:45 wollny
support for direct attribute conversion
Revision 1.14 2005/01/20 14:34:19 wollny
review evaluation of gradient field
Revision 1.13 2005/01/17 18:18:28 wollny
deformer now tolarate larger vector fields
Revision 1.12 2004/11/15 09:39:48 wollny
remove Pixeltransfer
Revision 1.11 2004/11/03 15:36:25 wollny
make the attrlist const in the constructor
Revision 1.10 2004/11/03 14:29:50 wollny
change attribute list handling in 3DDatafield
Revision 1.9 2004/10/15 10:21:51 tittge
consistently promote attribute passing
Revision 1.8 2004/08/25 09:08:31 wollny
added an emacs style comment to all source files
Revision 1.7 2004/07/22 13:42:56 wollny
construt with attributes
Revision 1.6 2004/07/22 11:06:44 wollny
construt with attributes
Revision 1.5 2004/07/13 09:16:16 wollny
g++ 3.4 compile
Revision 1.4 2004/06/03 09:57:32 wollny
Changed (hopefully) all instancable class names to Cxxxxx
Revision 1.3 2004/02/20 08:57:44 tittge
add version tracking, improve iterator performance
Revision 1.2 2004/02/12 14:00:25 tittge
Major addaptions from libmia0
Revision 1.1.1.1 2004/02/11 18:18:05 tittge
start project
*/