Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Cresson Remi
SimpleExtractionTools
Commits
1bf5351a
Commit
1bf5351a
authored
Oct 14, 2021
by
Cresson Remi
Browse files
Merge branch 'master' of gitlab-ssh.irstea.fr:remi.cresson/SimpleExtractionTools
parents
be3c5d10
db2cc25e
Changes
5
Hide whitespace changes
Inline
Side-by-side
include/otbMeanResampleImageFilter.hxx
View file @
1bf5351a
...
...
@@ -43,15 +43,15 @@ MeanResampleImageFilter<TImage>
// The new output image has the same origin
ImagePointType
origin
=
inputImage
->
GetOrigin
();
origin
[
0
]
+=
0.5
*
inputImage
->
GetS
ignedS
pacing
()[
0
]
*
(
m_StepX
-
1
);
origin
[
1
]
+=
0.5
*
inputImage
->
GetS
ignedS
pacing
()[
1
]
*
(
m_StepY
-
1
);
origin
[
0
]
+=
0.5
*
inputImage
->
GetSpacing
()[
0
]
*
(
m_StepX
-
1
);
origin
[
1
]
+=
0.5
*
inputImage
->
GetSpacing
()[
1
]
*
(
m_StepY
-
1
);
outputPtr
->
SetOrigin
(
origin
);
// New spacing for the output image
ImageSpacingType
spacing
=
inputImage
->
GetS
ignedS
pacing
();
ImageSpacingType
spacing
=
inputImage
->
GetSpacing
();
spacing
[
0
]
*=
m_StepX
;
spacing
[
1
]
*=
m_StepY
;
outputPtr
->
SetS
ignedS
pacing
(
spacing
);
outputPtr
->
SetSpacing
(
spacing
);
// New size for the output image
ImageRegionType
inRegion
=
inputImage
->
GetLargestPossibleRegion
();
...
...
include/otbMosaicFromDirectoryHandler.h
0 → 100644
View file @
1bf5351a
/*
* otbMosaicFromDirectoryHandler.h
*
* Created on: 24 mars 2016
* Author: cresson
*/
#ifndef MODULES_REMOTE_OTB_MosaicFromDirectoryHandler_INCLUDE_OTBMosaicFromDirectoryHandler_H_
#define MODULES_REMOTE_OTB_MosaicFromDirectoryHandler_INCLUDE_OTBMosaicFromDirectoryHandler_H_
#include "itkImageSource.h"
#include "itkExceptionObject.h"
#include "itkImageRegion.h"
#include "otbStreamingSimpleMosaicFilter.h"
#include "otbImageFileReader.h"
#include "itkDirectory.h"
#include "otbImageIOBase.h"
#include "otbImageIOFactory.h"
#include "otbMultiToMonoChannelExtractROI.h"
#include "otbGenericRSResampleImageFilter.h"
#include "itkNearestNeighborInterpolateImageFunction.h"
namespace
otb
{
/** \class MosaicFromDirectoryHandler
* \brief This ImageSource produces an otb::image from multiple rasters
* stored in the m_Directory.
* TODO: Currently only .tif extension is supported. Might be nice to change it.
*
*
* \ingroup OTBMosaic
*
*/
template
<
class
TOutputImage
,
class
TReferenceImage
>
class
ITK_EXPORT
MosaicFromDirectoryHandler
:
public
itk
::
ImageSource
<
TOutputImage
>
{
public:
/** Standard class typedefs. */
typedef
MosaicFromDirectoryHandler
Self
;
typedef
itk
::
ImageSource
<
TOutputImage
>
Superclass
;
typedef
itk
::
SmartPointer
<
Self
>
Pointer
;
/** Method for creation through the object factory. */
itkNewMacro
(
Self
);
/** Run-time type information (and related methods). */
itkTypeMacro
(
MosaicFromDirectoryHandler
,
ImageSource
);
/** Typedefs for output image */
typedef
typename
TOutputImage
::
SizeType
SizeType
;
typedef
typename
TOutputImage
::
IndexType
IndexType
;
typedef
typename
TOutputImage
::
SpacingType
SpacingType
;
typedef
typename
TOutputImage
::
PointType
PointType
;
typedef
typename
TOutputImage
::
RegionType
ImageRegionType
;
typedef
typename
TOutputImage
::
InternalPixelType
OutputImagePixelType
;
/** Typedefs for mosaic filter */
typedef
otb
::
VectorImage
<
OutputImagePixelType
>
InternalMaskImageType
;
typedef
otb
::
StreamingSimpleMosaicFilter
<
InternalMaskImageType
>
MosaicFilterType
;
typedef
typename
MosaicFilterType
::
Pointer
MosaicFilterPointerType
;
/** Typedefs for image reader */
typedef
otb
::
ImageFileReader
<
InternalMaskImageType
>
ReaderType
;
typedef
typename
ReaderType
::
Pointer
ReaderPointerType
;
/** Typedefs for casting the image */
typedef
otb
::
MultiToMonoChannelExtractROI
<
OutputImagePixelType
,
OutputImagePixelType
>
CastFilterType
;
typedef
typename
CastFilterType
::
Pointer
CastFilterPointerType
;
/** Typedefs for image reprojection */
typedef
otb
::
GenericRSResampleImageFilter
<
InternalMaskImageType
,
InternalMaskImageType
>
ResamplerType
;
typedef
typename
ResamplerType
::
Pointer
ResamplerPointerType
;
typedef
itk
::
NearestNeighborInterpolateImageFunction
<
InternalMaskImageType
,
double
>
NNInterpolatorType
;
/** Input directory accessors */
itkGetMacro
(
Directory
,
std
::
string
);
itkSetMacro
(
Directory
,
std
::
string
);
/** Output parameters setters */
itkSetMacro
(
OutputSpacing
,
SpacingType
);
itkSetMacro
(
OutputSize
,
SizeType
);
itkSetMacro
(
OutputOrigin
,
PointType
);
void
SetReferenceImage
(
TReferenceImage
*
ptr
){
m_RefImagePtr
=
ptr
;}
itkSetMacro
(
UseReferenceImage
,
bool
);
/** Prepare image allocation at the first call of the pipeline processing */
virtual
void
GenerateOutputInformation
(
void
);
/** Does the real work. */
virtual
void
GenerateData
();
protected:
MosaicFromDirectoryHandler
();
virtual
~
MosaicFromDirectoryHandler
();
// Masks directory
std
::
string
m_Directory
;
// Output parameters
SpacingType
m_OutputSpacing
;
SizeType
m_OutputSize
;
PointType
m_OutputOrigin
;
// Internal filters
MosaicFilterPointerType
mosaicFilter
;
CastFilterPointerType
castFilter
;
std
::
vector
<
ReaderPointerType
>
readers
;
std
::
vector
<
ResamplerPointerType
>
resamplers
;
// Reference image pointer
bool
m_UseReferenceImage
;
TReferenceImage
*
m_RefImagePtr
;
private:
MosaicFromDirectoryHandler
(
const
Self
&
);
//purposely not implemented
void
operator
=
(
const
Self
&
);
//purposely not implemented
};
}
//namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include <otbMosaicFromDirectoryHandler.txx>
#endif
#endif
/* MODULES_REMOTE_OTB_MosaicFromDirectoryHandler_INCLUDE_OTBMosaicFromDirectoryHandler_H_ */
include/otbMosaicFromDirectoryHandler.txx
0 → 100644
View file @
1bf5351a
/*
* otbMosaicFromDirectoryHandler.hxx
*
* Created on: 24 mars 2016
* Author: cresson
*/
#ifndef MODULES_REMOTE_OTB_MosaicFromDirectoryHandler_INCLUDE_OTBMosaicFromDirectoryHandler_HXX_
#define MODULES_REMOTE_OTB_MosaicFromDirectoryHandler_INCLUDE_OTBMosaicFromDirectoryHandler_HXX_
#include "otbMosaicFromDirectoryHandler.h"
#include "otbImageFileWriter.h"
namespace otb
{
template <class TOutputImage, class TReferenceImage>
MosaicFromDirectoryHandler<TOutputImage, TReferenceImage>
::MosaicFromDirectoryHandler()
{
mosaicFilter = MosaicFilterType::New();
castFilter = CastFilterType::New();
m_UseReferenceImage = false;
m_RefImagePtr = 0;
}
template <class TOutputImage, class TReferenceImage>
MosaicFromDirectoryHandler<TOutputImage, TReferenceImage>
::~MosaicFromDirectoryHandler()
{
}
template <class TOutputImage, class TReferenceImage>
void
MosaicFromDirectoryHandler<TOutputImage, TReferenceImage>
::GenerateOutputInformation()
{
if (m_Directory[m_Directory.size()-1] != '/')
{
// If not, we add the separator
m_Directory.append("/");
}
// Get the list of files in the directory
itk::Directory::Pointer dir = itk::Directory::New();
if (!dir->Load(m_Directory.c_str()))
{
itkExceptionMacro(<< "Unable to browse directory " << m_Directory);
}
// Instanciate a new mosaic filter
mosaicFilter = MosaicFilterType::New();
mosaicFilter->SetGlobalWarningDisplay(false);
readers.clear();
resamplers.clear();
// Browse the directory
for (unsigned int i = 0; i < dir->GetNumberOfFiles(); i++)
{
const char *filename = dir->GetFile(i);
std::string sfilename(filename);
sfilename = m_Directory + sfilename;
// Try to read the file
otb::ImageIOBase::Pointer imageIO =
otb::ImageIOFactory::CreateImageIO(sfilename.c_str(),otb::ImageIOFactory::ReadMode);
if( imageIO.IsNotNull() )
{
// create reader
ReaderPointerType reader = ReaderType::New();
reader->SetFileName(sfilename);
reader->UpdateOutputInformation();
readers.push_back(reader);
if (m_UseReferenceImage)
{
ResamplerPointerType resampler = ResamplerType::New();
resampler->SetInput(reader->GetOutput());
// Setup transform through projRef and Keywordlist
SpacingType defSpacing = m_RefImagePtr->GetSignedSpacing();
defSpacing[0] *= 10;
defSpacing[1] *= 10;
resampler->SetDisplacementFieldSpacing(defSpacing);
resampler->SetInputKeywordList(reader->GetOutput()->GetImageKeywordlist());
resampler->SetInputProjectionRef(reader->GetOutput()->GetProjectionRef());
resampler->SetOutputKeywordList(m_RefImagePtr->GetImageKeywordlist());
resampler->SetOutputProjectionRef(m_RefImagePtr->GetProjectionRef());
resampler->SetOutputOrigin(m_RefImagePtr->GetOrigin());
resampler->SetOutputSpacing(m_RefImagePtr->GetSignedSpacing());
resampler->SetOutputSize(m_RefImagePtr->GetLargestPossibleRegion().GetSize());
resampler->SetOutputStartIndex(m_RefImagePtr->GetLargestPossibleRegion().GetIndex());
typename NNInterpolatorType::Pointer interpolator = NNInterpolatorType::New();
resampler->SetInterpolator(interpolator);
resamplers.push_back(resampler);
mosaicFilter->PushBackInput(resampler->GetOutput());
}
else
{
mosaicFilter->PushBackInput(reader->GetOutput());
}
}
else
{
// itkWarningMacro(<<"Unable to read file " << sfilename);
}
}
if (m_UseReferenceImage)
{
mosaicFilter->SetOutputOrigin(m_RefImagePtr->GetOrigin());
mosaicFilter->SetOutputSpacing(m_RefImagePtr->GetSignedSpacing());
mosaicFilter->SetOutputSize(m_RefImagePtr->GetLargestPossibleRegion().GetSize());
}
else
{
mosaicFilter->SetOutputOrigin(m_OutputOrigin);
mosaicFilter->SetOutputSpacing(m_OutputSpacing);
mosaicFilter->SetOutputSize(m_OutputSize);
}
mosaicFilter->SetAutomaticOutputParametersComputation(false);
castFilter->SetInput(mosaicFilter->GetOutput());
castFilter->GraftOutput( this->GetOutput() );
castFilter->UpdateOutputInformation();
this->GraftOutput( castFilter->GetOutput() );
}
template <class TOutputImage, class TReferenceImage>
void
MosaicFromDirectoryHandler<TOutputImage, TReferenceImage>
::GenerateData()
{
castFilter->GraftOutput( this->GetOutput() );
castFilter->Update();
this->GraftOutput( castFilter->GetOutput() );
}
} // end namespace otb
#endif /* MODULES_REMOTE_OTB_MosaicFromDirectoryHandler_INCLUDE_OTBMosaicFromDirectoryHandler_HXX_ */
include/otbVectorDataToLabelImageCustomFilter.hxx
View file @
1bf5351a
...
...
@@ -119,7 +119,7 @@ VectorDataToLabelImageCustomFilter<TVectorData, TOutputImage>
::
SetOutputParametersFromImage
(
const
ImageBaseType
*
src
)
{
this
->
SetOutputOrigin
(
src
->
GetOrigin
()
);
this
->
SetOutputS
ignedS
pacing
(
src
->
GetSignedSpacing
()
);
this
->
SetOutputSpacing
(
src
->
GetSignedSpacing
()
);
this
->
SetOutputSize
(
src
->
GetLargestPossibleRegion
().
GetSize
()
);
otb
::
ImageMetadataInterfaceBase
::
Pointer
imi
=
otb
::
ImageMetadataInterfaceFactory
::
CreateIMI
(
src
->
GetMetaDataDictionary
());
this
->
SetOutputProjectionRef
(
imi
->
GetProjectionRef
());
...
...
@@ -144,7 +144,7 @@ VectorDataToLabelImageCustomFilter<TVectorData, TOutputImage>
outputPtr
->
SetLargestPossibleRegion
(
outputLargestPossibleRegion
);
// Set spacing and origin
outputPtr
->
SetS
ignedS
pacing
(
m_OutputSpacing
);
outputPtr
->
SetSpacing
(
m_OutputSpacing
);
outputPtr
->
SetOrigin
(
m_OutputOrigin
);
itk
::
MetaDataDictionary
&
dict
=
outputPtr
->
GetMetaDataDictionary
();
...
...
@@ -295,8 +295,8 @@ VectorDataToLabelImageCustomFilter<TVectorData, TOutputImage>::GenerateData()
this
->
GetOutput
()
->
TransformIndexToPhysicalPoint
(
bufferIndexOrigin
,
bufferOrigin
);
geoTransform
[
0
]
=
bufferOrigin
[
0
];
geoTransform
[
3
]
=
bufferOrigin
[
1
];
geoTransform
[
1
]
=
this
->
GetOutput
()
->
GetS
ignedS
pacing
()[
0
];
geoTransform
[
5
]
=
this
->
GetOutput
()
->
GetS
ignedS
pacing
()[
1
];
geoTransform
[
1
]
=
this
->
GetOutput
()
->
GetSpacing
()[
0
];
geoTransform
[
5
]
=
this
->
GetOutput
()
->
GetSpacing
()[
1
];
// FIXME: Here component 1 and 4 should be replaced by the orientation parameters
geoTransform
[
2
]
=
0.
;
...
...
otb-module.cmake
View file @
1bf5351a
...
...
@@ -8,6 +8,7 @@ otb_module(SimpleExtractionTools
OTBImageBase
OTBImageIO
OTBStatistics
OTBMosaic
TEST_DEPENDS
OTBTestKernel
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment