DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Types | Public Member Functions | Private Member Functions | Private Attributes
DGtal::ReverseDistanceTransformation< Image, p, IntegerShort > Class Template Reference

#include <ReverseDistanceTransformation.h>

Collaboration diagram for DGtal::ReverseDistanceTransformation< Image, p, IntegerShort >:
Collaboration graph
[legend]

Public Types

typedef
ImageContainerBySTLVector
< HyperRectDomain< typename
Image::Domain::Space >
, IntegerShort > 
OutputImage
typedef Image::Value Value
typedef Image::Point Point
typedef Image::Vector Vector
typedef Image::Dimension Dimension
typedef Image::Size Size
typedef Image::Integer Integer
typedef Image::Domain Domain
typedef
Image::Domain::Space::Point::Coordinate 
Coordinate
typedef SeparableMetricHelper
< Point, Integer, p > 
SeparableMetric

Public Member Functions

 BOOST_CONCEPT_ASSERT ((CBoundedInteger< IntegerShort >))
 ReverseDistanceTransformation (const IntegerShort defaultForeground=NumberTraits< IntegerShort >::ONE, const IntegerShort defaultBackground=NumberTraits< IntegerShort >::ZERO)
 ~ReverseDistanceTransformation ()
OutputImage reconstruction (const Image &inputImage)
template<typename DigitalSet >
void reconstructionAsSet (DigitalSet &aSet, const Image &inputImage)
template<typename Set >
void reconstructionAsSet (Set &aSet, const I &aImage)

Private Member Functions

bool reconstructionInternal (const Image &aImage, Image &output, Image &swap)
OutputImage castValues (const Image &input) const
void computeSteps (const Image &inputImage, Image &output, const Dimension dim) const
void computeSteps1D (const Image &input, Image &output, const Point &startingPoint, const Size dim, Integer s[], Integer t[]) const

Private Attributes

SeparableMetric myMetric
Point myLowerBoundCopy
Point myUpperBoundCopy
Point myExtent
Vector myDisplacementVector
IntegerShort myForegroundValue
IntegerShort myBackgroundValue

Detailed Description

template<typename Image, DGtal::uint32_t p, typename IntegerShort = DGtal::int8_t>
class DGtal::ReverseDistanceTransformation< Image, p, IntegerShort >

Aim: Implementation of the linear in time reverse distance transformation.

Description of template class 'ReverseDistanceTransformation'

More precisely, given an input image where value V at a point P corresponds to a disc with center P and radius V. The aim of the reverse distance transformation is thus to reconstruct the binary shape as the union of all balls defined in the input map.

Template Parameters:
Imagean input image type containng distance values.
pthe static integer value to define the l_p metric.
IntegerShort(optional) type used to represent the output object values (default: DGtal::int8_t).xs

Definition at line 75 of file ReverseDistanceTransformation.h.


Member Typedef Documentation

template<typename Image, DGtal::uint32_t p, typename IntegerShort = DGtal::int8_t>
typedef Image::Domain::Space::Point::Coordinate DGtal::ReverseDistanceTransformation< Image, p, IntegerShort >::Coordinate

Definition at line 94 of file ReverseDistanceTransformation.h.

template<typename Image, DGtal::uint32_t p, typename IntegerShort = DGtal::int8_t>
typedef Image::Dimension DGtal::ReverseDistanceTransformation< Image, p, IntegerShort >::Dimension

Definition at line 90 of file ReverseDistanceTransformation.h.

template<typename Image, DGtal::uint32_t p, typename IntegerShort = DGtal::int8_t>
typedef Image::Domain DGtal::ReverseDistanceTransformation< Image, p, IntegerShort >::Domain

Definition at line 93 of file ReverseDistanceTransformation.h.

template<typename Image, DGtal::uint32_t p, typename IntegerShort = DGtal::int8_t>
typedef Image::Integer DGtal::ReverseDistanceTransformation< Image, p, IntegerShort >::Integer

Definition at line 92 of file ReverseDistanceTransformation.h.

template<typename Image, DGtal::uint32_t p, typename IntegerShort = DGtal::int8_t>
typedef ImageContainerBySTLVector< HyperRectDomain<typename Image::Domain::Space> , IntegerShort > DGtal::ReverseDistanceTransformation< Image, p, IntegerShort >::OutputImage

Type of resulting image.

Definition at line 85 of file ReverseDistanceTransformation.h.

template<typename Image, DGtal::uint32_t p, typename IntegerShort = DGtal::int8_t>
typedef Image::Point DGtal::ReverseDistanceTransformation< Image, p, IntegerShort >::Point

Definition at line 88 of file ReverseDistanceTransformation.h.

template<typename Image, DGtal::uint32_t p, typename IntegerShort = DGtal::int8_t>
typedef SeparableMetricHelper< Point , Integer , p > DGtal::ReverseDistanceTransformation< Image, p, IntegerShort >::SeparableMetric

