last-svn-commit-706-g8f0158d mln/io/dicom/load.hh: Fix invalid data while loading large image.

--- milena/ChangeLog | 5 +++++ milena/mln/io/dicom/load.hh | 37 ++++++++++++++++++------------------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/milena/ChangeLog b/milena/ChangeLog index 994efe7..1939611 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,3 +1,8 @@ +2011-05-12 Guillaume Lazzara <z@lrde.epita.fr> + + * mln/io/dicom/load.hh: Fix invalid data while loading large + image. + 2011-01-27 Guillaume Lazzara <z@lrde.epita.fr> * mln/io/dicom/load.hh: Fix invalid image loading. diff --git a/milena/mln/io/dicom/load.hh b/milena/mln/io/dicom/load.hh index 1823b18..be75bdf 100644 --- a/milena/mln/io/dicom/load.hh +++ b/milena/mln/io/dicom/load.hh @@ -1,4 +1,5 @@ -// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2009, 2011 EPITA Research and Development Laboratory +// (LRDE) // // This file is part of Olena. // @@ -143,14 +144,21 @@ namespace mln 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 = 0; i < ndims; ++i) + int j = ndims - 1; + for (int i = 0; i < ndims; ++i, --j) { vmin[i] = 0; vmax[i] = dims[i] - 1; if (i == 0) - vdims[i] = 1; + vdims[j] = 1; else - vdims[i] = dims[i - 1] * vdims[i - 1]; + vdims[j] = dims[i - 1] * vdims[j + 1]; + } + + if (ndims > 1) + { + std::swap(vmin[0], vmin[1]); + std::swap(vmax[0], vmax[1]); } mln_site(I) pmin(vmin); @@ -160,31 +168,22 @@ namespace mln mln_piter(I) p(ima.domain()); unsigned int index = 0; - // FIXME: HACK. We may prefer to change the way we access the - // data instead of swapping that information. If swap is not - // performed, the loaded image is rotated and symmetrized. - std::swap(vdims[0], vdims[1]); - - // int k = 0; for_all(p) { index = 0; for (int i = 0; i < ndims; ++i) { - index += p.to_site().to_vec()[i] * vdims[i]; + index += p[i] * vdims[i]; } - ima(p) = (unsigned char) dataBuffer[(index * bytes_allocated) * samples_per_pixel]; + mln_value(I) v = (unsigned char) dataBuffer[(index * bytes_allocated) * samples_per_pixel]; // FIXME: RGB support, HighBit if HB == 1 - for (int j = 0; j < bytes_allocated; ++j) + for (unsigned int j = 0; j < bytes_allocated; ++j) { - ima(p) += ((unsigned char) dataBuffer[(index * bytes_allocated + j) * samples_per_pixel]) * 256 * j; + v += ((unsigned char) dataBuffer[(index * bytes_allocated + j) * samples_per_pixel]) * 256 * j; } - /*std::cout << "[ x = " << p.to_site().to_vec()[0] - << " | y = " << p.to_site().to_vec()[1] - << " | z = " << p.to_site().to_vec()[2] - << " ] => " << ima(p) - << std::endl;*/ + + ima(p) = v; } delete(dataBuffer); -- 1.5.6.5
participants (1)
-
Guillaume Lazzara