URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-02-19 Fabien Freling <fabien.freling(a)lrde.epita.fr>
Experiment DICOM support with GDCM.
* fabien/gdcm/Makefile: Specific Makefile to test.
* fabien/gdcm/gdcm.cc: New test file.
* fabien/gdcm/load.hh: Implement GDCM DICOM support.
* fabien/magick/Makefile: Update.
* fabien/magick/load.hh: Update ImageMagick DICOM support.
* fabien/magick/magick.cc: Update.
---
gdcm/Makefile | 12 +++
gdcm/gdcm.cc | 18 +++++
gdcm/load.hh | 196 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
magick/load.hh | 10 ++
magick/magick.cc | 3
5 files changed, 238 insertions(+), 1 deletion(-)
Index: trunk/milena/sandbox/fabien/gdcm/Makefile
===================================================================
--- trunk/milena/sandbox/fabien/gdcm/Makefile (revision 0)
+++ trunk/milena/sandbox/fabien/gdcm/Makefile (revision 3394)
@@ -0,0 +1,12 @@
+all: gdcm.cc
+ g++ -I../../../ \
+ -I/Users/HiSoKa/Downloads/gdcm-2.0.10/Source/Common/ \
+ -I/Users/HiSoKa/Downloads/gdcmbin/Source/Common/ \
+ -I/Users/HiSoKa/Downloads/gdcm-2.0.10/Source/DataDictionary/ \
+ -I/Users/HiSoKa/Downloads/gdcm-2.0.10/Source/MediaStorageAndFileFormat/ \
+ -I/Users/HiSoKa/Downloads/gdcm-2.0.10/Source/DataStructureAndEncodingDefinition/ \
+ -L/Users/HiSoKa/Downloads/gdcmbin/bin \
+ -lgdcmCommon -lgdcmDICT -lgdcmDSED -lgdcmIOD -lgdcmMSFF -lgdcmexpat -lgdcmjpeg12
-lgdcmjpeg16 -lgdcmjpeg8 -lgdcmopenjpeg -lgdcmuuid -lgdcmzlib \
+ -framework CoreFoundation \
+ -DNDEBUG \
+ gdcm.cc -o mln_gdcm
Index: trunk/milena/sandbox/fabien/gdcm/load.hh
===================================================================
--- trunk/milena/sandbox/fabien/gdcm/load.hh (revision 0)
+++ trunk/milena/sandbox/fabien/gdcm/load.hh (revision 3394)
@@ -0,0 +1,196 @@
+// 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_IO_DICOM_LOAD_HH
+# define MLN_IO_DICOM_LOAD_HH
+
+/*!
+ * \file mln/io/magick/load.hh
+ *
+ * \brief Define a function which loads an image of kind magick with
+ * given path.
+ *
+ */
+
+# include <mln/core/image/image2d.hh>
+# include <mln/core/image/image3d.hh>
+
+# include <mln/value/int_u16.hh>
+
+# include <gdcmReader.h>
+# include <gdcmImageReader.h>
+# include <gdcmWriter.h>
+# include <gdcmDataSet.h>
+# include <gdcmAttribute.h>
+
+
+namespace mln
+{
+
+ namespace io
+ {
+
+ namespace dicom
+ {
+
+ /*! Load a gdcm image in a Milena image.
+ *
+ * \param[out] ima A reference to the image which will receive
+ * data.
+ * \param[in] filename The source.
+ */
+ template <typename I>
+ void load(Image<I>& ima,
+ const std::string& filename);
+
+ /*! Load a gdcm image in a Milena image. To use this routine, you
+ * should specialize the template whith the value type of the
+ * image loaded. (ex : load<value::int_u8>("...") )
+ *
+ * \param[in] filename The image source.
+ *
+ * \return An image2d which contains loaded data.
+ */
+ template <typename V>
+ image2d<V> load(const std::string& filename);
+
+ /*! Load a gdcm image in a Milena image. To use this routine, you
+ * should specialize the template whith the value type of the
+ * image loaded. (ex : load<value::int_u8>("...") )
+ *
+ * \param[in] filename The image source.
+ *
+ * \return An image2d which contains loaded data.
+ */
+ template <typename V>
+ image3d<V> load(const std::string& filename);
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename V>
+ inline
+ image2d<V> load(const std::string& filename)
+ {
+ trace::entering("mln::io::gdcm::load");
+ image2d<V> ima;// = io::pnm::load<V>(MAGICK, filename);
+ trace::exiting("mln::io::gdcm::load");
+ return ima;
+ }
+
+ template <typename V>
+ inline
+ image3d<V> load(const std::string& filename)
+ {
+ trace::entering("mln::io::gdcm::load");
+ image2d<V> ima;// = io::pnm::load<V>(MAGICK, filename);
+ trace::exiting("mln::io::gdcm::load");
+ return ima;
+ }
+
+
+ template <typename I>
+ inline
+ void load(Image<I>& ima_,
+ const std::string& filename)
+ {
+ trace::entering("mln::io::gdcm::load");
+
+ using value::int_u16;
+ I& ima = exact(ima_);
+
+ gdcm::ImageReader r;
+ r.SetFileName(filename.c_str());
+ if (!r.Read())
+ {
+ std::cerr << "error: cannot open file '" << filename
<< "'!";
+ abort();
+ }
+
+ gdcm::File &file = r.GetFile();
+ gdcm::DataSet& ds = file.GetDataSet();
+
+ gdcm::Image& image = r.GetImage();
+
+ std::cout << std::endl << "Image information" << std::endl
+ << "=================" << std::endl;
+ image.Print(std::cout);
+
+ std::cout << std::endl << "Buffer information" << std::endl
+ << "=================" << std::endl;
+ std::cout << "Buffer length: " << image.GetBufferLength() <<
std::endl;
+ char* dataBuffer = new char[image.GetBufferLength()];
+ if (image.GetBuffer(dataBuffer))
+ std::cout << "GetBuffer success" << std::endl;
+ else
+ std::cout << "GetBuffer failure" << std::endl;
+
+ int ndims = image.GetNumberOfDimensions();
+ const unsigned int* dims = image.GetDimensions();
+
+ // FIXME: Check ScalarType
+ if (ndims == 1)
+ {
+
+ }
+ if (ndims == 2)
+ {
+ //image2d<int_u16> mln_ima(dims[1], dims[0]);
+ //mln_piter(image2d<int_u16>) p(ima.domain());
+ //for_all(p)
+ //{
+ // ima(p) = dataBuffer[(p.col() + p.row() * dims[0]) * 2] * 256 +
+ // dataBuffer[(p.col() + p.row() * dims[0]) * 2 + 1];
+ //}
+ }
+ if (ndims == 3)
+ {
+ //image3d<int_u16> ima(dims[2], dims[1], dims[0]);
+ mln_site(I) pmin(0, 0, 0);
+ mln_site(I) pmax(dims[2], dims[1], dims[0]);
+ mln_concrete(I) result(box<mln_site(I)>(pmin, pmax));
+ initialize(ima, result);
+ mln_piter(image3d<int_u16>) p(ima.domain());
+ for_all(p)
+ {
+ ima(p) = dataBuffer[(p.col() + p.row() * dims[0] + p.sli() * dims[0] * dims[1]) * 2]
* 256+
+ dataBuffer[(p.col() + p.row() * dims[0] + p.sli() * dims[0] * dims[1]) * 2 + 1];
+ }
+ }
+
+ trace::exiting("mln::io::dicom::load");
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::io::dicom
+
+ } // end of namespace mln::io
+
+} // end of namespace mln
+
+
+#endif // ! MLN_IO_DICOM_LOAD_HH
Index: trunk/milena/sandbox/fabien/gdcm/gdcm.cc
===================================================================
--- trunk/milena/sandbox/fabien/gdcm/gdcm.cc (revision 0)
+++ trunk/milena/sandbox/fabien/gdcm/gdcm.cc (revision 3394)
@@ -0,0 +1,18 @@
+#include <mln/core/image/image2d.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/value/int_u16.hh>
+
+#include "load.hh"
+
+#include <mln/io/dump/save.hh>
+
+int main()
+{
+ using namespace mln;
+ using value::int_u16;
+
+ image3d<int_u16> lena;
+
+ io::dicom::load(lena, "/Users/HiSoKa/Work/IGR/souris18/irm/IM_0052.dcm");
+ io::dump::save(lena, "IM_0052.dump");
+}
Index: trunk/milena/sandbox/fabien/magick/magick.cc
===================================================================
--- trunk/milena/sandbox/fabien/magick/magick.cc (revision 3393)
+++ trunk/milena/sandbox/fabien/magick/magick.cc (revision 3394)
@@ -10,5 +10,6 @@
image2d<int_u8> lena;
- io::magick::load(lena,
"/Users/HiSoKa/Work/LRDE/Olena/resources/CardiacCT/178562160.dcm");
+ //io::magick::load(lena,
"/Users/HiSoKa/Work/LRDE/Olena/resources/CardiacCT/178562160.dcm");
+ io::magick::load(lena, "/Users/HiSoKa/Work/IGR/souris18/irm/IM_0052.dcm");
}
Index: trunk/milena/sandbox/fabien/magick/Makefile
===================================================================
Index: trunk/milena/sandbox/fabien/magick/load.hh
===================================================================
--- trunk/milena/sandbox/fabien/magick/load.hh (revision 3393)
+++ trunk/milena/sandbox/fabien/magick/load.hh (revision 3394)
@@ -124,8 +124,18 @@
std::cout << "height: " << file.rows() << std::endl;
std::cout << "x resolution: " << file.xResolution() <<
std::endl;
std::cout << "y resolution: " << file.yResolution() <<
std::endl;
+ std::cout << "depth: " << file.depth() << std::endl;
+ //std::cout << "packets: " << file.packets() << std::endl;
+ //std::cout << "packet size: " << file.packetSize() <<
std::endl;
std::cout << "comment: " << file.comment() << std::endl;
std::cout << "format: " << file.format() << std::endl;
+ std::cout << "number of scenes: " <<
file.imageInfo()->number_scenes << std::endl;
+ std::cout << "scene: " << file.imageInfo()->scene <<
std::endl;
+ std::cout << "filename: " << file.imageInfo()->filename
<< std::endl;
+
+ //Magick::Pixels::Pixels pixels(file);
+ //std::cout << "sizeof PixelPacket: " << sizeof (pixel_cache)
<< std::endl;
+ //std::cout << "sizeof *PixelPacket: " << sizeof (*pixel_cache)
<< std::endl;
trace::exiting("mln::io::magick::load");
}