We construct the type associated to the separable metric.

Definition at line 97 of file ReverseDistanceTransformation.h.

template<typename Image, DGtal::uint32_t p, typename IntegerShort = DGtal::int8_t>
typedef Image::Size DGtal::ReverseDistanceTransformation< Image, p, IntegerShort >::Size

Definition at line 91 of file ReverseDistanceTransformation.h.

template<typename Image, DGtal::uint32_t p, typename IntegerShort = DGtal::int8_t>
typedef Image::Value DGtal::ReverseDistanceTransformation< Image, p, IntegerShort >::Value

Definition at line 87 of file ReverseDistanceTransformation.h.

template<typename Image, DGtal::uint32_t p, typename IntegerShort = DGtal::int8_t>
typedef Image::Vector DGtal::ReverseDistanceTransformation< Image, p, IntegerShort >::Vector

Definition at line 89 of file ReverseDistanceTransformation.h.


Constructor & Destructor Documentation

template<typename I , DGtal::uint32_t p, typename IntShort>
DGtal::ReverseDistanceTransformation< I, p, IntShort >::ReverseDistanceTransformation ( const IntShort  defaultForeground = NumberTraits< IntegerShort >::ONE,
const IntShort  defaultBackground = NumberTraits< IntegerShort >::ZERO 
)
inline

Constructor.

Parameters:
defaultForgroundValue(optional) default used to represent object grid points
defaultBackgroundValue(optional) default used to represent background grid points

Constructor.

Definition at line 47 of file ReverseDistanceTransformation.ih.

:
myForegroundValue(defaultForeground),
myBackgroundValue(defaultBackground)
{
}
template<typename I , DGtal::uint32_t p, typename IntShort >
DGtal::ReverseDistanceTransformation< I, p, IntShort >::~ReverseDistanceTransformation ( )
inline

Default destructor

Destructor.

Definition at line 60 of file ReverseDistanceTransformation.ih.

{
}

Member Function Documentation

template<typename Image, DGtal::uint32_t p, typename IntegerShort = DGtal::int8_t>
DGtal::ReverseDistanceTransformation< Image, p, IntegerShort >::BOOST_CONCEPT_ASSERT ( (CBoundedInteger< IntegerShort >)  )
template<typename I, DGtal::uint32_t p, typename IntShort >
DGtal::ReverseDistanceTransformation< I, p, IntShort >::OutputImage DGtal::ReverseDistanceTransformation< I, p, IntShort >::castValues ( const I &  input) const
inlineprivate

Cast values in order to output an image of type ImageOutput. Basically, in internal computations, 0 values are associated to background points and '>0' to object point. This method casts the value to match with myForegroundValue ad myBackgroundValue specified in the constructor.

Parameters:
inputImageinput internal image.
Returns:
the filtered image.

Definition at line 169 of file ReverseDistanceTransformation.ih.

{
//We threshold input values
typename OutputImage::Iterator ito = output.begin();
for(typename I::ConstIterator it=input.begin(),
itend = input.end();
it != itend;
++it,++ito)
if ( (*it) > 0)
else
return output;
}
template<typename I, DGtal::uint32_t p, typename IntShort >
void DGtal::ReverseDistanceTransformation< I, p, IntShort >::computeSteps ( const I &  inputImage,
I &  output,
const Dimension  dim 
) const
inlineprivate

Compute the other steps of the separable reverse distance transformation.

Parameters:
inputImagethe image resulting of the first (or intermediate) step
outputthe output image
dimthe dimension to process

Definition at line 190 of file ReverseDistanceTransformation.ih.

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), and DGtal::trace.

{
std::string title = "RDT dimension " + boost::lexical_cast<string>( dim ); ;
trace.beginBlock ( title );
typedef typename Domain::ConstSubRange::ConstIterator ConstDomIt;
//We setup the subdomain iterator
//the iterator will scan dimension using the order:
// {n-1, n-2, ... 1} (we skip the '0' dimension.
std::vector<Size> subdomain;
subdomain.reserve(I::dimension - 1);
for (unsigned int k = 0; k < I::dimension ; k++)
if ( (I::dimension - 1 - k) != dim)
subdomain.push_back( I::dimension - 1 - k );
Size maxSize = myExtent.normInfinity();
//Stacks used in the envelope computation
Integer *s = new Integer[maxSize+1];
Integer *t = new Integer[maxSize+1];
ASSERT( s != NULL);
ASSERT( t != NULL);
//We process the dimensions to construct a Point
for (ConstDomIt it = localDomain.subRange( subdomain ).begin(),
itend = localDomain.subRange( subdomain ).end(); it != itend; ++it)
{
computeSteps1D ( input, output, (*it), dim, s, t );
}
delete[] s;
delete[] t;
}
template<typename I, DGtal::uint32_t p, typename IntShort >
void DGtal::ReverseDistanceTransformation< I, p, IntShort >::computeSteps1D ( const I &  input,
I &  output,
const Point startingPoint,
const Size  dim,
Integer  s[],
Integer  t[] 
) const
private

