mirror of https://github.com/CGAL/cgal
Improve CGAL::Image_3
- The type of `value_outside` is now directory `Return_type`: no need to apply the transformation. - The indicator functions of the labelized trilinear interpolation can be changed.
This commit is contained in:
parent
12be44eac3
commit
35cb7bd5b8
|
|
@ -47,16 +47,23 @@ namespace CGAL {
|
||||||
namespace ImageIO {
|
namespace ImageIO {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class Indicator : public std::unary_function<T, double>
|
struct Indicator_factory
|
||||||
{
|
{
|
||||||
|
class Indicator : public std::unary_function<T, double>
|
||||||
|
{
|
||||||
const T label;
|
const T label;
|
||||||
public:
|
public:
|
||||||
Indicator(T i) : label(i) {};
|
Indicator(T i) : label(i) {};
|
||||||
|
|
||||||
double operator()(T x) const
|
double operator()(T x) const
|
||||||
{
|
{
|
||||||
return (x == label) ? 1. : 0.;
|
return (x == label) ? 1. : 0.;
|
||||||
}
|
}
|
||||||
|
}; // end nested class Indicator
|
||||||
|
|
||||||
|
Indicator indicator(T i) const {
|
||||||
|
return Indicator(i);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace CGAL::ImageIO
|
} // end namespace CGAL::ImageIO
|
||||||
|
|
@ -185,8 +192,8 @@ public:
|
||||||
trilinear_interpolation(const Coord_type&x,
|
trilinear_interpolation(const Coord_type&x,
|
||||||
const Coord_type&y,
|
const Coord_type&y,
|
||||||
const Coord_type&z,
|
const Coord_type&z,
|
||||||
const Image_word_type& value_outside =
|
const Target_word_type& value_outside =
|
||||||
Image_word_type(),
|
Target_word_type(),
|
||||||
Image_transform transform =
|
Image_transform transform =
|
||||||
Image_transform() ) const;
|
Image_transform() ) const;
|
||||||
|
|
||||||
|
|
@ -198,8 +205,8 @@ public:
|
||||||
trilinear_interpolation(const Coord_type&x,
|
trilinear_interpolation(const Coord_type&x,
|
||||||
const Coord_type&y,
|
const Coord_type&y,
|
||||||
const Coord_type&z,
|
const Coord_type&z,
|
||||||
const Image_word_type& value_outside =
|
const Target_word_type& value_outside =
|
||||||
Image_word_type()) const
|
Target_word_type()) const
|
||||||
{
|
{
|
||||||
return trilinear_interpolation<
|
return trilinear_interpolation<
|
||||||
Image_word_type,
|
Image_word_type,
|
||||||
|
|
@ -208,13 +215,31 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Image_word_type,
|
template <typename Image_word_type,
|
||||||
typename Coord_type>
|
typename Coord_type,
|
||||||
Image_word_type
|
typename Target_word_type>
|
||||||
|
Target_word_type
|
||||||
labellized_trilinear_interpolation(const Coord_type&x,
|
labellized_trilinear_interpolation(const Coord_type&x,
|
||||||
const Coord_type&y,
|
const Coord_type&y,
|
||||||
const Coord_type&z,
|
const Coord_type&z,
|
||||||
const Image_word_type& value_outside =
|
const Target_word_type& value_outside =
|
||||||
Image_word_type()) const;
|
Target_word_type()) const
|
||||||
|
{
|
||||||
|
CGAL::ImageIO::Indicator_factory<Image_word_type> indicator_factory;
|
||||||
|
return labellized_trilinear_interpolation<Image_word_type>
|
||||||
|
(x, y, z, value_outside, indicator_factory);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Image_word_type,
|
||||||
|
typename Coord_type,
|
||||||
|
typename Target_word_type,
|
||||||
|
typename Indicator_factory>
|
||||||
|
Target_word_type
|
||||||
|
labellized_trilinear_interpolation
|
||||||
|
(const Coord_type&x,
|
||||||
|
const Coord_type&y,
|
||||||
|
const Coord_type&z,
|
||||||
|
const Target_word_type& value_outside,
|
||||||
|
const Indicator_factory indicator_factory) const;
|
||||||
|
|
||||||
}; // end Image_3
|
}; // end Image_3
|
||||||
|
|
||||||
|
|
@ -226,12 +251,12 @@ Target_word_type
|
||||||
Image_3::trilinear_interpolation(const Coord_type& x,
|
Image_3::trilinear_interpolation(const Coord_type& x,
|
||||||
const Coord_type& y,
|
const Coord_type& y,
|
||||||
const Coord_type& z,
|
const Coord_type& z,
|
||||||
const Image_word_type& value_outside,
|
const Target_word_type& value_outside,
|
||||||
Image_transform transform) const
|
Image_transform transform) const
|
||||||
{
|
{
|
||||||
// Check on double/float coordinates, because (int)-0.1 gives 0
|
// Check on double/float coordinates, because (int)-0.1 gives 0
|
||||||
if ( x < 0 || y < 0 || z < 0 )
|
if ( x < 0 || y < 0 || z < 0 )
|
||||||
return Target_word_type(value_outside);
|
return value_outside;
|
||||||
|
|
||||||
const Coord_type lx = x / image()->vx;
|
const Coord_type lx = x / image()->vx;
|
||||||
const Coord_type ly = y / image()->vy;
|
const Coord_type ly = y / image()->vy;
|
||||||
|
|
@ -248,7 +273,7 @@ Image_3::trilinear_interpolation(const Coord_type& x,
|
||||||
ly >= dimy-1 ||
|
ly >= dimy-1 ||
|
||||||
lx >= dimx-1)
|
lx >= dimx-1)
|
||||||
{
|
{
|
||||||
return Target_word_type(transform(value_outside));
|
return value_outside;
|
||||||
}
|
}
|
||||||
|
|
||||||
// images are indexed by (z,y,x)
|
// images are indexed by (z,y,x)
|
||||||
|
|
@ -411,12 +436,16 @@ Image_3::trilinear_interpolation(const Coord_type& x,
|
||||||
|
|
||||||
|
|
||||||
template <typename Image_word_type,
|
template <typename Image_word_type,
|
||||||
typename Coord_type>
|
typename Coord_type,
|
||||||
Image_word_type
|
typename Target_word_type,
|
||||||
Image_3::labellized_trilinear_interpolation(const Coord_type& x,
|
typename Indicator_factory>
|
||||||
|
Target_word_type
|
||||||
|
Image_3::labellized_trilinear_interpolation
|
||||||
|
(const Coord_type& x,
|
||||||
const Coord_type& y,
|
const Coord_type& y,
|
||||||
const Coord_type& z,
|
const Coord_type& z,
|
||||||
const Image_word_type& value_outside) const
|
const Target_word_type& value_outside,
|
||||||
|
const Indicator_factory indicator_factory) const
|
||||||
{
|
{
|
||||||
// Check on double/float coordinates, because (int)-0.1 gives 0
|
// Check on double/float coordinates, because (int)-0.1 gives 0
|
||||||
if ( x < 0 || y < 0 || z < 0 ) return value_outside;
|
if ( x < 0 || y < 0 || z < 0 ) return value_outside;
|
||||||
|
|
@ -481,15 +510,14 @@ Image_3::labellized_trilinear_interpolation(const Coord_type& x,
|
||||||
return labels[0];
|
return labels[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef ImageIO::Indicator<Image_word_type> Indicator;
|
|
||||||
double best_value = 0.;
|
double best_value = 0.;
|
||||||
Image_word_type best = 0;
|
Image_word_type best = 0;
|
||||||
for(int i = 0; i < lc; ++i)
|
for(int i = 0; i < lc; ++i)
|
||||||
{
|
{
|
||||||
Image_word_type iwt = labels[i];
|
Image_word_type iwt = labels[i];
|
||||||
const double r =
|
const double r =
|
||||||
trilinear_interpolation<Image_word_type,double,Coord_type, Indicator>(
|
trilinear_interpolation<Image_word_type,double,Coord_type>(
|
||||||
x, y, z, value_outside, Indicator(iwt));
|
x, y, z, value_outside, indicator_factory.indicator(iwt));
|
||||||
CGAL_assertion(r >= 0.);
|
CGAL_assertion(r >= 0.);
|
||||||
CGAL_assertion(r <= 1.);
|
CGAL_assertion(r <= 1.);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ public:
|
||||||
/// Constructor
|
/// Constructor
|
||||||
Image_to_labeled_function_wrapper(const Image_& image,
|
Image_to_labeled_function_wrapper(const Image_& image,
|
||||||
const Transform& transform = Transform(),
|
const Transform& transform = Transform(),
|
||||||
const Image_word_type value_outside = 0)
|
const Return_type value_outside = 0)
|
||||||
: r_im_(image)
|
: r_im_(image)
|
||||||
, transform(transform)
|
, transform(transform)
|
||||||
, value_outside(value_outside)
|
, value_outside(value_outside)
|
||||||
|
|
@ -85,7 +85,7 @@ public:
|
||||||
if ( labeled_image )
|
if ( labeled_image )
|
||||||
{
|
{
|
||||||
return static_cast<return_type>(transform(
|
return static_cast<return_type>(transform(
|
||||||
r_im_.labellized_trilinear_interpolation(
|
r_im_.template labellized_trilinear_interpolation<Image_word_type>(
|
||||||
CGAL::to_double(p.x()),
|
CGAL::to_double(p.x()),
|
||||||
CGAL::to_double(p.y()),
|
CGAL::to_double(p.y()),
|
||||||
CGAL::to_double(p.z()),
|
CGAL::to_double(p.z()),
|
||||||
|
|
@ -130,7 +130,7 @@ private:
|
||||||
/// Labeled image to wrap
|
/// Labeled image to wrap
|
||||||
const Image_& r_im_;
|
const Image_& r_im_;
|
||||||
const Transform transform;
|
const Transform transform;
|
||||||
const Image_word_type value_outside;
|
const Return_type value_outside;
|
||||||
|
|
||||||
}; // end class Image_to_labeled_function_wrapper
|
}; // end class Image_to_labeled_function_wrapper
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue