5 #include <boost/lexical_cast.hpp>
7 #include <mln/border/duplicate.hh>
8 #include <mln/io/ppm/save.hh>
9 #include <mln/level/fill.hh>
14 using namespace mln::value
;
18 add_bias (image2d
<float> nrg
, const char* path
)
20 image2d
<rgb8
> tmp
= load (path
);
21 assert (tmp
.domain () == nrg
.domain ());
22 image2d
<rgb8
>::fwd_piter
p (tmp
.domain ());
25 nrg (p
) += tmp (p
).red () - tmp (p
).green ();
28 /// \file Find a vertical seam in an image.
30 int main (int argc
, char** argv
)
32 if (argc
!= 5 && argc
!= 6)
34 std::cerr
<< "usage: " << *argv
35 << " N in.ppm carved.ppm seams.ppm [bias.ppm]\n"
36 "where N is an integer > 0: the number of seams to carve.\n";
43 nseam
= boost::lexical_cast
<unsigned> (argv
[1]);
45 catch (const boost::bad_lexical_cast
&)
47 std::cerr
<< "invalid 1st argument" << std::endl
;
51 std::cerr
<< "initializing ... ";
52 image2d
<rgb8
> img
= load (argv
[2]);
53 border::duplicate (img
);
54 image2d
<float> nrg
= get_nrg (img
);
56 add_bias (nrg
, argv
[5]);
57 std::stack
<std::vector
<unsigned> > seams
;
59 for (unsigned i
= 0; i
< nseam
; ++i
)
61 std::cerr
<< (i
+ 1) << "..";
62 seams
.push (find_vertical_seam (nrg
));
63 img
= carve_vertical_seam (img
, seams
.top ());
64 nrg
= carve_vertical_seam (nrg
, seams
.top ());
65 adjust_vertical_nrg (img
, nrg
, seams
.top ());
66 border::duplicate (img
);
67 image2d
<float> new_nrg
= get_nrg (img
);
70 io::ppm::save (img
, argv
[3]);
71 for (unsigned i
= 0; i
< nseam
; ++i
)
73 img
= uncarve_vertical_seam (img
, seams
.top ());
77 io::ppm::save (img
, argv
[4]);
78 std::cerr
<< std::endl
;