Compute the 1D DT associated to the steps except the first one.

Parameters:
aImagethe input image
outputthe output image with the DT values
startingPointa point to specify the starting point of the 1D row
dimthe dimension to process
Todo:
optimize the test here

Definition at line 237 of file ReverseDistanceTransformation.ih.

{
Coordinate q = 0;
Point sQ = startingPoint;
Point pU = startingPoint;
//trace.info()<<endl<<"Enter startingPoint="<<startingPoint<<endl;
//init of the stack structure
pU[dim] = myLowerBoundCopy[dim];
while ((pU[dim] <= myUpperBoundCopy[dim])
&& (input ( pU ) == 0))
pU[dim] ++;
if ( pU[dim] > myUpperBoundCopy[dim] )
{
for(typename I::SpanIterator it= output.spanBegin(startingPoint,dim),
itend=output.spanEnd(startingPoint,dim);
it != itend; ++it)
output.setValue(it, 0);
return;
}
q = 0;
s[q] = pU[dim];
sQ[dim] = s[q];
t[q] = myLowerBoundCopy[dim];
//Forward Scan
for ( int u = pU[dim] + 1; u <= myUpperBoundCopy[dim] ; u++ )
{
pU[ dim ] = u;
if ( input( pU ) == 0 )
{
//trace.info() << "Ctd " << pU ;
continue;
}
while ( ( q >= 0 ) &&
( myMetric.reversedF ( t[q], s[q], (const int)input ( sQ ) ) <
myMetric.reversedF ( t[q], u, (const int)input ( pU ) ) ) )
{
q--;
if (q>=0)
sQ[dim] = s[q];
}
if ( q < 0 )
{
q = 0;
s[0] = u;
t[0] = myLowerBoundCopy[dim];
sQ[dim] = u;
}
else
{
sQ[dim] = s[q];
w = 1 + myMetric.reversedSep ( s[q],
(const int)input ( sQ ),
u,
(const int)input ( pU ) );
if (( w <= myUpperBoundCopy[dim] ) && (w>= myLowerBoundCopy[dim]))
{
q++;
s[q] = u;
sQ[dim] = u;
t[q] = w;
}
}
}
Point last = startingPoint;
ASSERT(q>=0);
//Backward Scan
for (last[dim] = myUpperBoundCopy[dim];
last[dim] >= myLowerBoundCopy[dim] ;
last[dim]-- )
{
if (myMetric.reversedF ( last[dim] , s[q], (const int)input ( sQ )) > 0 )
output.setValue ( last, myMetric.reversedF ( last[dim] , s[q], (const int)input ( sQ ) ) );
else
output.setValue ( last, 0 );
if (( last[dim] == t[q] ) && (q > 0))
{
q--;
sQ[dim] = s[q];
}
}
}
template<typename I, DGtal::uint32_t p, typename IntShort >
DGtal::ReverseDistanceTransformation< I, p, IntShort >::OutputImage DGtal::ReverseDistanceTransformation< I, p, IntShort >::reconstruction ( const I &  inputImage)
inline

Compute the Reverse Distance Transformation of an image with the SeparableMetric metric.

Parameters:
inputImagethe input image with distance values
Returns:
the distance transformation image with the Internal format.
Todo:
do something if domain is not hyperrect

Definition at line 68 of file ReverseDistanceTransformation.ih.

{
//We copy the image extent.
myLowerBoundCopy = Point(); //(O,O,...O)
myUpperBoundCopy = aImage.domain().upperBound() - aImage.domain().lowerBound();
myDisplacementVector = aImage.domain().lowerBound();
I output ( typename I::Domain(myLowerBoundCopy, myUpperBoundCopy));
I swap ( typename I::Domain(myLowerBoundCopy, myUpperBoundCopy));
bool isSwap = reconstructionInternal(aImage,output,swap);
if ( !isSwap )
{
//swap.translateDomain(myDisplacementVector);
return castValues(swap);
}
else
{
//output.translateDomain(myDisplacementVector);
return castValues(output);
}
}
template<typename Image, DGtal::uint32_t p, typename IntegerShort = DGtal::int8_t>
template<typename Set >
void DGtal::ReverseDistanceTransformation< Image, p, IntegerShort >::reconstructionAsSet ( Set &  aSet,
const I &  aImage 
)
inline
Todo:
bug in the CDigitalSet concept

Definition at line 98 of file ReverseDistanceTransformation.ih.

