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
Container Registry
Model registry
Operate
Environments
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
Sébastien Peillet
otb
Commits
250c996e
Commit
250c996e
authored
9 years ago
by
Guillaume Pasero
Browse files
Options
Downloads
Patches
Plain Diff
ENH: heavy use of Traits to support scalar images, fix the use of AccumulatorType
parent
b70f6ea5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Modules/IO/TestKernel/include/otbDifferenceImageFilter.h
+6
-5
6 additions, 5 deletions
Modules/IO/TestKernel/include/otbDifferenceImageFilter.h
Modules/IO/TestKernel/include/otbDifferenceImageFilter.txx
+35
-17
35 additions, 17 deletions
Modules/IO/TestKernel/include/otbDifferenceImageFilter.txx
with
41 additions
and
22 deletions
Modules/IO/TestKernel/include/otbDifferenceImageFilter.h
+
6
−
5
View file @
250c996e
...
...
@@ -45,7 +45,8 @@ public:
typedef
typename
OutputImageType
::
RegionType
OutputImageRegionType
;
typedef
typename
itk
::
NumericTraits
<
OutputPixelType
>::
RealType
RealType
;
typedef
typename
itk
::
NumericTraits
<
RealType
>::
AccumulateType
AccumulateType
;
typedef
typename
RealType
::
RealValueType
ScalarRealType
;
typedef
typename
itk
::
NumericTraits
<
OutputPixelType
>
::
ScalarRealType
ScalarRealType
;
/** Set the valid image input. This will be input 0. */
virtual
void
SetValidInput
(
const
InputImageType
*
validImage
);
...
...
@@ -65,7 +66,7 @@ public:
/** Get parameters of the difference image after execution. */
itkGetMacro
(
MeanDifference
,
RealType
);
itkGetMacro
(
TotalDifference
,
Real
Type
);
itkGetMacro
(
TotalDifference
,
Accumulate
Type
);
itkGetMacro
(
NumberOfPixelsWithDifferences
,
unsigned
long
);
protected:
...
...
@@ -94,12 +95,12 @@ protected:
ScalarRealType
m_DifferenceThreshold
;
RealType
m_MeanDifference
;
RealType
m_TotalDifference
;
AccumulateType
m_TotalDifference
;
unsigned
long
m_NumberOfPixelsWithDifferences
;
int
m_ToleranceRadius
;
std
::
vector
<
Real
Type
>
m_ThreadDifferenceSum
;
itk
::
Array
<
unsigned
long
>
m_ThreadNumberOfPixels
;
std
::
vector
<
Accumulate
Type
>
m_ThreadDifferenceSum
;
itk
::
Array
<
unsigned
long
>
m_ThreadNumberOfPixels
;
private
:
DifferenceImageFilter
(
const
Self
&
);
//purposely not implemented
...
...
This diff is collapsed.
Click to expand it.
Modules/IO/TestKernel/include/otbDifferenceImageFilter.txx
+
35
−
17
View file @
250c996e
...
...
@@ -7,6 +7,7 @@
#include "itkImageRegionIterator.h"
#include "itkNeighborhoodAlgorithm.h"
#include "itkProgressReporter.h"
#include "itkDefaultConvertPixelTraits.h"
namespace otb
{
...
...
@@ -26,8 +27,12 @@ DifferenceImageFilter<TInputImage, TOutputImage>
m_ToleranceRadius = 0;
// Initialize statistics about difference image.
m_MeanDifference.SetSize(0);
m_TotalDifference.SetSize(0);
itk::NumericTraits<RealType>::SetLength(
m_MeanDifference,
itk::DefaultConvertPixelTraits<RealType>::GetNumberOfComponents());
itk::NumericTraits<AccumulateType>::SetLength(
m_TotalDifference,
itk::DefaultConvertPixelTraits<RealType>::GetNumberOfComponents());
m_MeanDifference = itk::NumericTraits<RealType>::ZeroValue(m_MeanDifference);
m_TotalDifference = itk::NumericTraits<AccumulateType>::ZeroValue(m_TotalDifference);
m_NumberOfPixelsWithDifferences = 0;
...
...
@@ -89,12 +94,16 @@ DifferenceImageFilter<TInputImage, TOutputImage>
{
int numberOfThreads = this->GetNumberOfThreads();
m_MeanDifference.SetSize(this->GetInput(0)->GetNumberOfComponentsPerPixel());
m_TotalDifference.SetSize(this->GetInput(0)->GetNumberOfComponentsPerPixel());
itk::NumericTraits<RealType>::SetLength(
m_MeanDifference,
this->GetInput(0)->GetNumberOfComponentsPerPixel());
itk::NumericTraits<AccumulateType>::SetLength(
m_TotalDifference,
this->GetInput(0)->GetNumberOfComponentsPerPixel());
// Initialize statistics about difference image.
m_MeanDifference
.Fill(
itk::NumericTraits<
Scalar
RealType>::Zero);
m_TotalDifference
.Fill(
itk::NumericTraits<
ScalarReal
Type>::Zero);
m_MeanDifference
=
itk::NumericTraits<RealType>::Zero
Value(m_MeanDifference
);
m_TotalDifference
=
itk::NumericTraits<
Accumulate
Type>::Zero
Value(m_TotalDifference
);
m_NumberOfPixelsWithDifferences = 0;
// Resize the thread temporaries
...
...
@@ -175,17 +184,22 @@ DifferenceImageFilter<TInputImage, TOutputImage>
// sign.
RealType difference = static_cast<RealType>(t) - static_cast<RealType>(test.GetPixel(i));
for (unsigned int j = 0; j < difference
.Size(
); ++j)
for (unsigned int j = 0; j <
itk::NumericTraits<RealType>::GetLength(
difference)
; ++j)
{
if (difference[j] < 0)
ScalarRealType d = static_cast<ScalarRealType>(
itk::DefaultConvertPixelTraits<RealType>::GetNthComponent(j,difference));
if (d < 0)
{
d
ifference[j]
*= -1;
d *= -1;
}
ScalarRealType
d
= static_cast<ScalarRealType>(
difference[j]);
if (d < m
inimumDifference[j]
)
ScalarRealType
m
= static_cast<ScalarRealType>(
itk::DefaultConvertPixelTraits<OutputPixelType>::GetNthComponent(j,minimumDifference));
if (d < m)
{
minimumDifference[j] = d;
itk::DefaultConvertPixelTraits<OutputPixelType>::SetNthComponent(
j,
minimumDifference,
d);
// std::cout << std::setprecision(16) << minimumDifference[j] << std::endl;
// std::cout << std::setprecision(16) << t << std::endl;
// std::cout << std::setprecision(16) << test.GetPixel(i) << std::endl;
...
...
@@ -198,18 +212,22 @@ DifferenceImageFilter<TInputImage, TOutputImage>
// ScalarRealType tMax=vcl_abs(t[0]);
ScalarRealType tMax = 0.01; //Avoiding the 0 case for neighborhood computing
// NB: still more restrictive than before for small values.
for (unsigned int j = 0; j <
t.Size(
); ++j)
for (unsigned int j = 0; j <
itk::NumericTraits<InputPixelType>::GetLength(t
); ++j)
{
if (vcl_abs(t[j]) > tMax) tMax = vcl_abs(t[j]);
ScalarRealType tc = static_cast<ScalarRealType>(
itk::DefaultConvertPixelTraits<InputPixelType>::GetNthComponent(j,t));
if (vcl_abs(tc) > tMax) tMax = vcl_abs(tc);
}
// Check if difference is above threshold
// the threshold is interpreted as relative to the value
bool isDifferent = false;
for (unsigned int j = 0; j < minimumDifference
.Size(
); ++j)
for (unsigned int j = 0; j <
itk::NumericTraits<OutputPixelType>::GetLength(
minimumDifference); ++j)
{
if (minimumDifference[j] > m_DifferenceThreshold * tMax)
ScalarRealType m = static_cast<ScalarRealType>(
itk::DefaultConvertPixelTraits<OutputPixelType>::GetNthComponent(j,minimumDifference));
if (m > m_DifferenceThreshold * tMax)
{
// std::cout << std::setprecision(16) << minimumDifference[j] << std::endl;
isDifferent = true;
...
...
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