27 #ifndef MLN_BORDER_MIRROR_HH
28 # define MLN_BORDER_MIRROR_HH
40 # include <mln/core/image/image1d.hh>
41 # include <mln/core/image/image2d.hh>
42 # include <mln/core/image/image3d.hh>
44 # include <mln/core/concept/image.hh>
45 # include <mln/core/internal/fixme.hh>
46 # include <mln/core/internal/fixme.hh>
47 # include <mln/geom/min_row.hh>
48 # include <mln/geom/max_row.hh>
49 # include <mln/geom/min_col.hh>
50 # include <mln/geom/max_col.hh>
51 # include <mln/geom/ninds.hh>
53 # include <mln/opt/element.hh>
72 void mirror(
const Image<I>& ima);
75 # ifndef MLN_INCLUDE_ONLY
82 void mirror_(
const box1d&,
const I& ima_)
84 trace::entering(
"border::impl::mirror_");
85 I& ima =
const_cast<I&
>(ima_);
88 border =
static_cast<def::coord>(ima.border()),
101 opt::element(ima, border - 1 - i) = ima(
point1d(i));
103 for (; i < border; ++i)
104 opt::element(ima, border - 1 - i) = ima(
point1d(static_cast<def::coord>(min - 1)));
115 opt::element(ima, border + nbinds + i) = ima(
point1d(j));
120 opt::element(ima, border + nbinds + i) = ima(
point1d(j));
122 trace::exiting(
"border::impl::mirror_");
125 template <
typename I>
127 void mirror_(
const box2d&,
const I& ima_)
129 trace::entering(
"border::impl::mirror_");
130 I& ima =
const_cast<I&
>(ima_);
132 unsigned border = ima.border ();
135 unsigned real_nbcols = (nbcols + 1) + 2 * border;
136 unsigned start = real_nbcols * border + border;
140 for (
unsigned i = 0; i < border; ++i)
141 for (
unsigned j = 0; j < border; ++j)
142 opt::element(ima, i * ((nbcols + 1) + 2 * border) + j) =
143 opt::element(ima, s);
147 for (
unsigned i = 0; i < border; ++i)
148 for (
unsigned j = 1; j <= border; ++j)
149 opt::element(ima, i * ((nbcols + 1) + 2 * border) + (nbcols + border + j)) = opt::element(ima, s);
152 s = start + (nbrows * real_nbcols);
153 for (
unsigned i = 1; i <= border; ++i)
154 for (
unsigned j = 1; j <= border; ++j)
155 opt::element(ima, s - i + (j * (real_nbcols))) =
156 opt::element(ima, s);
159 s = start + (nbrows * real_nbcols) + nbcols;
160 for (
unsigned i = 1; i <= border; ++i)
161 for (
unsigned j = 1; j <= border; ++j)
162 opt::element(ima, s + i + (j * real_nbcols)) =
163 opt::element(ima, s);
167 for (
unsigned i = 0; i <= nbcols; ++i)
168 for (
unsigned j = 1; j <= border; ++j)
169 opt::element(ima, s + i - (j * real_nbcols)) =
170 opt::element(ima, s + i + ((j - 1)* real_nbcols));
174 for (
unsigned i = 0; i <= nbrows; ++i)
175 for (
unsigned j = 1; j <= border; ++j)
176 opt::element(ima, s + (i * real_nbcols) - j) =
177 opt::element(ima, s + (i * real_nbcols) + (j - 1));
181 for (
unsigned i = 0; i <= nbrows; ++i)
182 for (
unsigned j = 1; j <= border; ++j)
183 opt::element(ima, s + (i * real_nbcols + nbcols) + j) =
184 opt::element(ima, s + (i * real_nbcols + nbcols) - (j - 1));
187 s = start + (nbrows * real_nbcols);
188 for (
unsigned i = 0; i <= nbcols; ++i)
189 for (
unsigned j = 1; j <= border; ++j)
190 opt::element(ima, s + i + (j * real_nbcols)) =
191 opt::element(ima, s + i - ((j - 1)* real_nbcols));
193 trace::exiting(
"border::impl::mirror_");
196 template <
typename I>
198 void mirror_(
const box3d&,
const I& ima)
200 trace::warning(
"border::mirror for 3D image is not implemented,"
201 " so image borders have not been mirrored!");
210 template <
typename I>
214 trace::entering(
"border::mirror");
216 const I& ima = exact(ima_);
218 mln_precondition(ima.is_valid());
219 mlc_is(mln_trait_image_speed(I), trait::image::speed::fastest)::check();
221 typedef mln_psite(I) P;
226 impl::mirror_(ima.bbox(), ima);
228 trace::exiting(
"border::mirror");
231 # endif // ! MLN_INCLUDE_ONLY
238 #endif // ! MLN_BORDER_MIRROR_HH