URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-03-16 Fabien Freling <fabien.freling(a)lrde.epita.fr>
Fix median threshold and add ImageMagick load support..
* fabien/igr/Makefile: Update.
* fabien/igr/check.sh: Update.
* fabien/igr/med.cc: Fix median value.
* fabien/magick/Makefile: Update.
* fabien/magick/load.hh: Implement Magick support.
* fabien/magick/magick.cc: Test file for Magick support.
---
igr/Makefile | 2 -
igr/check.sh | 7 ++--
igr/med.cc | 26 +++++++++++----
magick/load.hh | 95 ++++++++++++++++++++-----------------------------------
magick/magick.cc | 19 +++++++----
5 files changed, 74 insertions(+), 75 deletions(-)
Index: trunk/milena/sandbox/fabien/igr/check.sh
===================================================================
--- trunk/milena/sandbox/fabien/igr/check.sh (revision 3535)
+++ trunk/milena/sandbox/fabien/igr/check.sh (revision 3536)
@@ -12,11 +12,14 @@
echo " for lambda_closing = ${lambda_closing}";
./clo_vol grad.dump $dim ${lambda_closing}
nbasins=`./wst clo_vol.dump $dim`
+ echo " nbasins = $nbasins"
../bin/dumpl32_to_colorize wst.dump $dim $nbasins
results/colorize_${3}_${lambda_closing}.ppm
median=`./med wst.dump $dim $input $nbasins`
+ echo " median = $median"
+ threshold=$(($median / 2))
../bin/dumpi12_to_pgm med.dump $dim results/median_${3}_${lambda_closing}.pgm
- ./thres med.dump $dim $median
- mv bin_result.pbm results/result_${3}_${lambda_closing}.pbm
+ ./thres med.dump $dim $threshold
+ mv result.pbm results/result_${3}_${lambda_closing}.pbm
#if [ $2 -eq 2 ]; then
# if [ ${lambda_closing} -eq 100 ]; then
Index: trunk/milena/sandbox/fabien/igr/med.cc
===================================================================
--- trunk/milena/sandbox/fabien/igr/med.cc (revision 3535)
+++ trunk/milena/sandbox/fabien/igr/med.cc (revision 3536)
@@ -20,9 +20,12 @@
#include <mln/core/routine/extend.hh>
#include <mln/accu/mean.hh>
#include <mln/accu/median_h.hh>
-#include <mln/morpho/elementary/dilation.hh>
+#include <mln/histo/array.hh>
+#include <mln/histo/compute.hh>
+#include <mln/labeling/compute.hh>
#include <mln/labeling/mean_values.hh>
#include <mln/level/compute.hh>
+#include <mln/morpho/elementary/dilation.hh>
#include <mln/pw/all.hh>
#include <mln/util/array.hh>
@@ -59,6 +62,8 @@
return 1;
}
+ unsigned median = 0;
+
if (dim == 2)
{
image2d<L> labels;
@@ -70,18 +75,27 @@
data::fill((labels | (pw::value(labels) == 0u)).rw(), wst_dilate);
mln_VAR(wst_mean, labeling::mean_values(dcm, labels, nbasins));
- accu::mean<float> accu_mean;
- util::array<float> means = level::compute(accu_mean, wst_mean);
-
- // FIXME: Take median value of means
+ histo::array<int_u12> histogram = histo::compute(wst_mean);
+ int j = 0;
+ int k = 0;
+ for (int i = 0; i < histogram.nvalues(); ++i)
+ {
+ if (histogram[i])
+ histogram[i] = i;
+ }
+ image1d<unsigned> ima_histo;
+ convert::from_to(histogram, ima_histo);
+ accu::median_h<int_u12> accu_med;
+ median = level::compute(accu_med, ima_histo | pw::value(ima_histo) != pw::cst(0));
io::dump::save(wst_mean, "med.dump");
- std::cout << median << std::endl;
}
else
{
// FIXME
}
+ std::cout << median << std::endl;
+
return 0;
}
Index: trunk/milena/sandbox/fabien/igr/Makefile
===================================================================
--- trunk/milena/sandbox/fabien/igr/Makefile (revision 3535)
+++ trunk/milena/sandbox/fabien/igr/Makefile (revision 3536)
@@ -49,4 +49,4 @@
g++ -I../../../ ${CXXFLAGS} $^ -o thres
clean:
- rm -rf *.dump *.p?m *.plot *.log *.csv
+ rm -rf *.dump *.p?m *.plot *.log *.csv *.dSYM
Index: trunk/milena/sandbox/fabien/TODO
===================================================================
Index: trunk/milena/sandbox/fabien/magick/magick.cc
===================================================================
--- trunk/milena/sandbox/fabien/magick/magick.cc (revision 3535)
+++ trunk/milena/sandbox/fabien/magick/magick.cc (revision 3536)
@@ -1,15 +1,22 @@
#include <mln/core/image/image2d.hh>
-#include <mln/value/int_u8.hh>
+#include <mln/value/rgb8.hh>
#include "load.hh"
-int main()
+int main(int argc, char* argv[])
{
using namespace mln;
- using value::int_u8;
+ using value::rgb8;
- image2d<int_u8> lena;
+ if (argc != 2)
+ {
+ std::cout << "Usage: " << argv[0] << "
filename.ext" << std::endl;
+ return 1;
+ }
+
+ image2d<rgb8> lena;
+
+ io::magick::load(lena, argv[1]);
- //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");
+ return 0;
}
Index: trunk/milena/sandbox/fabien/magick/Makefile
===================================================================
Index: trunk/milena/sandbox/fabien/magick/load.hh
===================================================================
--- trunk/milena/sandbox/fabien/magick/load.hh (revision 3535)
+++ trunk/milena/sandbox/fabien/magick/load.hh (revision 3536)
@@ -37,6 +37,7 @@
*/
# include <mln/core/image/image2d.hh>
+# include <mln/value/rgb8.hh>
# include <Magick++.h>
@@ -59,58 +60,19 @@
void load(Image<I>& ima,
const std::string& filename);
- /*! Load a magick 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 magick 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::magick::load");
- image2d<V> ima;// = io::pnm::load<V>(MAGICK, filename);
- trace::exiting("mln::io::magick::load");
- return ima;
- }
-
- template <typename V>
- inline
- image3d<V> load(const std::string& filename)
- {
- trace::entering("mln::io::magick::load");
- image2d<V> ima;// = io::pnm::load<V>(MAGICK, filename);
- trace::exiting("mln::io::magick::load");
- return ima;
- }
-
template <typename I>
inline
- void load(Image<I>& ima,
+ void load(Image<I>& ima_,
const std::string& filename)
{
trace::entering("mln::io::magick::load");
+ I& ima = exact(ima_);
+
//std::ifstream file(filename.c_str());
//if (! file)
//{
@@ -118,24 +80,37 @@
// abort();
//}
- Magick::Image file(filename);
- //std::cout << "file attribute: " << file.attribute() <<
std::endl;
- std::cout << "width: " << file.columns() << std::endl;
- 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;
+ Magick::Image im_file(filename);
+ im_file.modifyImage();
+ im_file.type(Magick::TrueColorType);
+ int columns = im_file.columns();
+ int rows = im_file.rows();
+ /*std::cout << "width: " <<columns << std::endl;
+ std::cout << "height: " <<rows << std::endl;
+ std::cout << "depth: " <<im_file.depth() << std::endl;
+ std::cout << "comment: " <<im_file.comment() << std::endl;
+ std::cout << "format: " <<im_file.format() << std::endl;
+ std::cout << "filename: " <<im_file.imageInfo()->filename
<< std::endl;*/
+
+ const Magick::PixelPacket *pixel_cache = im_file.getConstPixels(0, 0, columns, rows);
+
+ algebra::vec<mln_site_(I)::dim, unsigned int> vmin;
+ algebra::vec<mln_site_(I)::dim, unsigned int> vmax;
+ vmin[0] = 0;
+ vmin[1] = 0;
+ vmax[0] = rows - 1;
+ vmax[1] = columns - 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());
+ for_all(p)
+ {
+ const Magick::PixelPacket *pixel = pixel_cache + (int) p.to_site().to_vec()[0] *
columns
+ + (int) p.to_site().to_vec()[1];
+ ima(p) = value::rgb8(pixel->red % 256, pixel->green % 256, pixel->blue %
256); // WARNING: Quantum = 16bits but rgb is 8bits
+ }
trace::exiting("mln::io::magick::load");
}