Commit 41c82626 authored by Guillaume Lazzara's avatar Guillaume Lazzara
Browse files

Add crop tools.

	* preprocessing/crop.hh,
	* preprocessing/crop_without_localization.hh: new routines.

	* tests/preprocessing/Makefile.am,
	* tests/preprocessing/crop.cc,
	* tests/preprocessing/crop_without_localization.cc: Associated
	tests.
parent 8c069f07
2010-05-25 Guillaume Lazzara <z@lrde.epita.fr>
Add crop tools.
* preprocessing/crop.hh,
* preprocessing/crop_without_localization.hh: new routines.
* tests/preprocessing/Makefile.am,
* tests/preprocessing/crop.cc,
* tests/preprocessing/crop_without_localization.cc: Associated
tests.
2010-05-25 Guillaume Lazzara <z@lrde.epita.fr>
Small fixes.
......
// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
// Olena is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, version 2 of the License.
//
// Olena is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Olena. If not, see <http://www.gnu.org/licenses/>.
//
// As a special exception, you may use this file as part of a free
// software project without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to produce
// an executable, this file does not by itself cause the resulting
// executable to be covered by the GNU General Public License. This
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
#ifndef SCRIBO_PREPROCESSING_CROP_HH
# define SCRIBO_PREPROCESSING_CROP_HH
# include <mln/core/concept/image.hh>
# include <mln/data/paste.hh>
/// \file
///
/// \brief Crop an image preserving the localization.
namespace scribo
{
namespace preprocessing
{
using namespace mln;
/*! \brief crop an image preserving the localization.
\param[in] input An image.
\param[in] domain A region of interest.
\return An image defined on the domain \p domain with the
corresponding data copied from \p input.
*/
template <typename I>
mln_concrete(I)
crop(const Image<I>& input, const mln_box(I)& domain);
# ifndef MLN_INCLUDE_ONLY
template <typename I>
mln_concrete(I)
crop(const Image<I>& input, const mln_box(I)& domain)
{
trace::entering("scribo::preprocessing::crop");
mln_assertion(exact(input).is_valid());
mln_concrete(I) output(domain);
data::paste(input | domain, output);
trace::exiting("scribo::preprocessing::crop");
return output;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace scribo::preprocessing
} // end of namespace scribo
#endif // ! SCRIBO_PREPROCESSING_CROP_HH
// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
// Olena is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, version 2 of the License.
//
// Olena is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Olena. If not, see <http://www.gnu.org/licenses/>.
//
// As a special exception, you may use this file as part of a free
// software project without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to produce
// an executable, this file does not by itself cause the resulting
// executable to be covered by the GNU General Public License. This
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
#ifndef SCRIBO_PREPROCESSING_CROP_WITHOUT_LOCALIZATION_HH
# define SCRIBO_PREPROCESSING_CROP_WITHOUT_LOCALIZATION_HH
# include <mln/core/concept/image.hh>
# include <mln/data/paste_without_localization.hh>
/// \file
///
/// \brief Crop an image without preserving the localization.
namespace scribo
{
namespace preprocessing
{
using namespace mln;
/*! \brief crop an image without preserving the localization.
\param[in] input An image.
\param[in] domain A region of interest.
\return An image defined on a domain starting from the origin
(literal::origin) and having the same size as \p domain. Its
data corresponds to the data copied from \p input in the domain
\p domain.
*/
template <typename I>
mln_concrete(I)
crop_without_localization(const Image<I>& input, const mln_box(I)& domain);
# ifndef MLN_INCLUDE_ONLY
template <typename I>
mln_concrete(I)
crop_without_localization(const Image<I>& input, const mln_box(I)& domain)
{
trace::entering("scribo::preprocessing::crop_without_localization");
mln_assertion(exact(input).is_valid());
typedef mln_site(I) P;
P pmin, pmax;
for (unsigned i = 0; i < P::dim; ++i)
{
pmin[i] = 0;
pmax[i] = domain.pmax()[i] - domain.pmin()[i];
}
mln_box(I) b(pmin, pmax);
mln_concrete(I) output(b);
data::paste_without_localization(input | domain, output);
trace::exiting("scribo::preprocessing::crop_without_localization");
return output;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace scribo::preprocessing
} // end of namespace scribo
#endif // ! SCRIBO_PREPROCESSING_CROP_WITHOUT_LOCALIZATION_HH
......@@ -20,10 +20,14 @@
include $(top_srcdir)/scribo/tests/tests.mk
check_PROGRAMS = \
unskew \
rotate_90
crop \
crop_without_localization \
rotate_90 \
unskew
unskew_SOURCES = unskew.cc
crop_SOURCES = crop.cc
crop_without_localization_SOURCES = crop_without_localization.cc
rotate_90_SOURCES = rotate_90.cc
unskew_SOURCES = unskew.cc
TESTS = $(check_PROGRAMS)
// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
// Olena is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, version 2 of the License.
//
// Olena is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Olena. If not, see <http://www.gnu.org/licenses/>.
//
// As a special exception, you may use this file as part of a free
// software project without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to produce
// an executable, this file does not by itself cause the resulting
// executable to be covered by the GNU General Public License. This
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
#include <mln/core/image/image2d.hh>
#include <mln/data/compare.hh>
#include <scribo/preprocessing/crop.hh>
#include <scribo/tests/data.hh>
int main(int argc, char *argv[])
{
(void) argc;
(void) argv;
using namespace mln;
// Ref
image2d<bool> ref(make::box2d(2,2, 8,8));
data::fill(ref, 0);
data::fill((ref | make::box2d(2,2, 2,3)).rw(), true);
// Test
image2d<bool> ima(10, 10);
data::fill(ima, 0);
data::fill((ima | box2d(3, 4)).rw(), true);
image2d<bool> test = scribo::preprocessing::crop(ima, make::box2d(2,2, 8,8));
mln_assertion(ref == test);
}
// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
// Olena is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, version 2 of the License.
//
// Olena is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Olena. If not, see <http://www.gnu.org/licenses/>.
//
// As a special exception, you may use this file as part of a free
// software project without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to produce
// an executable, this file does not by itself cause the resulting
// executable to be covered by the GNU General Public License. This
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
#include <mln/core/image/image2d.hh>
#include <mln/data/compare.hh>
#include <scribo/preprocessing/crop_without_localization.hh>
#include <mln/debug/println.hh>
#include <scribo/tests/data.hh>
int main(int argc, char *argv[])
{
(void) argc;
(void) argv;
using namespace mln;
// Ref
image2d<bool> ref(box2d(7, 7));
data::fill(ref, 0);
data::fill((ref | box2d(1, 2)).rw(), true);
// Test
image2d<bool> ima(10, 10);
data::fill(ima, 0);
data::fill((ima | box2d(3, 4)).rw(), true);
image2d<bool>
test = scribo::preprocessing::crop_without_localization(ima,
make::box2d(2,2,
8,8));
mln_assertion(ref == test);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment