Commit ec25f0fb authored by Julien Michel's avatar Julien Michel
Browse files

Conditions mirroir au bord

parent 744250ff
......@@ -59,17 +59,17 @@ MirrorBoundaryCondition<TImage>
for (i = 0; i < ImageDimension; ++i)
{
if (boundary_offset[i] != 0)
{ // If the neighborhood overlaps on the low edge, then wrap from the
// high edge of the image.
// if (point_index[i] < static_cast<OffsetValueType>(iterator->GetRadius(i)))
// {
ptr += boundary_offset[i] * offset_table[i];
// }
// else // wrap from the low side of the image
// {
// ptr -= iterator->GetImagePointer()->GetBufferedRegion().GetSize()[i] *
// offset_table[i] + boundary_offset[i] * offset_table[i];
// }
{
// If the neighborhood overlaps on the low edge, then wrap from the
// high edge of the image.
if (point_index[i] < static_cast<OffsetValueType>(iterator->GetRadius(i)))
{
ptr += boundary_offset[i] * offset_table[i];
}
else // wrap from the low side of the image
{
ptr -= boundary_offset[i] * offset_table[i];
}
}
}
......@@ -116,7 +116,16 @@ MirrorBoundaryCondition<TImage>
{
if (boundary_offset[i] != 0)
{
ptr += boundary_offset[i] * offset_table[i];
// If the neighborhood overlaps on the low edge, then wrap from the
// high edge of the image.
if (point_index[i] < static_cast<OffsetValueType>(iterator->GetRadius(i)))
{
ptr += boundary_offset[i] * offset_table[i];
}
else // wrap from the low side of the image
{
ptr -= boundary_offset[i] * offset_table[i];
}
}
}
......
......@@ -15,8 +15,8 @@
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __otbUnaryFunctorNeighborhoodVectorImageFilter_h
#define __otbUnaryFunctorNeighborhoodVectorImageFilter_h
#ifndef __otbUnaryFunctorNeighborhoodImageFilter_h
#define __otbUnaryFunctorNeighborhoodImageFilter_h
#include "itkInPlaceImageFilter.h"
#include "itkImageRegionIteratorWithIndex.h"
......@@ -24,8 +24,8 @@
#include "itkProcessObject.h"
namespace otb {
/** \class UnaryFunctorNeighborhoodVectorImageFilter
* \brief Implements neighborhood-wise generic operation of image beeing vector images.
/** \class UnaryFunctorNeighborhoodImageFilter
* \brief Implements neighborhood-wise generic operation on image
*
* This class is parameterized over the input image type
* and the type of the output image. It is also parameterized by the
......@@ -34,12 +34,12 @@ namespace otb {
* \ingroup IntensityImageFilters Multithreaded
*/
template <class TInputImage, class TOutputImage, class TFunction >
class ITK_EXPORT UnaryFunctorNeighborhoodVectorImageFilter
class ITK_EXPORT UnaryFunctorNeighborhoodImageFilter
: public itk::InPlaceImageFilter<TInputImage,TOutputImage>
{
public:
/** Standard class typedefs. */
typedef UnaryFunctorNeighborhoodVectorImageFilter Self;
typedef UnaryFunctorNeighborhoodImageFilter Self;
typedef itk::InPlaceImageFilter<TInputImage,TOutputImage > Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
......@@ -48,7 +48,7 @@ public:
itkNewMacro(Self);
/** Run-time type information (and related methods). */
itkTypeMacro(UnaryFunctorNeighborhoodVectorImageFilter,InPlaceImageFilter);
itkTypeMacro(UnaryFunctorNeighborhoodImageFilter,InPlaceImageFilter);
/** Some convenient typedefs. */
......@@ -97,17 +97,21 @@ public:
this->Modified();
}
typedef itk::ConstNeighborhoodIterator<TInputImage> NeighborhoodIteratorType;
typedef typename NeighborhoodIteratorType::RadiusType RadiusType;
typedef unsigned char RadiusSizeType;
protected:
UnaryFunctorNeighborhoodVectorImageFilter();
virtual ~UnaryFunctorNeighborhoodVectorImageFilter() {};
/** UnaryFunctorNeighborhoodVectorImageFilter can be implemented as a multithreaded filter.
/**
* Constructor
*/
UnaryFunctorNeighborhoodImageFilter();
/**
* Destructor
*/
virtual ~UnaryFunctorNeighborhoodImageFilter() {};
/** UnaryFunctorNeighborhoodImageFilter can be implemented as a multithreaded filter.
* Therefore, this implementation provides a ThreadedGenerateData() routine
* which is called for each processing thread. The output image data is
* allocated automatically by the superclass prior to calling
......@@ -119,9 +123,18 @@ protected:
* ImageToImageFilter::GenerateData() */
virtual void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId );
/**
* Pad the input requested region by radius
*/
virtual void GenerateInputRequestedRegion(void);
/**
* Allocate the output buffer before calling the ThreadedGenerateData.
*/
/* virtual void BeforeThreadedGenerateData(void); */
private:
UnaryFunctorNeighborhoodVectorImageFilter(const Self&); //purposely not implemented
UnaryFunctorNeighborhoodImageFilter(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
unsigned int m_Radius;
......@@ -131,7 +144,7 @@ private:
} // namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbUnaryFunctorNeighborhoodVectorImageFilter.txx"
#include "otbUnaryFunctorNeighborhoodImageFilter.txx"
#endif
......
......@@ -15,37 +15,87 @@
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef _otbUnaryFunctorNeighborhoodVectorImageFilter_txx
#define _otbUnaryFunctorNeighborhoodVectorImageFilter_txx
#ifndef _otbUnaryFunctorNeighborhoodImageFilter_txx
#define _otbUnaryFunctorNeighborhoodImageFilter_txx
#include "otbUnaryFunctorNeighborhoodVectorImageFilter.h"
#include "otbUnaryFunctorNeighborhoodImageFilter.h"
#include "itkImageRegionIterator.h"
#include "itkConstNeighborhoodIterator.h"
#include "itkNeighborhoodAlgorithm.h"
#include "itkProgressReporter.h"
#include "otbMirrorBoundaryCondition.h"
#include "itkZeroFluxNeumannBoundaryCondition.h"
namespace otb
{
/**
* Constructor
*/
template <class TInputImage, class TOutputImage, class TFunction >
UnaryFunctorNeighborhoodVectorImageFilter<TInputImage,TOutputImage,TFunction>
::UnaryFunctorNeighborhoodVectorImageFilter()
UnaryFunctorNeighborhoodImageFilter<TInputImage,TOutputImage,TFunction>
::UnaryFunctorNeighborhoodImageFilter()
{
this->SetNumberOfRequiredInputs( 1 );
this->InPlaceOff();
m_Radius = 1;
}
template <class TInputImage, class TOutputImage, class TFunction >
void
UnaryFunctorNeighborhoodImageFilter<TInputImage,TOutputImage,TFunction>
::GenerateInputRequestedRegion()
{
// call the superclass' implementation of this method
Superclass::GenerateInputRequestedRegion();
// get pointers to the input and output
typename Superclass::InputImagePointer inputPtr =
const_cast< TInputImage * >( this->GetInput());
typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
if ( !inputPtr || !outputPtr )
{
return;
}
// get a copy of the input requested region (should equal the output
// requested region)
typename TInputImage::RegionType inputRequestedRegion;
inputRequestedRegion = inputPtr->GetRequestedRegion();
// pad the input requested region by the operator radius
inputRequestedRegion.PadByRadius( m_Radius );
// crop the input requested region at the input's largest possible region
if ( inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()) )
{
inputPtr->SetRequestedRegion( inputRequestedRegion );
return;
}
else
{
// Couldn't crop the region (requested region is outside the largest
// possible region). Throw an exception.
// store what we tried to request (prior to trying to crop)
inputPtr->SetRequestedRegion( inputRequestedRegion );
// build an exception
itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
itk::OStringStream msg;
msg << this->GetNameOfClass()
<< "::GenerateInputRequestedRegion()";
e.SetLocation(msg.str().c_str());
e.SetDescription("Requested region is (at least partially) outside the largest possible region.");
e.SetDataObject(inputPtr);
throw e;
}
}
/**
* ThreadedGenerateData Performs the neighborhood-wise operation
*/
template <class TInputImage, class TOutputImage, class TFunction >
void
UnaryFunctorNeighborhoodVectorImageFilter<TInputImage, TOutputImage, TFunction>
UnaryFunctorNeighborhoodImageFilter<TInputImage, TOutputImage, TFunction>
::ThreadedGenerateData( const OutputImageRegionType &outputRegionForThread, int threadId)
{
itk::ZeroFluxNeumannBoundaryCondition<TInputImage> nbc;
......@@ -53,31 +103,49 @@ UnaryFunctorNeighborhoodVectorImageFilter<TInputImage, TOutputImage, TFunction>
RadiusType r;
r.Fill(m_Radius);
NeighborhoodIteratorType neighInputIt;
// This is the main difference from UnaryFunctorNeighborhoodVectorImageFilter<TInputImage, TOutputImage, TFunction>::ThreadedGenerateData( const OutputImageRegionType &outputRegionForThread, int threadId)
OutputImagePointer outputPtr = this->GetOutput();
outputPtr->SetNumberOfComponentsPerPixel( inputPtr->GetNumberOfComponentsPerPixel() );
outputPtr->Allocate();
itk::ImageRegionIterator<TOutputImage> outputIt;
// Find the data-set boundary "faces"
typedef typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<InputImageType> TypeFace;
typename TypeFace::FaceListType::iterator fit;
typename TypeFace::FaceListType faceList;
TypeFace bC;
typedef typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<InputImageType> TypeFace;
typename TypeFace::FaceListType::iterator fit;
typename TypeFace::FaceListType faceList;
TypeFace bC;
faceList = bC( inputPtr, outputRegionForThread, r );
// support progress methods/callbacks
itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
fit=faceList.begin();
NeighborhoodIteratorType neighInputIt( r, inputPtr, outputRegionForThread );
neighInputIt.OverrideBoundaryCondition( &nbc );
neighInputIt.GoToBegin();
outputIt = itk::ImageRegionIterator<TOutputImage> ( outputPtr,outputRegionForThread );
outputIt.GoToBegin();
while ( !outputIt.IsAtEnd() )
{
outputIt.Set( m_Functor( neighInputIt ) );
++neighInputIt;
++outputIt;
progress.CompletedPixel();
}
++fit;
// Process each of the boundary faces.
// Center first and then left, right, up, down borders
for ( fit=faceList.begin(); fit != faceList.end(); ++fit )
for (; fit != faceList.end(); ++fit )
{
NeighborhoodIteratorType neighInputIt( r, inputPtr, *fit );
neighInputIt=NeighborhoodIteratorType( r, inputPtr, *fit );
neighInputIt.OverrideBoundaryCondition( &nbc );
neighInputIt.GoToBegin();
......
......@@ -36,12 +36,12 @@ namespace otb
* \par
*
* It provides a geodesic decomposition of the input image, with the following scheme.
* Let \f$f_0\f$ denote the input image, \$f\stackrel{\smile}{\mu}_{N}(f)\f$ denote
* the convex membership function, \$f\stackrel{\frown}{\mu}_{N}(f) \f$ denote the concave
membership function and \f$\psi_{N}(f)\f$ denote the leveling function, for a given radius \f$ N \f$
as defined in the documentation of the \class{GeodesicMorphologyDecompositionImageFilter}.
* Let \f$f_0\f$ denote the input image,\f$\stackrel{\smile}{\mu}_{N}(f)\f$ denote
* the convex membership function, \f$ \stackrel{\frown}{\mu}_{N}(f) \f$ denote the concave
* membership function and \f$\psi_{N}(f)\f$ denote the leveling function, for a given radius \f$ N \f$
* as defined in the documentation of the GeodesicMorphologyDecompositionImageFilter .
* Let \f$[N_{1},\ldots,N_{n}]\f$ denote a range of increasing radius (or scales). The iterative
* decomposition is defined as follow:
* decomposition is defined as follows:
*
* \f[
* f_{n} = \psi_{N_{n}}(f_{n-1})
......
......@@ -25,7 +25,7 @@
#include "itkNumericTraits.h"
#include <vector>
#include "itkConstNeighborhoodIterator.h"
#include "otbUnaryFunctorNeighborhoodVectorImageFilter.h"
#include "otbUnaryFunctorNeighborhoodImageFilter.h"
#include "itkVariableSizeMatrix.h"
#include "otbAtmosphericRadiativeTerms.h"
......@@ -119,9 +119,9 @@ namespace otb
*/
template <class TInputImage, class TOutputImage>
class ITK_EXPORT SurfaceAdjencyEffect6SCorrectionSchemeFilter :
public UnaryFunctorNeighborhoodVectorImageFilter< TInputImage,
TOutputImage,
ITK_TYPENAME Functor::ComputeNeighborhoodContributionFunctor< itk::ConstNeighborhoodIterator<TInputImage>,
public UnaryFunctorNeighborhoodImageFilter< TInputImage,
TOutputImage,
ITK_TYPENAME Functor::ComputeNeighborhoodContributionFunctor< itk::ConstNeighborhoodIterator<TInputImage>,
ITK_TYPENAME TOutputImage::PixelType > >
{
public:
......@@ -131,7 +131,7 @@ public:
/** "typedef" for standard classes. */
typedef SurfaceAdjencyEffect6SCorrectionSchemeFilter Self;
typedef UnaryFunctorNeighborhoodVectorImageFilter< TInputImage, TOutputImage, FunctorType > Superclass;
typedef UnaryFunctorNeighborhoodImageFilter< TInputImage, TOutputImage, FunctorType > Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
......@@ -143,7 +143,7 @@ public:
itkNewMacro(Self);
/** return class name. */
itkTypeMacro(SurfaceAdjencyEffect6SCorrectionSchemeFilter, UnaryFunctorNeighborhoodVectorImageFilter);
itkTypeMacro(SurfaceAdjencyEffect6SCorrectionSchemeFilter, UnaryFunctorNeighborhoodImageFilter);
/** Extract input and output images dimensions.*/
itkStaticConstMacro( InputImageDimension, unsigned int, TInputImage::ImageDimension);
......
......@@ -439,18 +439,18 @@ ADD_TEST(coTvDrawPatFilter ${COMMON_TESTS6}
${TEMP}/coTvDrawPathFilterOutput.png
)
# ------- otb::UnaryFunctorNeighborhoodVectorImageFilter ----------------------
ADD_TEST(coTuUnaryFunctorNeighborhoodVectorImageFilterNew ${COMMON_TESTS6}
otbUnaryFunctorNeighborhoodVectorImageFilterNew
# ------- otb::UnaryFunctorNeighborhoodImageFilter ----------------------
ADD_TEST(coTuUnaryFunctorNeighborhoodImageFilterNew ${COMMON_TESTS6}
otbUnaryFunctorNeighborhoodImageFilterNew
)
ADD_TEST(coTvUnaryFunctorNeighborhoodVectorImageFilter ${COMMON_TESTS6}
ADD_TEST(coTvUnaryFunctorNeighborhoodImageFilter ${COMMON_TESTS6}
--compare-image ${TOL}
${INPUTDATA}/poupees_sub.png # copie the input image
${TEMP}/coTvUnaryFunctorNeighborhoodVectorImageFilter.tif
otbUnaryFunctorNeighborhoodVectorImageFilter
${TEMP}/coTvUnaryFunctorNeighborhoodImageFilter.tif
otbUnaryFunctorNeighborhoodImageFilter
${INPUTDATA}/poupees_sub.png
${TEMP}/coTvUnaryFunctorNeighborhoodVectorImageFilter.tif
${TEMP}/coTvUnaryFunctorNeighborhoodImageFilter.tif
3
)
......@@ -534,8 +534,8 @@ otbDrawPathListFilterWithValue.cxx
otbPolyLineParametricPathWithValueNew.cxx
otbPolygonNew.cxx
otbPolygon.cxx
otbUnaryFunctorNeighborhoodVectorImageFilterNew.cxx
otbUnaryFunctorNeighborhoodVectorImageFilter.cxx
otbUnaryFunctorNeighborhoodImageFilterNew.cxx
otbUnaryFunctorNeighborhoodImageFilter.cxx
)
SET(BasicCommon_SRCS7
otbGenericInterpolateImageFunctionNew.cxx
......
......@@ -35,6 +35,6 @@ REGISTER_TEST(otbDrawPathFilterNew);
REGISTER_TEST(otbDrawPathFilter);
REGISTER_TEST(otbPolygonNew);
REGISTER_TEST(otbPolygon);
REGISTER_TEST(otbUnaryFunctorNeighborhoodVectorImageFilterNew);
REGISTER_TEST(otbUnaryFunctorNeighborhoodVectorImageFilter);
REGISTER_TEST(otbUnaryFunctorNeighborhoodImageFilterNew);
REGISTER_TEST(otbUnaryFunctorNeighborhoodImageFilter);
}
......@@ -49,9 +49,9 @@ int otbMirrorBoundaryConditionTest(int argc, char * argv[])
itk::OStringStream oss;
PixelType in,out;
for(unsigned int i = 0;i<rad[0];++i)
for(unsigned int i = 1;i<=rad[0];++i)
{
for(unsigned int j = 0;j<rad[1];++j)
for(unsigned int j = 1;j<=rad[1];++j)
{
off1[0] = -static_cast<int>(i);
off1[1] = -static_cast<int>(j);
......@@ -72,7 +72,6 @@ int otbMirrorBoundaryConditionTest(int argc, char * argv[])
}
ImageType::IndexType center;
center[0]=reader->GetOutput()->GetLargestPossibleRegion().GetSize()[0]/2;
center[1]=reader->GetOutput()->GetLargestPossibleRegion().GetSize()[1]/2;
......
......@@ -16,7 +16,6 @@ int otbOssimElevManagerTest(int argc,char* argv[])
}
const ossimFilename srtmDir(argv[1]);
//std::cout<<"ossimFilename.isDir(): "<<srtmDir.isDir()<<std::endl;
const char * outfname = argv[2];
typedef double PixelType;
......@@ -61,22 +60,7 @@ int otbOssimElevManagerTest(int argc,char* argv[])
ossimElevManager * elevManager = ossimElevManager::instance();
int error = elevManager->openDirectory(srtmDir);
//std::cout<<"ossim::isnan(ossim::nan()): "<<ossim::isnan(ossim::nan())<<std::endl;
//std::cout<<"Opening srtmDir : "<<error<<std::endl;
std::vector<ossimFilename> list;
elevManager->getOpenCellList(list);
//std::cout<<"Open cells: "<<std::endl;
for(std::vector<ossimFilename>::iterator it = list.begin();it!=list.end();++it)
{
//std::cout<<(*it)<<std::endl;
}
elevManager->openDirectory(srtmDir);
IteratorType it(image,image->GetLargestPossibleRegion());
......@@ -88,7 +72,7 @@ int otbOssimElevManagerTest(int argc,char* argv[])
ossimWorldPoint.lon=point[0];
ossimWorldPoint.lat=point[1];
double height = elevManager->getHeightAboveMSL(ossimWorldPoint);
//std::cout<<"Ground point: "<<point<<" value: "<<height<<" is coverered "<<elevManager->pointHasCoverage(ossimWorldPoint)<<" "<<" srtm data for point "<<elevManager->getCellFilenameForPoint(ossimWorldPoint)<<std::endl;
if (!ossim::isnan(height))
{
// Fill the image
......
Markdown is supported
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