URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-03-13 Fabien Freling <fabien.freling(a)lrde.epita.fr>
Find threshold value thanks to watershed.
* fabien/bin/dumpi12_to_pgm.cc: New tool.
* fabien/igr/Makefile: Update.
* fabien/igr/check.sh: Update.
* fabien/igr/graph.cc: Update.
* fabien/igr/med.cc: Find median region value.
* fabien/igr/thres.cc: Threshold image.
---
TODO | 8 +++-
bin/dumpi12_to_pgm.cc | 55 +++++++++++++++++++++++++++++++
igr/Makefile | 6 +++
igr/check.sh | 37 +++++++++++++--------
igr/graph.cc | 13 ++++++-
igr/med.cc | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++
igr/thres.cc | 67 ++++++++++++++++++++++++++++++++++++++
7 files changed, 256 insertions(+), 17 deletions(-)
Index: trunk/milena/sandbox/fabien/igr/graph.cc
===================================================================
--- trunk/milena/sandbox/fabien/igr/graph.cc (revision 3525)
+++ trunk/milena/sandbox/fabien/igr/graph.cc (revision 3526)
@@ -11,11 +11,13 @@
#include <mln/io/dump/all.hh>
#include <mln/io/dicom/load.hh>
#include <mln/io/pgm/save.hh>
+#include <mln/io/ppm/save.hh>
#include <mln/value/int_u8.hh>
#include <mln/value/int_u12.hh>
#include <mln/value/label_16.hh>
#include <mln/value/label_32.hh>
+#include <mln/value/rgb8.hh>
#include <mln/morpho/watershed/flooding.hh>
@@ -53,6 +55,8 @@
#include <mln/extract/all.hh>
#include <mln/make/region_adjacency_graph.hh>
+#include <mln/debug/colorize.hh>
+
@@ -241,6 +245,7 @@
using value::int_u12;
using value::label_16;
using value::label_32;
+ using value::rgb8;
typedef label_32 L;
if (argc != 6)
@@ -315,8 +320,12 @@
mln_VAR(wsd2_, morpho::elementary::dilation(extend(wsd2 | (pw::value(wsd2) == 0u),
wsd2), c8()));
data::fill((wsd2 | (pw::value(wsd2) == 0u)).rw(), wsd2_);
- io::pgm::save(level::stretch(int_u8(), labeling::mean_values(dcm, wshed, nbasins)),
"wsd_original.pgm");
- io::pgm::save(level::stretch(int_u8(), labeling::mean_values(dcm, wsd2, nbasins2)),
"wsd_mean_colors.pgm");
+ mln_VAR(original, level::stretch(int_u8(), labeling::mean_values(dcm, wshed,
nbasins)));
+ mln_VAR(mean, level::stretch(int_u8(), labeling::mean_values(dcm, wsd2, nbasins2)));
+ io::pgm::save(original, "wsd_original.pgm");
+ io::pgm::save(mean, "wsd_mean_colors.pgm");
+ io::ppm::save(debug::colorize(rgb8(), wshed, nbasins),
"wsd_colorize_01.ppm");
+ io::ppm::save(debug::colorize(rgb8(), wsd2, nbasins2),
"wsd_colorize_02.ppm");
}
else
{
Index: trunk/milena/sandbox/fabien/igr/check.sh
===================================================================
--- trunk/milena/sandbox/fabien/igr/check.sh (revision 3525)
+++ trunk/milena/sandbox/fabien/igr/check.sh (revision 3526)
@@ -4,22 +4,33 @@
{
echo "Processing $3..."
dist_max=10
+ input=$1
+ dim=$2
- ./grad $1 $2
- for lambda_closing in 10 50 100 500 1000 5000 10000 50000; do
+ ./grad $input $dim
+ for lambda_closing in 50 100 500 1000 5000 10000 50000; do
echo " for lambda_closing = ${lambda_closing}";
- ./clo_vol grad.dump $2 ${lambda_closing}
- nbasins=`./wst clo_vol.dump $2`
- ../bin/dumpl32_to_colorize wst.dump $2 $nbasins
results/colorize_${3}_${lambda_closing}.ppm
+ ./clo_vol grad.dump $dim ${lambda_closing}
+ nbasins=`./wst clo_vol.dump $dim`
+ ../bin/dumpl32_to_colorize wst.dump $dim $nbasins
results/colorize_${3}_${lambda_closing}.ppm
+ median=`./med wst.dump $dim $input $nbasins`
+ ../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
- if [ ${lambda_closing} -eq 100 ]; then
- for lambda_dist in 10 50 100; do
- nbasins_after=`./graph wst.dump $2 $1 $lambda_dist $nbasins`
- mv wsd_original.pgm results/graph_${3}_${lambda_closing}_${lambda_dist}_01.pgm
- mv wsd_mean_colors.pgm results/graph_${3}_${lambda_closing}_${lambda_dist}_02.pgm
- echo "nbasins was" $nbasins "and now is" $nbasins_after "( diff
=" $(($nbasins - $nbasins_after)) ")"
- done
- fi
+#if [ $2 -eq 2 ]; then
+# if [ ${lambda_closing} -eq 100 ]; then
+# for lambda_dist in 50 100 120 130 140 150; do
+# nbasins_after=`./graph wst.dump $2 $1 $lambda_dist $nbasins`
+# mv wsd_original.pgm results/graph_${3}_${lambda_closing}_${lambda_dist}_01.pgm
+# mv wsd_mean_colors.pgm results/graph_${3}_${lambda_closing}_${lambda_dist}_02.pgm
+# mv wsd_colorize_01.ppm results/graph_${3}_${lambda_closing}_${lambda_dist}_03.ppm
+# mv wsd_colorize_02.ppm results/graph_${3}_${lambda_closing}_${lambda_dist}_04.ppm
+# diff=$(($nbasins - $nbasins_after))
+# echo " dist = $lambda_dist | $nbasins -> $nbasins_after (diff = $diff )
$(($diff * 100 / $nbasins))%"
+# done
+# fi
+# fi
done
# rm *.dump
}
Index: trunk/milena/sandbox/fabien/igr/med.cc
===================================================================
--- trunk/milena/sandbox/fabien/igr/med.cc (revision 0)
+++ trunk/milena/sandbox/fabien/igr/med.cc (revision 3526)
@@ -0,0 +1,87 @@
+#include <iostream>
+#include <mln/core/image/image2d.hh>
+#include <mln/core/image/image3d.hh>
+#include <mln/core/image/image_if.hh>
+
+#include <mln/core/alias/neighb2d.hh>
+#include <mln/core/alias/window2d.hh>
+#include <mln/core/alias/neighb3d.hh>
+#include <mln/core/alias/window3d.hh>
+
+#include <mln/io/dump/all.hh>
+#include <mln/io/dicom/load.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/value/int_u12.hh>
+#include <mln/value/label_16.hh>
+#include <mln/value/label_32.hh>
+
+#include <mln/core/var.hh>
+#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/labeling/mean_values.hh>
+#include <mln/level/compute.hh>
+#include <mln/pw/all.hh>
+#include <mln/util/array.hh>
+
+
+
+///////////////////
+// //
+// Main Function //
+// //
+///////////////////
+
+
+int main(int argc, char *argv[])
+{
+ using namespace mln;
+ using value::int_u8;
+ using value::int_u12;
+ using value::label_16;
+ using value::label_32;
+ typedef label_32 L;
+
+ if (argc != 5)
+ {
+ std::cout << "Usage: " << argv[0] << "
<ima.dump> <dimensions> <ima.dcm> <nbasins>"
+ << std::endl;
+ return 1;
+ }
+
+ unsigned dim = atoi(argv[2]);
+ L nbasins = atoi(argv[4]);
+ if (dim != 2 && dim != 3)
+ {
+ std::cout << "<dimensions> invalid" << std::endl;
+ return 1;
+ }
+
+ if (dim == 2)
+ {
+ image2d<L> labels;
+ io::dump::load(labels, argv[1]);
+ image2d<int_u12> dcm;
+ io::dicom::load(dcm, argv[3]);
+
+ mln_VAR(wst_dilate, morpho::elementary::dilation(extend(labels | (pw::value(labels)
== 0u), labels), c8()));
+ 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
+
+ io::dump::save(wst_mean, "med.dump");
+ std::cout << median << std::endl;
+ }
+ else
+ {
+ // FIXME
+ }
+
+ return 0;
+}
Index: trunk/milena/sandbox/fabien/igr/thres.cc
===================================================================
--- trunk/milena/sandbox/fabien/igr/thres.cc (revision 0)
+++ trunk/milena/sandbox/fabien/igr/thres.cc (revision 3526)
@@ -0,0 +1,67 @@
+#include <iostream>
+#include <mln/core/image/image2d.hh>
+#include <mln/core/image/image3d.hh>
+#include <mln/core/image/image_if.hh>
+
+#include <mln/core/alias/neighb2d.hh>
+#include <mln/core/alias/window2d.hh>
+#include <mln/core/alias/neighb3d.hh>
+#include <mln/core/alias/window3d.hh>
+
+#include <mln/io/dump/all.hh>
+#include <mln/io/pbm/save.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/value/int_u12.hh>
+#include <mln/value/label_16.hh>
+#include <mln/value/label_32.hh>
+
+#include <mln/binarization/threshold.hh>
+
+
+
+///////////////////
+// //
+// Main Function //
+// //
+///////////////////
+
+
+int main(int argc, char *argv[])
+{
+ using namespace mln;
+ using value::int_u8;
+ using value::int_u12;
+ using value::label_16;
+ using value::label_32;
+ typedef label_32 L;
+
+ if (argc != 4)
+ {
+ std::cout << "Usage: " << argv[0] << "
<ima.dump> <dimensions> <threshold>"
+ << std::endl;
+ return 1;
+ }
+
+ unsigned dim = atoi(argv[2]);
+ unsigned threshold = atoi(argv[3]);
+ if (dim != 2 && dim != 3)
+ {
+ std::cout << "<dimensions> invalid" << std::endl;
+ return 1;
+ }
+
+ if (dim == 2)
+ {
+ image2d<int_u12> input;
+ io::dump::load(input, argv[1]);
+ image2d<bool> bin_result = binarization::threshold(input, threshold);
+ io::pbm::save(bin_result, "result.pbm");
+ }
+ else
+ {
+ // FIXME
+ }
+
+ return 0;
+}
Index: trunk/milena/sandbox/fabien/igr/Makefile
===================================================================
--- trunk/milena/sandbox/fabien/igr/Makefile (revision 3525)
+++ trunk/milena/sandbox/fabien/igr/Makefile (revision 3526)
@@ -42,5 +42,11 @@
graph: graph.cc
g++ -I../../../ ${DICOM_INC} ${DICOM_LIBS} ${CXXFLAGS} $^ -o graph
+med: med.cc
+ g++ -I../../../ ${DICOM_INC} ${DICOM_LIBS} ${CXXFLAGS} $^ -o med
+
+thres: thres.cc
+ g++ -I../../../ ${CXXFLAGS} $^ -o thres
+
clean:
rm -rf *.dump *.p?m *.plot *.log *.csv
Index: trunk/milena/sandbox/fabien/TODO
===================================================================
--- trunk/milena/sandbox/fabien/TODO (revision 3525)
+++ trunk/milena/sandbox/fabien/TODO (revision 3526)
@@ -28,5 +28,9 @@
[X] Batch process watershed with 2D, 3D and any combination of parameters
[X] Cut into small tools
[X] Test 3D workflow on 2D images
-[ ] Create colorized colors for graph
-[ ] Diff with %
+[X] Create colorized colors for graph
+[X] Diff with %
+[ ] Find biggest dark regions (threshold value or median accu - median / 2 - )
+ [ ] Learn regions value
+ [ ] Threshold
+[ ] Profile for performance
Index: trunk/milena/sandbox/fabien/bin/dumpi12_to_pgm.cc
===================================================================
--- trunk/milena/sandbox/fabien/bin/dumpi12_to_pgm.cc (revision 0)
+++ trunk/milena/sandbox/fabien/bin/dumpi12_to_pgm.cc (revision 3526)
@@ -0,0 +1,55 @@
+#include <mln/core/image/image2d.hh>
+#include <mln/make/image3d.hh>
+#include <mln/debug/slices_2d.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/value/int_u12.hh>
+#include <mln/value/label_32.hh>
+
+#include <mln/io/dump/load.hh>
+#include <mln/io/pgm/save.hh>
+
+#include <mln/level/stretch.hh>
+
+
+int usage(char* argv[])
+{
+ std::cerr << "usage: " << argv[0] << " input.dump dim
output.pgm" << std::endl;
+ return 1;
+}
+
+
+
+int main(int argc, char* argv[])
+{
+ using namespace mln;
+ using value::int_u8;
+ using value::int_u12;
+ using value::label_32;
+ using value::rgb8;
+
+ if (argc != 4)
+ return usage(argv);
+
+ unsigned dim = atoi(argv[2]);
+ unsigned nbasins = atoi(argv[3]);
+ if (dim != 2 && dim != 3)
+ {
+ std::cout << "<dimensions> invalid" << std::endl;
+ return 1;
+ }
+
+ if (dim == 2)
+ {
+ image2d<int_u12> ima2d;
+ io::dump::load(ima2d, argv[1]);
+ image2d<int_u8> ima_pgm = level::stretch(int_u8(), ima2d);
+ io::pgm::save(ima_pgm, argv[3]);
+ }
+ else
+ {
+ // FIXME
+ }
+
+ return 0;
+}