33 #if defined(DECImageHelpers_RECURSES)
34 #error Recursive header files inclusion detected in DECImageHelpers.h
35 #else // defined(DECImageHelpers_RECURSES)
37 #define DECImageHelpers_RECURSES
39 #if !defined DECImageHelpers_h
41 #define DECImageHelpers_h
46 #include "DGtal/base/Common.h"
47 #include "DGtal/images/CImage.h"
48 #include "DGtal/topology/CCellularGridSpaceND.h"
49 #include "DGtal/math/linalg/CLinearAlgebra.h"
50 #include "DGtal/dec/DiscreteExteriorCalculus.h"
70 template <
typename Calculus, DGtal::Dimension dim, DGtal::Duality duality>
75 typedef typename Calculus::LinearAlgebraBackend::Triplet Triplet;
77 typedef std::vector<Triplet> Triplets;
80 for (Index index=0; index<kform.
length(); index++)
81 triplets.push_back(Triplet(index, index, kform.
myContainer(index)));
84 op.myContainer.setFromTriplets( triplets.begin(), triplets.end() );
97 template <
typename Calculus, DGtal::Dimension dim, DGtal::Duality duality>
116 template <
typename Calculus, DGtal::Dimension dim, DGtal::Duality duality>
137 template <
typename Image>
143 typedef typename Point::Coordinate Coordinate;
145 for (
int y = 0; y < pixel_size; y++ )
146 for (
int x = 0; x < pixel_size; x++ )
148 Point q( (Coordinate) x, (Coordinate) y );
165 template <
typename Image>
171 typedef typename Point::Coordinate Coordinate;
176 for (
int y = 0; y < pixel_size_y; y++ )
177 for (
int x = 0; x < pixel_size_x; x++ )
179 Point q( (Coordinate) x, (Coordinate) y );
196 template <
typename Image>
202 typedef typename Point::Coordinate Coordinate;
207 for (
int y = pixel_size_y; y < pixel_size; y++ )
208 for (
int x = pixel_size_x; x < pixel_size; x++ )
210 Point q( (Coordinate) x, (Coordinate) y );
236 template <
typename Calculus,
typename AnyForm2,
typename Image,
typename Function>
241 const Function& functor,
242 double cut_low = 0.0,
double cut_up = 1.0,
int pixel_size = 1 )
252 double max_u = min_u;
253 for ( Index index = 0; index < u.myContainer.rows(); index++)
256 min_u = std::min( min_u, v );
257 max_u = std::max( max_u, v );
259 if ( min_u < cut_low ) min_u = cut_low;
260 if ( max_u > cut_up ) max_u = cut_up;
261 for ( Index index = 0; index < u.myContainer.rows(); index++)
263 SCell cell = u.getSCell( index );
265 double w = std::min( cut_up, std::max( cut_low, v ) );
266 if ( min_u != max_u ) w = ( w - min_u ) / ( max_u - min_u );
296 template <
typename Calculus,
typename Form1,
typename Image,
typename Function,
typename Predicate>
299 const Form1& v,
bool primal,
301 const Function& functor,
302 const Predicate& predicate,
303 double cut_low = 0.0,
double cut_up = 1.0,
int pixel_size = 1 )
313 double max_v = min_v;
314 for ( Index index = 0; index < v.myContainer.rows(); index++)
317 min_v = std::min( min_v, w );
318 max_v = std::max( max_v, w );
320 if ( min_v < cut_low ) min_v = cut_low;
321 if ( max_v > cut_up ) max_v = cut_up;
322 for ( Index index = 0; index < v.myContainer.rows(); index++)
324 SCell cell = v.getSCell( index );
326 if ( ! predicate( u ) )
continue;
327 double w = std::min( cut_up, std::max( cut_low, u ) );
328 if ( min_v != max_v ) w = ( w - min_v ) / ( max_v - min_v );
358 template <
typename Calculus,
typename Image,
typename Function,
typename Predicate>
363 const Function& functor,
364 const Predicate& predicate,
365 double cut_low = 0.0,
double cut_up = 1.0,
int pixel_size = 1 )
368 form1ToImage( calculus, v,
false, image, functor, predicate,
369 cut_low, cut_up, pixel_size );
395 template <
typename Calculus,
typename Image,
typename Function,
typename Predicate>
400 const Function& functor,
401 const Predicate& predicate,
402 double cut_low = 0.0,
double cut_up = 1.0,
int pixel_size = 1 )
405 form1ToImage( calculus, v,
true, image, functor, predicate,
406 cut_low, cut_up, pixel_size );
432 template <
typename Calculus,
typename AnyForm2,
typename Image,
typename Function>
439 const Function& functor,
440 double cut_low = 0.0,
double cut_up = 1.0,
int pixel_size = 1 )
447 double max_u = min_u;
448 for ( Index index = 0; index < u0.myContainer.rows(); index++)
451 min_u = std::min( min_u, v );
452 max_u = std::max( max_u, v );
454 for ( Index index = 0; index < u1.myContainer.rows(); index++)
457 min_u = std::min( min_u, v );
458 max_u = std::max( max_u, v );
460 for ( Index index = 0; index < u2.myContainer.rows(); index++)
463 min_u = std::min( min_u, v );
464 max_u = std::max( max_u, v );
466 if ( min_u < cut_low ) min_u = cut_low;
467 if ( max_u > cut_up ) max_u = cut_up;
468 for ( Index index = 0; index < u0.myContainer.rows(); index++)
470 SCell cell = u0.getSCell( index );
472 double w0 = std::min( cut_up, std::max( cut_low, v0 ) );
473 if ( min_u != max_u ) w0 = ( w0 - min_u ) / ( max_u - min_u );
475 double w1 = std::min( cut_up, std::max( cut_low, v1 ) );
476 if ( min_u != max_u ) w1 = ( w1 - min_u ) / ( max_u - min_u );
478 double w2 = std::min( cut_up, std::max( cut_low, v2 ) );
479 if ( min_u != max_u ) w2 = ( w2 - min_u ) / ( max_u - min_u );
504 template <
typename Calculus,
typename AnyForm2,
typename Image>
509 double cut_low = 0.0,
double cut_up = 1.0,
514 [] (
double x ) {
return (
unsigned char) ( round( x * 255.0 ) ); },
515 cut_low, cut_up, pixel_size );
538 template <
typename Calculus,
typename Image>
543 double cut_low = 0.0,
double cut_up = 1.0,
551 [] (
double x ) {
return (
unsigned char) ( round( x * 255.0 ) ); },
552 [] (
double x ) {
return x < 0.25; },
553 cut_low, cut_up, pixel_size );
576 template <
typename Calculus,
typename Image>
581 double cut_low = 0.0,
double cut_up = 1.0,
589 [] (
double x ) {
return (
unsigned char) ( round( x * 255.0 ) ); },
590 [] (
double x ) {
return x < 0.25; },
591 cut_low, cut_up, pixel_size );
615 template <
typename Calculus,
typename Image>
620 double cut_low = 0.0,
double cut_up = 1.0,
628 [color] (
double x ) {
return color; },
629 [] (
double x ) {
return x < 0.25; },
630 cut_low, cut_up, pixel_size );
654 template <
typename Calculus,
typename Image>
659 double cut_low = 0.0,
double cut_up = 1.0,
667 [color] (
double x ) {
return color; },
668 [] (
double x ) {
return x < 0.25; },
669 cut_low, cut_up, pixel_size );
697 template <
typename Calculus,
typename AnyForm2,
typename Image>
704 double cut_low = 0.0,
double cut_up = 1.0,
709 ( calculus, u0, u1, u2, image,
710 [] (
double r,
double g,
double b )
711 {
return Color( (
unsigned char) ( round( r * 255.0 ) ),
712 (
unsigned char) ( round( g * 255.0 ) ),
713 (
unsigned char) ( round( b * 255.0 ) ) ); },
714 cut_low, cut_up, pixel_size );
739 template <
typename TKSpace,
740 typename TLinearAlgebra = EigenLinearAlgebraBackend >
799 D0( calculus ),
D1( calculus ),
815 const KSpace & K = calculus.
myKSpace;
817 Point p0 = K.uKCoords( K.lowerCell() );
818 Point p1 = K.uKCoords( K.upperCell() );
830 D0 = calculus.template derivative<0,PRIMAL>();
832 D1 = calculus.template derivative<1,PRIMAL>();
834 dual_D0 = calculus.template derivative<0,DUAL>();
836 dual_D1 = calculus.template derivative<1,DUAL>();
838 primal_h0 = calculus.template hodge<0,PRIMAL>();
840 primal_h1 = calculus.template hodge<1,PRIMAL>();
842 primal_h2 = calculus.template hodge<2,PRIMAL>();
844 dual_h0 = calculus.template hodge<0,DUAL>();
846 dual_h1 = calculus.template hodge<1,DUAL>();
848 dual_h2 = calculus.template hodge<2,DUAL>();
890 PrimalDerivative0
D0;
892 PrimalDerivative1
D1;
920 #endif // !defined DECImageHelpers_h
922 #undef DECImageHelpers_RECURSES
923 #endif // else defined(DECImageHelpers_RECURSES)
void beginBlock(const std::string &keyword="")
DECImage2D(int _verbose=1)
void dualForm1ToGreyLevelImage(const Calculus &calculus, const typename Calculus::DualForm1 &v, Image &image, double cut_low=0.0, double cut_up=1.0, int pixel_size=1)
Calculus::PrimalHodge0 PrimalHodge0
BOOST_CONCEPT_ASSERT((concepts::CCellularGridSpaceND< KSpace >))
const ConstIterator & begin() const
const ConstIterator & end() const
void primalForm1ToImage(const Calculus &calculus, const typename Calculus::PrimalForm1 &v, Image &image, const Function &functor, const Predicate &predicate, double cut_low=0.0, double cut_up=1.0, int pixel_size=1)
LinearAlgebraBackend::DenseVector::Scalar Scalar
const Point & sKCoords(const SCell &c) const
void primalForm1ToRGBColorImage(const Calculus &calculus, const typename Calculus::PrimalForm1 &v, Image &image, Color color, double cut_low=0.0, double cut_up=1.0, int pixel_size=1)
DGtal::LinearOperator< Calculus, dim, duality, dim, duality > diagonal(const DGtal::KForm< Calculus, dim, duality > &kform)
Calculus::DualHodge0 DualHodge0
static double castToDouble(const T &aT)
TImageContainer::Point Point
Calculus::PrimalDerivative0 PrimalDerivative0
DualDerivative0 dual_D0
dual derivative dual 0-form -> dual 1-form
Calculus::DualDerivative1 DualDerivative1
Calculus::PrimalAntiderivative1 PrimalAntiderivative1
void threeForms2ToImage(const Calculus &calculus, const AnyForm2 &u0, const AnyForm2 &u1, const AnyForm2 &u2, Image &image, const Function &functor, double cut_low=0.0, double cut_up=1.0, int pixel_size=1)
Aim: This class simplifies the development of 2D image processing tools using discrete exterior calcu...
void setValue(const Point &aPoint, const Value &aValue)
Calculus::PrimalHodge1 PrimalHodge1
PrimalHodge2 primal_h2
hodge star: 2-form -> dual 2-form
DualDerivative1 dual_D1
dual derivative dual 1-form -> dual 2-form
void init(Clone< KSpace > aKSpace)
DualHodge0 dual_h0
hodge star: dual 0-form -> 0-form
DiscreteExteriorCalculusFactory< LinearAlgebra > CalculusFactory
void threeForms2ToRGBColorImage(const Calculus &calculus, const AnyForm2 &u0, const AnyForm2 &u1, const AnyForm2 &u2, Image &image, double cut_low=0.0, double cut_up=1.0, int pixel_size=1)
Calculus::PrimalHodge2 PrimalHodge2
TLinearAlgebra LinearAlgebra
Calculus::DualAntiderivative2 DualAntiderivative2
Calculus::PrimalForm2 PrimalForm2
DGtal::LinearOperator< Calculus, dim, duality, dim, duality > squaredDiagonal(const DGtal::KForm< Calculus, dim, duality > &kform)
Calculus::PrimalIdentity2 PrimalIdentity2
void dualForm1ToImage(const Calculus &calculus, const typename Calculus::DualForm1 &v, Image &image, const Function &functor, const Predicate &predicate, double cut_low=0.0, double cut_up=1.0, int pixel_size=1)
void writeDualLinel(Image &image, typename Image::Point pt, typename Image::Value val, int pixel_size=1)
Calculus::DualAntiderivative1 DualAntiderivative1
Space::RealVector RealVector
Calculus::PrimalForm1 PrimalForm1
DiscreteExteriorCalculus< 2, 2, LinearAlgebra > Calculus
DualHodge1 dual_h1
hodge star: dual 1-form -> 1-form
Calculus::DualHodge2 DualHodge2
Calculus::PrimalIdentity1 PrimalIdentity1
void writePixel(Image &image, typename Image::Point pt, typename Image::Value val, int pixel_size=1)
void dualForm1ToRGBColorImage(const Calculus &calculus, const typename Calculus::DualForm1 &v, Image &image, Color color, double cut_low=0.0, double cut_up=1.0, int pixel_size=1)
Calculus::PrimalDerivative1 PrimalDerivative1
Point sCoords(const SCell &c) const
static bool even(ParamType aT)
Calculus::DualHodge1 DualHodge1
int verbose
The verbose level (0: silent).
void writePrimalLinel(Image &image, typename Image::Point pt, typename Image::Value val, int pixel_size=1)
Trace trace(traceWriterTerm)
Calculus::PrimalIdentity0 PrimalIdentity0
void form1ToImage(const Calculus &calculus, const Form1 &v, bool primal, Image &image, const Function &functor, const Predicate &predicate, double cut_low=0.0, double cut_up=1.0, int pixel_size=1)
void primalForm1ToGreyLevelImage(const Calculus &calculus, const typename Calculus::PrimalForm1 &v, Image &image, double cut_low=0.0, double cut_up=1.0, int pixel_size=1)
typename Self::Point Point
Calculus calculus
The discrete exterior calculus instance.
void form2ToGreyLevelImage(const Calculus &calculus, const AnyForm2 &u, Image &image, double cut_low=0.0, double cut_up=1.0, int pixel_size=1)
void squares(DGtal::KForm< Calculus, dim, duality > &kform)
PrimalHodge0 primal_h0
hodge star: 0-form -> dual 0-form
Calculus::DualDerivative0 DualDerivative0
Calculus::PrimalAntiderivative2 PrimalAntiderivative2
DualHodge2 dual_h2
hodge star: dual 2-form -> 2-form
bool insertSCell(const SCell &signed_cell)
Domain cell_domain
The cell domain (i.e. all the cells)
void form2ToImage(const Calculus &calculus, const AnyForm2 &u, Image &image, const Function &functor, double cut_low=0.0, double cut_up=1.0, int pixel_size=1)
TImageContainer::Value Value
DiscreteExteriorCalculusSolver< Calculus, LinearAlgebraSolver, 0, PRIMAL, 0, PRIMAL > SolverU
PrimalDerivative0 D0
primal derivative: 0-form -> 1-form
LinearAlgebra::SolverSimplicialLLT LinearAlgebraSolver
BOOST_STATIC_ASSERT((KSpace::dimension==2))
static const constexpr Dimension dimension
PrimalDerivative1 D1
primal derivative: 1-form -> 2-form
PrimalHodge1 primal_h1
hodge star: 1-form -> dual 1-form
DiscreteExteriorCalculusSolver< Calculus, LinearAlgebraSolver, 1, PRIMAL, 1, PRIMAL > SolverV
DECImage2D & operator=(const DECImage2D &other)=delete
Domain domain
The image domain (i.e. all the pixels)
Calculus::PrimalForm0 PrimalForm0
HyperRectDomain< Space > Domain
RealVector::Component Scalar
LinearAlgebraBackend::DenseVector::Index Index