/* -*- 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
*/