https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena/sandbox
Index: ChangeLog
from Alexandre Abraham <abraham(a)lrde.epita.fr>
It now compiles.
* markov/markov.cc: add name modification.
* markov/markov.hh: many little fixes.
markov.cc | 7 ++++++-
markov.hh | 49 +++++++++++++++++++++++++++++++------------------
2 files changed, 37 insertions(+), 19 deletions(-)
Index: markov/markov.cc
--- markov/markov.cc (revision 2877)
+++ markov/markov.cc (working copy)
@@ -26,6 +26,7 @@
// Public License.
#include <mln/core/image/image2d.hh>
+#include <mln/core/alias/neighb2d.hh>
#include <mln/io/pgm/load.hh>
#include <mln/io/pbm/save.hh>
@@ -47,6 +48,10 @@
image2d<int_u8> ima;
io::pgm::load(ima, argv[1]);
+
int temperature = atoi(argv[2]);
- io::pgm::save(markov(ima, temperature), name.append("_markoved.pbm"));
+
+ std::string name(argv[1]);
+ name.erase(name.length() - 4);
+ io::pbm::save(markov(ima, c4(), temperature), name.append("_markoved.pbm"));
}
Index: markov/markov.hh
--- markov/markov.hh (revision 2877)
+++ markov/markov.hh (working copy)
@@ -2,10 +2,13 @@
# define MARKOV_HH_
# include <cmath>
+# include <random.hh>
+# include <T_gen.hh>
namespace mln
{
+ /* I think we don't need it anymore...
inline
const neighb2d& neighb_h1()
{
@@ -19,49 +22,59 @@
}
return it;
}
+ */
- double compute_energy(const Image2d<int_u8>& ima, bool xi, const point2d&
p)
+ template <typename I, typename N>
+ double compute_energy(const I& ima, const N& nbh, bool xi, const
mln_piter(I)& p)
{
// Compute u(x,y)
double u;
- if (v)
- u = ima(p) / 255;
+ if (xi)
+ u = (double) ima(p) / mln_max(mln_value(I));
else
- u = 1 - ima(p) / 255;
+ u = (double) (1 - ima(p)) / mln_max(mln_value(I));
// u(x) is cst donc osef
// u voisinage
+
+ mln_niter(N) n(nbh, p);
+ for_all(n)
+ // treat each point here ;), no need to make weird neighborhoods
+ // make sth with |ima(p) - ima(n)|
+ abs(ima(p) - ima(n));
}
- template <typename I, typename G, typename R> // I == int_u8
- markov(const Image<I>& ima_, unsigned start_temp)
+ template <typename I, typename N> // I == int_u8
+ mln_ch_value(I, bool) markov(const Image<I>& ima_, const
Neighborhood<N> nbh_, unsigned start_temp)
{
- exact(I) &ima = ima_;
+ const I &ima = exact(ima_);
+ const N &nbh = exact(nbh_);
- double espilon = 0.001;
+ double epsilon = 0.001;
mln_ch_value(I, bool) out(ima.domain()); // FIXME: generalize, we might not do a
binarisation
- G temp(start_temp);
+ // G temp(start_temp);
+ temperature_generator temp(start_temp, 0.99);
- R v_random(0, 1);
- R p_random(0., 1.);
+ Random<bool> v_random(0, 1); // mettre max et min ?
+ Random<double> p_random(0., 1.); // idem
- init(ima, out);
+ // init(ima, out); ca empeche de compiloter
- while (temp.value() < epsilon)
+ while (temp < epsilon)
{
- mln_piter p(ima.domain());
+ mln_piter(I) p(ima.domain());
for_all(p)
{
bool v = v_random.get();
- u = compute_energy(ima, out(p), p);
- up = compute_energy(ima, v, p);
+ double u = compute_energy(ima, nbh, out(p), p);
+ double up = compute_energy(ima, nbh, v, p);
- d_u = abs(up - u);
+ double d_u = abs(up - u);
- proba = ...;
+ double proba = 0.5; // FIXME
if (d_u < 0 or (p_random.get() > proba))
out(p) = v;