{
//BOOST_CONCEPT_ASSERT(( CDigitalSet<Set> ));
//We copy the image extent and translate the image domains to (0,..0)x(Upper-Lower)
myLowerBoundCopy = Point(); //(O,O,...O)
myUpperBoundCopy = aImage.domain().upperBound() - aImage.domain().lowerBound();
myDisplacementVector = aImage.domain().lowerBound();
typename I::Domain domain(myLowerBoundCopy,myUpperBoundCopy);
I output ( typename I::Domain(myLowerBoundCopy, myUpperBoundCopy ));
I swap ( typename I::Domain( myLowerBoundCopy, myUpperBoundCopy ));
bool isSwap = reconstructionInternal(aImage,output,swap);
for(typename I::Domain::ConstIterator it=domain.begin(),
itend = domain.end();
it != itend;
++it)
if (isSwap)
{
if ( output(*it) > 0)
aSet.insertNew((*it) + myDisplacementVector);
}
else
{
if ( swap(*it) > 0)
aSet.insertNew((*it) + myDisplacementVector);
}
}
template<typename Image, DGtal::uint32_t p, typename IntegerShort = DGtal::int8_t>
template<typename DigitalSet >
void DGtal::ReverseDistanceTransformation< Image, p, IntegerShort >::reconstructionAsSet ( DigitalSet &  aSet,
const Image inputImage 
)

Computes the reverse distance transformation and appends the result to the given digital set.

Parameters:
inputImagethe input image with distance values.
aSetthe set to append the result points to.
Template Parameters:
DigitalSetthe type of set to use.
template<typename I, DGtal::uint32_t p, typename IntShort >
bool DGtal::ReverseDistanceTransformation< I, p, IntShort >::reconstructionInternal ( const I &  aImage,
I &  output,
I &  swap 
)
inlineprivate

Internal method for the reconstruction (with double buffering)

Parameters:
aImageinput image with distances
outputbuffer with partial reconstruction.
swapbuffer with partial reconstruction
Returns:
a boolean to indicate which buffer contains the result (true->output).

Definition at line 136 of file ReverseDistanceTransformation.ih.

{
//We copy input image (implicit translation of values)
typename I::Iterator ito=output.begin();
for(typename I::ConstIterator it=aImage.begin(), itend = aImage.end();
it != itend;
++it,++ito)
(*ito) = (*it);
bool isSwap = true;
//We process the dimensions swaping the temporary buffers
for ( Dimension dim = 0; dim < I::dimension ; dim++ )
{
if ( isSwap )
computeSteps ( output, swap, dim );
else
computeSteps ( swap, output, dim );
isSwap = !isSwap;
}
return isSwap;
}

Field Documentation

template<typename Image, DGtal::uint32_t p, typename IntegerShort = DGtal::int8_t>
IntegerShort DGtal::ReverseDistanceTransformation< Image, p, IntegerShort >::myBackgroundValue
private

Value for background grid points.

Definition at line 218 of file ReverseDistanceTransformation.h.

template<typename Image, DGtal::uint32_t p, typename IntegerShort = DGtal::int8_t>
Vector DGtal::ReverseDistanceTransformation< Image, p, IntegerShort >::myDisplacementVector
private

Displacement vector to translate temporary images.

Definition at line 212 of file ReverseDistanceTransformation.h.

template<typename Image, DGtal::uint32_t p, typename IntegerShort = DGtal::int8_t>
Point DGtal::ReverseDistanceTransformation< Image, p, IntegerShort >::myExtent
private

Copy of the image extent.

Definition at line 209 of file ReverseDistanceTransformation.h.

template<typename Image, DGtal::uint32_t p, typename IntegerShort = DGtal::int8_t>
IntegerShort DGtal::ReverseDistanceTransformation< Image, p, IntegerShort >::myForegroundValue
private

Value for foreground grid points.

Definition at line 215 of file ReverseDistanceTransformation.h.

template<typename Image, DGtal::uint32_t p, typename IntegerShort = DGtal::int8_t>
Point DGtal::ReverseDistanceTransformation< Image, p, IntegerShort >::myLowerBoundCopy
private

Copy of the image lower bound.

Definition at line 203 of file ReverseDistanceTransformation.h.

template<typename Image, DGtal::uint32_t p, typename IntegerShort = DGtal::int8_t>
SeparableMetric DGtal::ReverseDistanceTransformation< Image, p, IntegerShort >::myMetric
private

The separable metric instance.

Definition at line 200 of file ReverseDistanceTransformation.h.

template<typename Image, DGtal::uint32_t p, typename IntegerShort = DGtal::int8_t>
Point DGtal::ReverseDistanceTransformation< Image, p, IntegerShort >::myUpperBoundCopy
private

Copy of the image lower bound.

Definition at line 206 of file ReverseDistanceTransformation.h.


The documentation for this class was generated from the following files: