URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-02-20 Fabien Freling <fabien.freling(a)lrde.epita.fr>
Update DICOM support to n dimensions.
* fabien/gdcm/gdcm.cc: Update.
* fabien/gdcm/load.hh: Update load support for
multidimensional DICOM.
---
gdcm.cc | 11 ++++++--
load.hh | 80 ++++++++++++++++++----------------------------------------------
2 files changed, 31 insertions(+), 60 deletions(-)
Index: trunk/milena/sandbox/fabien/gdcm/load.hh
===================================================================
--- trunk/milena/sandbox/fabien/gdcm/load.hh (revision 3402)
+++ trunk/milena/sandbox/fabien/gdcm/load.hh (revision 3403)
@@ -39,7 +39,7 @@
# include <mln/core/image/image2d.hh>
# include <mln/core/image/image3d.hh>
-# include <mln/value/int_u16.hh>
+# include <mln/algebra/vec.hh>
# include <gdcmReader.h>
# include <gdcmImageReader.h>
@@ -57,7 +57,7 @@
namespace dicom
{
- /*! Load a gdcm image in a Milena image.
+ /*! Load a dicom image in a Milena image.
*
* \param[out] ima A reference to the image which will receive
* data.
@@ -67,28 +67,6 @@
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>
@@ -135,52 +113,40 @@
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()];
image.GetBuffer(dataBuffer);
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];
- //}
+ algebra::vec<mln_site_(I)::dim, unsigned int> vmin;
+ algebra::vec<mln_site_(I)::dim, unsigned int> vmax;
+ algebra::vec<mln_site_(I)::dim, unsigned int> vdims;
+ for (int i = ndims - 1; i >= 0; --i)
+ {
+ vmin[i] = 0;
+ vmax[i] = dims[ndims - i - 1] - 1;
+ if (i == ndims - 1)
+ vdims[i] = 1;
+ else
+ vdims[i] = dims[ndims - i - 2] * vdims[i + 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] - 1, dims[1] - 1, dims[0] - 1);
+
+ mln_site(I) pmin(vmin);
+ mln_site(I) pmax(vmax);
mln_concrete(I) result(box<mln_site(I)>(pmin, pmax));
initialize(ima, result);
mln_piter(I) p(ima.domain());
+ // FIXME: Check ScalarType and HighBit
+ unsigned int index = 0;
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];
- std::cout << (p.col() + p.row() * dims[0] + p.sli() * dims[0] * dims[1]) * 2
<< " ["
- << "p.col = " << p.col() << "] ["
- << "p.row = " << p.row() << "] ["
- << "p.sli = " << p.sli() << "]"
- << std::endl;
+ index = 0;
+ for (int i = 0; i < ndims; ++i)
+ {
+ index += p.to_site().to_vec()[i] * vdims[i];
}
+ ima(p) = dataBuffer[index * 2] * 256 + dataBuffer[index * 2 + 1];
}
delete(dataBuffer);
Index: trunk/milena/sandbox/fabien/gdcm/gdcm.cc
===================================================================
--- trunk/milena/sandbox/fabien/gdcm/gdcm.cc (revision 3402)
+++ trunk/milena/sandbox/fabien/gdcm/gdcm.cc (revision 3403)
@@ -1,18 +1,23 @@
#include <mln/core/image/image2d.hh>
+#include <mln/core/image/image3d.hh>
#include <mln/value/int_u8.hh>
#include <mln/value/int_u16.hh>
#include "load.hh"
#include <mln/io/dump/save.hh>
+#include <mln/io/pgm/save.hh>
int main()
{
using namespace mln;
using value::int_u16;
- image3d<int_u16> lena;
+ image2d<int_u16> lena2;
+ image3d<int_u16> lena3;
- io::dicom::load(lena, "/Users/HiSoKa/Work/IGR/souris18/irm/IM_0061.dcm");
- io::dump::save(lena, "IM_0061.dump");
+ //io::dicom::load(lena3, "/Users/HiSoKa/Work/IGR/souris18/irm/IM_0058.dcm");
+ io::dicom::load(lena2, "/Users/HiSoKa/Work/IGR/souris18/irm/IM_0058.dcm");
+ //io::dump::save(lena3, "IM_0058.dump");
+ io::pgm::save(lena2, "IM_0058.pgm");
}