URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-06-02 Fabien Freling <fabien.freling(a)lrde.epita.fr>
Add mean images output.
* fabien/igr/check_dist.sh: New script for testing dist_edges.
* fabien/igr/check_edges.sh: New script for testing
distance and watershed computation.
* fabien/igr/dist_edges.cc: Small update.
* fabien/igr/mean_median_label.cc: Output images.
* fabien/igr/tmax.sh: New script for testing.
* fabien/igr/wst_edges.cc: Small update.
---
check_dist.sh | 19 +++++++++++++++++
check_edges.sh | 43 ++++++++++++++++++++++++++++++++++++++
dist_edges.cc | 8 +++----
mean_median_label.cc | 57 +++++++++++++++++++++++++++++++--------------------
tmax.sh | 23 ++++++++++++++++++++
wst_edges.cc | 3 +-
6 files changed, 126 insertions(+), 27 deletions(-)
Index: trunk/milena/sandbox/fabien/igr/mean_median_label.cc
===================================================================
--- trunk/milena/sandbox/fabien/igr/mean_median_label.cc (revision 3946)
+++ trunk/milena/sandbox/fabien/igr/mean_median_label.cc (revision 3947)
@@ -86,6 +86,18 @@
filename);
}
+ template <typename I>
+ void io_save_edges_float(const I& input,
+ value::int_u8 bg,
+ const std::string& filename)
+ {
+ mln_ch_value(I, value::int_u8) output = data::stretch(int_u8(), input);
+ io::pgm::save(world::inter_pixel::display_edge(output.unmorph_(),
+ bg,
+ 3),
+ filename);
+ }
+
} // end of namespace mln
@@ -96,29 +108,34 @@
int usage(const char* bin)
{
- std::cout << "Usage: " << bin << " input.dump
wst.dump" << std::endl;
+ std::cout << "Usage: " << bin << " dist.dump wst.dump
nbasins" << std::endl;
return 1;
}
int main(int argc, char* argv[])
{
- if (argc != 3)
+ if (argc != 4)
return usage(argv[0]);
+ label_16 nbasins = atoi(argv[3]);
// Initialization.
typedef float input_type;
- image2d<input_type> input;
- io::dump::load(input, argv[1]);
- image2d<label_16> wst;
- io::dump::load(input`, argv[1]);
+ image2d<int_u12> dist_input;
+ io::dump::load(dist_input, argv[1]);
+ mln_VAR(dist, dist_input | world::inter_pixel::is_separator());
+
+ image2d<label_16> wst_input;
+ io::dump::load(wst_input, argv[2]);
+ mln_VAR(wst, wst_input | world::inter_pixel::is_separator());
+
// Mean distance.
- accu::mean<E_TYPE> accu_mean;
- util::array<float> means = labeling::compute(accu_mean, e, wst, nbasins);
+ accu::mean<input_type> accu_mean;
+ util::array<float> means = labeling::compute(accu_mean, dist, wst, nbasins);
// Display.
{
@@ -127,13 +144,12 @@
initialize(ima_means, wst);
data::paste(wst, ima_means);
for (unsigned i = 1; i < means.nelements(); ++i)
- data::fill((ima_means | pw::value(ima_means) == pw::cst(i)).rw(), means[i]);
- mln_VAR(display_means, world::inter_pixel::display_edge(ima_means.unmorph_(), 0.0,
3));
- io::pgm::save(level::stretch(int_u8(), display_means), "means.pgm");
+ data::fill((ima_means | pw::value(ima_means) == pw::cst(i)).rw(), (unsigned)
means[i]);
+ io_save_edges_float(ima_means, 0u, "means.pgm");
}
- typedef accu::mean<int_u12,float,int_u12> A;
- util::array<int_u12> m = labeling::compute(A(), d, wst, nbasins);
+ typedef accu::mean<input_type> A;
+ util::array<input_type> m = labeling::compute(A(), dist, wst, nbasins);
{
util::array<int_u8> m_(nbasins.next());
@@ -141,14 +157,12 @@
for (unsigned l = 1; l <= nbasins; ++l)
{
m_[l] = m[l] / 16;
- if (m_[l] < 2) m_[l] == 2;
+ if (m_[l] < 2u)
+ m_[l] = 2u;
// basin <=> 2..255
}
- mln_VAR(d_m, level::transform(wst, m_));
- mln_VAR(out, world::inter_pixel::display_edge(d_m.unmorph_(),
- 0, // background <=> 0
- 3));
- io::pgm::save(out, "dist_mean.pgm");
+ mln_VAR(d_m, data::transform(wst, m_));
+ io_save_edges_float(d_m, 0u, "dist_mean.pgm");
}
@@ -157,7 +171,7 @@
util::array<accu::stat::deviation<float> > arr_dev;
for (unsigned i = 0; i < means.nelements(); ++i)
arr_dev.append(accu::stat::deviation<float> (means[i]));
- util::array<float> deviations = labeling::compute(arr_dev, e, wst, nbasins);
+ util::array<float> deviations = labeling::compute(arr_dev, dist, wst, nbasins);
// Display.
{
@@ -167,8 +181,7 @@
data::paste(wst, ima_dev);
for (unsigned i = 1; i < deviations.nelements(); ++i)
data::fill((ima_dev | pw::value(ima_dev) == pw::cst(i)).rw(), deviations[i]);
- mln_VAR(display_dev, world::inter_pixel::display_edge(ima_dev.unmorph_(), 0.0, 3));
- io::pgm::save(level::stretch(int_u8(), display_dev), "dev.pgm");
+ io_save_edges_float(ima_dev, 0u, "dev.pgm");
}
Index: trunk/milena/sandbox/fabien/igr/tmax.sh
===================================================================
--- trunk/milena/sandbox/fabien/igr/tmax.sh (revision 0)
+++ trunk/milena/sandbox/fabien/igr/tmax.sh (revision 3947)
@@ -0,0 +1,23 @@
+#!/bin/zsh
+
+
+process_file ()
+{
+ echo "Processing $1..." | cowsay
+ input=$1
+ dim=$2
+
+ ./crop $input 0 50 90 149 230 170 crop.dump
+ ./norm crop.dump norm.dump
+ ./time_max_norm norm.dump
+
+ convert tmax_max.pgm tmax_max.png
+ convert tmax_smooth_max.pgm tmax_smooth_max.png
+ convert tmax_time.pgm tmax_time.png
+ convert tmax_smooth_time.pgm tmax_smooth_time.png
+ rm tmax_*.pgm
+}
+
+# 3D (2D + t) images only
+make crop norm time_max_norm
+process_file "/Users/HiSoKa/Work/IGR/souris18/irm/IM_0052.dcm" 3 52
Property changes on: trunk/milena/sandbox/fabien/igr/tmax.sh
___________________________________________________________________
Name: svn:executable
+ *
Index: trunk/milena/sandbox/fabien/igr/check_edges.sh
===================================================================
--- trunk/milena/sandbox/fabien/igr/check_edges.sh (revision 0)
+++ trunk/milena/sandbox/fabien/igr/check_edges.sh (revision 3947)
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+
+process ()
+{
+ ./dist_edges $1 -1 $2 dist${2}.dump
+ if [ $? -gt 0 ]; then
+ echo "error: dist_edges failed"
+ exit
+ fi
+ nbasins=`./wst_edges dist${2}.dump $3`
+ if [ $? -gt 0 ]; then
+ echo "error: wst_edges failed"
+ exit
+ fi
+ ./mean_median_label dist${2}.dump watershed.dump $nbasins
+ if [ $? -gt 0 ]; then
+ echo "error: mean_median_label failed"
+ echo "nbasins: $nbasins"
+ exit
+ fi
+
+ convert dist.pgm dist${2}.png
+ convert watershed.ppm watershed${2}.png
+ convert means.pgm means${2}.png
+ convert dist_mean.pgm dist_mean${2}.png
+ convert dev.pgm dev${2}.png
+
+ cp watershed.dump watershed${2}.dump
+
+ # Cleanup.
+ rm *.pgm *.ppm
+}
+
+batch_process ()
+{
+ process $1 1 $2
+ process $1 2 $2
+ process $1 3 $2
+ process $1 4 $2
+}
+
+batch_process $1 $2
Property changes on: trunk/milena/sandbox/fabien/igr/check_edges.sh
___________________________________________________________________
Name: svn:executable
+ *
Index: trunk/milena/sandbox/fabien/igr/wst_edges.cc
===================================================================
--- trunk/milena/sandbox/fabien/igr/wst_edges.cc (revision 3946)
+++ trunk/milena/sandbox/fabien/igr/wst_edges.cc (revision 3947)
@@ -124,7 +124,8 @@
L nbasins;
mln_VAR(wst, morpho::watershed::flooding(d_clo, world::inter_pixel::e2e(), nbasins));
- std::cout << "nbasins: " << nbasins << std::endl;
+
+ std::cout << nbasins << std::endl;
mln_VAR(w_all, wst.unmorph_());
Index: trunk/milena/sandbox/fabien/igr/check_dist.sh
===================================================================
--- trunk/milena/sandbox/fabien/igr/check_dist.sh (revision 0)
+++ trunk/milena/sandbox/fabien/igr/check_dist.sh (revision 3947)
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+
+process ()
+{
+ ./dist_edges $1 -1 $2 dist${2}.dump
+ convert dist.pgm dist${2}.png
+ rm dist*.pgm
+}
+
+batch_process ()
+{
+ process $1 1
+ process $1 2
+ process $1 3
+ process $1 4
+}
+
+batch_process $1 $2
Property changes on: trunk/milena/sandbox/fabien/igr/check_dist.sh
___________________________________________________________________
Name: svn:executable
+ *
Index: trunk/milena/sandbox/fabien/igr/dist_edges.cc
===================================================================
--- trunk/milena/sandbox/fabien/igr/dist_edges.cc (revision 3946)
+++ trunk/milena/sandbox/fabien/igr/dist_edges.cc (revision 3947)
@@ -95,7 +95,7 @@
res /= std::max(sum_v1, sum_v2);
res = 1 - res;
- res = res * 4095;
+ res = (res * 4095) + 0.49;
return (int) res;
}
@@ -123,7 +123,7 @@
res = res / v1.nelements();
res = 1 - res;
- res = res * 4095;
+ res = (res * 4095) + 0.49;
return (int) res;
}
@@ -152,7 +152,7 @@
res = min / max;
res = 1 - res;
- res = res * 4095;
+ res = (res * 4095) + 0.49;
return (int) res;
}
@@ -181,7 +181,7 @@
res = res / v1.nelements();
//res = 1 - res;
- res = res * 4095;
+ res = (res * 4095) + 0.49;
return (int) res;
}