
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2009-02-26 Fabien Freling <fabien.freling@lrde.epita.fr> Add int_u12 type and fix DICOM support. * mln/convert/from_to.hxx: Convert histo::array into image1d. * mln/core/image/image1d.hh: Convert histo::array into image1d. * mln/io/all.hh: Add dicom include file. * mln/io/dicom/load.hh: Fix load support. * mln/value/int_u12.hh: New, implement int_u12 type. --- image1d.hh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) Index: trunk/milena/mln/core/image/image1d.hh =================================================================== --- trunk/milena/mln/core/image/image1d.hh (revision 3428) +++ trunk/milena/mln/core/image/image1d.hh (revision 3429) @@ -118,6 +118,27 @@ + // Forward declaration. + template <typename T> struct image1d; + + + + namespace convert + { + + namespace over_load + { + + // histo::array -> image1d. + template <typename V, typename T> + void from_to_(const histo::array<V>& from, image1d<T>& to); + + } // end of namespace mln::convert::over_load + + } // end of namespace mln::convert + + + /*! \brief Basic 1D image class. * * The parameter \c T is the type of pixel values. This image class @@ -520,9 +541,33 @@ # include <mln/core/w_window.hh> + namespace mln { + + namespace convert + { + + namespace over_load + { + + // histo::array -> image1d. + template <typename V, typename T> + inline + void + from_to_(const histo::array<V>& from, image1d<T>& to) + { + to.init_(make::box1d(from.nvalues()), 0); + for (unsigned i = 0; i < from.nvalues(); ++i) + from_to(from[i], to(point1d(i))); + } + + } // end of namespace mln::convert::over_load + + } // end of namespace mln::convert + + namespace trait { Index: trunk/milena/mln/value/int_u12.hh =================================================================== --- trunk/milena/mln/value/int_u12.hh (revision 0) +++ trunk/milena/mln/value/int_u12.hh (revision 3429) @@ -0,0 +1,55 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library 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 library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef MLN_VALUE_INT_U12_HH +# define MLN_VALUE_INT_U12_HH + +/*! \file mln/value/int_u12.hh + * + * \brief Define the alias value::int_u12. + */ + +# include <mln/value/int_u.hh> + + +namespace mln +{ + + namespace value + { + + + /// Alias for unsigned 12-bit integers. + typedef int_u<12> int_u12; + + + } // end of namespace mln::value + +} // end of namespace mln + + +#endif // ! MLN_VALUE_INT_U12_HH Index: trunk/milena/mln/convert/from_to.hxx =================================================================== --- trunk/milena/mln/convert/from_to.hxx (revision 3428) +++ trunk/milena/mln/convert/from_to.hxx (revision 3429) @@ -65,6 +65,8 @@ template <typename D> class window; template <typename D, typename W> class w_window; + template <typename T> struct image1d; + namespace algebra { template <unsigned n, typename T> class vec; template <unsigned d, typename C> class h_vec; @@ -76,6 +78,10 @@ } } + namespace histo { + template <typename T> struct array; + } + namespace util { template <typename T> class array; } @@ -360,6 +366,11 @@ void from_to_(const std::set<P,_C>& from, Site_Set<S>& to); + // histo::array -> image1d + template <typename V, typename T> + void + from_to_(const histo::array<V>& from, image1d<T>& to); + } // end of namespace mln::convert::over_load } // end of namespace mln::convert Index: trunk/milena/mln/io/dicom/load.hh =================================================================== --- trunk/milena/mln/io/dicom/load.hh (revision 3428) +++ trunk/milena/mln/io/dicom/load.hh (revision 3429) @@ -95,9 +95,8 @@ void load(Image<I>& ima_, const std::string& filename) { - trace::entering("mln::io::gdcm::load"); + trace::entering("mln::io::dicom::load"); - using value::int_u16; I& ima = exact(ima_); gdcm::ImageReader r; @@ -119,9 +118,18 @@ int ndims = image.GetNumberOfDimensions(); const unsigned int* dims = image.GetDimensions(); - unsigned short bytes_allocated = image.GetPixelFormat().GetBitsAllocated() / 8; + unsigned short bits_allocated = image.GetPixelFormat().GetBitsAllocated(); + unsigned short bytes_allocated = bits_allocated / 8; + unsigned short bits_stored = image.GetPixelFormat().GetBitsStored(); unsigned short samples_per_pixel = image.GetPixelFormat().GetSamplesPerPixel(); + unsigned int offset = 8 - (bits_allocated - bits_stored); + unsigned int off_pow = 1; + for (int i = 0; i < offset; ++i) + { + off_pow *= 2; + } + if (mln_site_(I)::dim != ndims) { std::cerr << "error: dimension mismatch" << std::endl; @@ -154,13 +162,18 @@ { index += p.to_site().to_vec()[i] * vdims[i]; } - ima(p) = dataBuffer[index * bytes_allocated * samples_per_pixel]; - // FIXME: RGB support, HighBit - for (int j = 1; j < bytes_allocated; ++j) - { - ima(p) *= 256; - ima(p) += dataBuffer[(index * bytes_allocated + j) * samples_per_pixel]; - } + + ima(p) = (unsigned char) dataBuffer[(index * bytes_allocated) * samples_per_pixel]; + // FIXME: RGB support, HighBit if HB == 1 + for (int j = 0; j < bytes_allocated; ++j) + { + ima(p) += ((unsigned char) dataBuffer[(index * bytes_allocated + j) * samples_per_pixel]) * 256 * j; + } + /*std::cout << "[ x = " << p.to_site().to_vec()[2] + << " | y = " << p.to_site().to_vec()[1] + << " | z = " << p.to_site().to_vec()[0] + << " ] => " << ima(p) + << std::endl;*/ } delete(dataBuffer); Index: trunk/milena/mln/io/all.hh =================================================================== --- trunk/milena/mln/io/all.hh (revision 3428) +++ trunk/milena/mln/io/all.hh (revision 3429) @@ -48,6 +48,7 @@ # include <mln/io/cloud/all.hh> # include <mln/io/dump/all.hh> +# include <mln/io/dicom/load.hh> # include <mln/io/pbm/all.hh> # include <mln/io/pfm/all.hh> # include <mln/io/pgm/all.hh>