Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
otb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Youssefi
otb
Commits
f86d0c77
Commit
f86d0c77
authored
14 years ago
by
Otmane Lahlou
Browse files
Options
Downloads
Patches
Plain Diff
ENH : make the otbShiftScaleSampleListFilter inherits from ListSampleToListSampleFilter
parent
4559ae39
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Code/Learning/otbShiftScaleSampleListFilter.h
+11
-38
11 additions, 38 deletions
Code/Learning/otbShiftScaleSampleListFilter.h
Code/Learning/otbShiftScaleSampleListFilter.txx
+44
-137
44 additions, 137 deletions
Code/Learning/otbShiftScaleSampleListFilter.txx
with
55 additions
and
175 deletions
Code/Learning/otbShiftScaleSampleListFilter.h
+
11
−
38
View file @
f86d0c77
...
...
@@ -18,9 +18,8 @@
#ifndef __otbShiftScaleSampleListFilter_h
#define __otbShiftScaleSampleListFilter_h
#include
"itkProcessObject.h"
#include
"itkDataObject.h"
#include
"itkDataObjectDecorator.h"
#include
"otbListSampleToListSampleFilter.h"
namespace
otb
{
namespace
Statistics
{
...
...
@@ -36,24 +35,22 @@ namespace Statistics {
*
* Shifts and scales can be set via the SetShift() and SetScales() methods.
*
* This filter provide pipeline support for itk::Statistics::ListSample via itk::DataObjectDecorator for
* both the input and the output sample list.
*
* \sa ImageToListAdaptor
* \sa ListSampleToListSampleFilter
*/
template
<
class
TInputSampleList
,
class
TOutputSampleList
=
TInputSampleList
>
class
ITK_EXPORT
ShiftScaleSampleListFilter
:
public
itk
::
ProcessObject
public
otb
::
Statistics
::
ListSampleToListSampleFilter
<
TInputSampleList
,
TOutputSampleList
>
{
public:
/** Standard class typedefs */
typedef
ShiftScaleSampleListFilter
Self
;
typedef
itk
::
ProcessObject
Superclass
;
typedef
ShiftScaleSampleListFilter
Self
;
typedef
otb
::
Statistics
::
ListSampleToListSampleFilter
<
TInputSampleList
,
TOutputSampleList
>
Superclass
;
typedef
itk
::
SmartPointer
<
Self
>
Pointer
;
typedef
itk
::
SmartPointer
<
const
Self
>
ConstPointer
;
/** Run-time type information (and related methods). */
itkTypeMacro
(
ShiftScaleSampleListFilter
,
itk
::
ProcessObject
);
itkTypeMacro
(
ShiftScaleSampleListFilter
,
otb
::
Statistics
::
ListSampleToListSampleFilter
);
/** Method for creation through the object factory. */
itkNewMacro
(
Self
);
...
...
@@ -71,13 +68,9 @@ public:
typedef
typename
OutputSampleListType
::
ConstPointer
OutputSampleListConstPointer
;
typedef
typename
OutputSampleListType
::
MeasurementVectorType
OutputMeasurementVectorType
;
typedef
typename
OutputMeasurementVectorType
::
ValueType
OutputValueType
;
/** ListSample is not a DataObject, we need to decorate it to push it down
* a ProcessObject's pipeline */
typedef
itk
::
DataObject
::
Pointer
DataObjectPointer
;
typedef
itk
::
DataObjectDecorator
<
InputSampleListType
>
InputSampleListObjectType
;
typedef
itk
::
DataObjectDecorator
<
OutputSampleListType
>
OutputSampleListObjectType
;
typedef
typename
Superclass
::
InputSampleList
Object
Type
InputSampleListObjectType
;
typedef
typename
Superclass
::
OutputSampleList
Object
Type
OutputSampleListObjectType
;
/** Set/Get the Shifts for this sample list */
itkSetMacro
(
Shifts
,
InputMeasurementVectorType
);
...
...
@@ -87,30 +80,10 @@ public:
itkSetMacro
(
Scales
,
InputMeasurementVectorType
);
itkGetMacro
(
Scales
,
InputMeasurementVectorType
);
/** Method to set/get the input list sample */
void
SetInput
(
const
InputSampleListType
*
inputPtr
);
void
SetInput
(
const
InputSampleListObjectType
*
inputPtr
);
/** Returns the input sample list */
const
InputSampleListType
*
GetInputSampleList
()
const
;
/** Returns the input sample list as a data object */
const
InputSampleListObjectType
*
GetInput
()
const
;
/** Returns the output sample list */
OutputSampleListType
*
GetOutputSampleList
();
/** Returns the output sample list as a data object */
OutputSampleListObjectType
*
GetOutput
();
protected:
/** This method causes the filter to generate its output. */
virtual
void
GenerateData
();
/** Standard itk::ProcessObject subclass method. */
virtual
DataObjectPointer
MakeOutput
(
unsigned
int
idx
);
ShiftScaleSampleListFilter
();
virtual
~
ShiftScaleSampleListFilter
()
{}
void
PrintSelf
(
std
::
ostream
&
os
,
itk
::
Indent
indent
)
const
;
...
...
@@ -125,7 +98,7 @@ private:
/** The vector of Scales */
InputMeasurementVectorType
m_Scales
;
};
// end of class
ImageToListGenerato
r
};
// end of class
ShiftScaleSampleListFilte
r
}
// end of namespace Statistics
}
// end of namespace otb
...
...
This diff is collapsed.
Click to expand it.
Code/Learning/otbShiftScaleSampleListFilter.txx
+
44
−
137
View file @
f86d0c77
...
...
@@ -26,164 +26,71 @@ namespace Statistics {
template < class TInputSampleList, class TOutputSampleList >
ShiftScaleSampleListFilter<TInputSampleList,TOutputSampleList>
::ShiftScaleSampleListFilter()
{
this->SetNumberOfRequiredInputs(1);
this->SetNumberOfRequiredOutputs(1);
// Generate the output sample list
typename OutputSampleListObjectType::Pointer outputPtr =
static_cast< OutputSampleListObjectType * >(this->MakeOutput(0).GetPointer());
this->ProcessObject::SetNthOutput(0, outputPtr.GetPointer());
}
template < class TInputSampleList, class TOutputSampleList >
typename ShiftScaleSampleListFilter<TInputSampleList,TOutputSampleList>
::DataObjectPointer
ShiftScaleSampleListFilter<TInputSampleList,TOutputSampleList>
::MakeOutput(unsigned int itkNotUsed(idx))
{
typename OutputSampleListObjectType::Pointer outputPtr = OutputSampleListObjectType::New();
OutputSampleListPointer outputSampleList = OutputSampleListType::New();
outputPtr->Set(outputSampleList);
return static_cast<DataObjectPointer>(outputPtr);
}
template < class TInputSampleList, class TOutputSampleList >
void
ShiftScaleSampleListFilter<TInputSampleList,TOutputSampleList>
::SetInput( const InputSampleListType * input )
{
typename InputSampleListObjectType::Pointer inputPtr = InputSampleListObjectType::New();
inputPtr->Set(input);
this->SetInput(inputPtr);
}
template < class TInputSampleList, class TOutputSampleList >
void
ShiftScaleSampleListFilter<TInputSampleList,TOutputSampleList>
::SetInput( const InputSampleListObjectType * inputPtr )
{
// Process object is not const-correct so the const_cast is required here
this->ProcessObject::SetNthInput(0,
const_cast< InputSampleListObjectType* >( inputPtr ) );
}
template < class TInputSampleList, class TOutputSampleList >
const typename ShiftScaleSampleListFilter<TInputSampleList,TOutputSampleList>
::InputSampleListObjectType *
ShiftScaleSampleListFilter<TInputSampleList,TOutputSampleList>
::GetInput() const
{
if (this->GetNumberOfInputs() < 1)
{
return 0;
}
return static_cast<const InputSampleListObjectType * >
(this->ProcessObject::GetInput(0) );
}
template < class TInputSampleList, class TOutputSampleList >
const typename ShiftScaleSampleListFilter<TInputSampleList,TOutputSampleList>
::InputSampleListType *
ShiftScaleSampleListFilter<TInputSampleList,TOutputSampleList>
::GetInputSampleList() const
{
if (this->GetNumberOfInputs() < 1)
{
return 0;
}
typename InputSampleListObjectType::Pointer dataObjectPointer = static_cast<const InputSampleListObjectType * >
(this->ProcessObject::GetInput(0) );
return dataObjectPointer->Get();
}
template < class TInputSampleList, class TOutputSampleList >
typename ShiftScaleSampleListFilter<TInputSampleList,TOutputSampleList>
::OutputSampleListType *
ShiftScaleSampleListFilter<TInputSampleList,TOutputSampleList>
::GetOutputSampleList()
{
typename OutputSampleListObjectType::Pointer dataObjectPointer = static_cast<OutputSampleListObjectType * >
(this->ProcessObject::GetOutput(0) );
return const_cast<OutputSampleListType *>(dataObjectPointer->Get());
}
template < class TInputSampleList, class TOutputSampleList >
typename ShiftScaleSampleListFilter<TInputSampleList,TOutputSampleList>
::OutputSampleListObjectType *
ShiftScaleSampleListFilter<TInputSampleList,TOutputSampleList>
::GetOutput()
{
return static_cast<OutputSampleListObjectType * >
(this->ProcessObject::GetOutput(0) );
}
::ShiftScaleSampleListFilter(){}
template < class TInputSampleList, class TOutputSampleList >
void
ShiftScaleSampleListFilter<TInputSampleList,TOutputSampleList>
::GenerateData()
{
// Retrieve input and output pointers
typename InputSampleListObjectType::ConstPointer inputPtr = this->GetInput();
typename OutputSampleListObjectType::Pointer outputPtr = this->GetOutput();
{
// Retrieve input and output pointers
typename InputSampleListObjectType::ConstPointer inputPtr = this->GetInput();
typename OutputSampleListObjectType::Pointer outputPtr = this->GetOutput();
// Retrieve the ListSample
InputSampleListConstPointer inputSampleListPtr = inputPtr->Get();
OutputSampleListPointer outputSampleListPtr = const_cast<OutputSampleListType *>(outputPtr->Get());
// Retrieve the ListSample
InputSampleListConstPointer inputSampleListPtr = inputPtr->Get();
OutputSampleListPointer outputSampleListPtr = const_cast<OutputSampleListType *>(outputPtr->Get());
// Compute the 1/(sigma) vector
InputMeasurementVectorType invertedScales = m_Scales;
for(unsigned int idx = 0;idx < invertedScales.Size();++idx)
{
invertedScales[idx] = 1 / m_Scales[idx];
}
// Compute the 1/(sigma) vector
InputMeasurementVectorType invertedScales = m_Scales;
for(unsigned int idx = 0;idx < invertedScales.Size();++idx)
{
invertedScales[idx] = 1 / m_Scales[idx];
}
// Clear any previous output
outputSampleListPtr->Clear();
// Clear any previous output
outputSampleListPtr->Clear();
typename InputSampleListType::ConstIterator inputIt = inputSampleListPtr->Begin();
typename InputSampleListType::ConstIterator inputIt = inputSampleListPtr->Begin();
// Set-up progress reporting
itk::ProgressReporter progress(this,0,inputSampleListPtr->Size());
// Set-up progress reporting
itk::ProgressReporter progress(this,0,inputSampleListPtr->Size());
// Iterate on the InputSampleList
while(inputIt != inputSampleListPtr->End())
{
// Retrieve current input sample
InputMeasurementVectorType currentInputMeasurement = inputIt.GetMeasurementVector();
// Iterate on the InputSampleList
while(inputIt != inputSampleListPtr->End())
{
// Retrieve current input sample
InputMeasurementVectorType currentInputMeasurement = inputIt.GetMeasurementVector();
// Build current output sample
OutputMeasurementVectorType currentOutputMeasurement;
currentOutputMeasurement.SetSize(currentInputMeasurement.GetSize());
// Build current output sample
OutputMeasurementVectorType currentOutputMeasurement;
currentOutputMeasurement.SetSize(currentInputMeasurement.GetSize());
// Center and reduce each component
for(unsigned int idx = 0;idx < invertedScales.Size();++idx)
{
currentOutputMeasurement[idx] = static_cast<OutputValueType>(
(currentInputMeasurement[idx]-m_Shifts[idx])*invertedScales[idx]);
}
// Center and reduce each component
for(unsigned int idx = 0;idx < invertedScales.Size();++idx)
{
currentOutputMeasurement[idx] = static_cast<OutputValueType>(
(currentInputMeasurement[idx]-m_Shifts[idx])*invertedScales[idx]);
}
// Add the current output sample to the output SampleList
outputSampleListPtr->PushBack(currentOutputMeasurement);
// Add the current output sample to the output SampleList
outputSampleListPtr->PushBack(currentOutputMeasurement);
// Update progress
progress.CompletedPixel();
// Update progress
progress.CompletedPixel();
++inputIt;
}
}
++inputIt;
}
}
template < class TInputSampleList, class TOutputSampleList >
void
ShiftScaleSampleListFilter<TInputSampleList,TOutputSampleList>
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
// Call superclass implementation
Superclass::PrintSelf(os,indent);
}
{
// Call superclass implementation
Superclass::PrintSelf(os,indent);
}
} // End namespace Statistics
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment