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
Antoine Belvire
otb
Commits
80175522
Commit
80175522
authored
9 years ago
by
Christophe Palmann
Browse files
Options
Downloads
Patches
Plain Diff
ENH: Frost filter with correct formula (SAR)
parent
11f03b9c
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/Filtering/ImageNoise/include/otbFrostImageFilter.h
+7
-14
7 additions, 14 deletions
Modules/Filtering/ImageNoise/include/otbFrostImageFilter.h
Modules/Filtering/ImageNoise/include/otbFrostImageFilter.txx
+47
-35
47 additions, 35 deletions
Modules/Filtering/ImageNoise/include/otbFrostImageFilter.txx
with
54 additions
and
49 deletions
Modules/Filtering/ImageNoise/include/otbFrostImageFilter.h
+
7
−
14
View file @
80175522
...
...
@@ -29,18 +29,11 @@ namespace otb
* \brief Anti-speckle image filter
*
* Uses a negative exponential convolution kernel.
* The output of the filter for pixel p is:
* \f$ \hat I_{s}=\sum_{p\in\eta_{p}} m_{p}I_{p} \f$
*
* where : \f$ m_{p}=\frac{KC_{s}^{2}\exp(-KC_{s}^{2}d_{s, p})}{\sum_{p\in\eta_{p}} KC_{s}^{2}\exp(-KC_{s}^{2}d_{s, p})} \f$
* and \f$ d_{s, p}=\sqrt{(i-i_{p})^2+(j-j_{p})^2} \f$
*
* \f$ K \f$ : the decrease coefficient
* \f$ (i, j)\f$ : the coordinates of the pixel inside the region
* defined by \f$ \eta_{s} \f$
* \f$ (i_{p}, j_{p})\f$ : the coordinates of the pixels belonging to \f$ \eta_{p} \subset \eta_{s} \f$
* \f$ C_{s}\f$ : the variation coefficient computed over \f$ \eta_{p}\f$
*
* The kernel is defined as follows:
* exp(-A*D), where
* D is the distance from the current pixel to the center pixel
* A = k*Ci*Ci with Ci = VAR[I]/ (E[I]*E[I])
* The final result is normalized by the sum of the kernel coefficients.
*
* \ingroup OTBImageNoise
*/
...
...
@@ -92,9 +85,9 @@ public:
/** Get the radius used to define the neighborhood for the filter calculation. */
itkGetConstReferenceMacro
(
Radius
,
SizeType
);
/** Set
T
he
numbers of view used for the filter calculation
. */
/** Set
t
he
damping factor
. */
itkSetMacro
(
Deramp
,
double
);
/** Get
T
he
numbers of view used for the filter calculation
. */
/** Get
t
he
damping factor
. */
itkGetConstReferenceMacro
(
Deramp
,
double
);
/** To be allowed to use the pipeline method FrostImageFilter needs
...
...
This diff is collapsed.
Click to expand it.
Modules/Filtering/ImageNoise/include/otbFrostImageFilter.txx
+
47
−
35
View file @
80175522
...
...
@@ -38,7 +38,7 @@ template <class TInputImage, class TOutputImage>
FrostImageFilter<TInputImage, TOutputImage>::FrostImageFilter()
{
m_Radius.Fill(1);
m_Deramp =
0.1
;
m_Deramp =
2
;
}
template <class TInputImage, class TOutputImage>
...
...
@@ -135,54 +135,66 @@ void FrostImageFilter<TInputImage, TOutputImage>::ThreadedGenerateData(
unsigned int neighborhoodSize = bit.Size();
it = itk::ImageRegionIterator<OutputImageType>(output, *fit);
bit.OverrideBoundaryCondition(&nbc);
bit.GoToBegin();
it.GoToBegin();
while (!bit.IsAtEnd())
{
sum = itk::NumericTraits<InputRealType>::Zero;
sum2 = itk::NumericTraits<InputRealType>::Zero;
for (i = 0; i < neighborhoodSize; ++i)
{
dPixel = static_cast<double>(bit.GetPixel(i));
sum += dPixel;
sum2 += dPixel * dPixel;
}
Mean = sum / double(neighborhoodSize);
Variance = sum2 / double(neighborhoodSize) - Mean * Mean;
if (Mean == 0)
{
Alpha = 0;
}
else
{
Alpha = m_Deramp * Variance / (Mean * Mean);
}
NormFilter = 0.0;
FrostFilter = 0.0;
const int rad_x = m_Radius[0];
const int rad_y = m_Radius[1];
for (int x = -rad_x; x <= rad_x; ++x)
Mean = sum / static_cast<double>(neighborhoodSize);
for (i = 0; i < neighborhoodSize; ++i)
{
for (int y = -rad_y; y <= rad_y; ++y)
{
double Dist = vcl_sqrt(static_cast<double>(x * x + y * y));
off[0] = x;
off[1] = y;
dPixel = static_cast<double>(bit.GetPixel(off));
CoefFilter = Alpha * vcl_exp(-Alpha * Dist);
NormFilter += CoefFilter;
FrostFilter += (CoefFilter * dPixel);
}
dPixel = static_cast<double>(bit.GetPixel(i));
sum2 += (dPixel-Mean) * (dPixel-Mean);
}
Variance = sum2 / double(neighborhoodSize-1);
if (NormFilter == 0.) dPixel = 0.;
else dPixel = FrostFilter / NormFilter;
const double epsilon = 0.0000000001;
if (vcl_abs(Mean) < epsilon)
{
dPixel = itk::NumericTraits<OutputPixelType>::Zero;
}
else if (vcl_abs(Variance) < epsilon)
{
dPixel = Mean;
}
else
{
Alpha = m_Deramp * Variance / (Mean * Mean);
NormFilter = 0.0;
FrostFilter = 0.0;
const int rad_x = m_Radius[0];
const int rad_y = m_Radius[1];
for (int x = -rad_x; x <= rad_x; ++x)
{
for (int y = -rad_y; y <= rad_y; ++y)
{
double Dist = vcl_sqrt(static_cast<double>(x * x + y * y));
off[0] = x;
off[1] = y;
dPixel = static_cast<double>(bit.GetPixel(off));
CoefFilter = vcl_exp(-Alpha * Dist);
NormFilter += CoefFilter;
FrostFilter += (CoefFilter * dPixel);
}
}
dPixel = FrostFilter / NormFilter;
}
it.Set(static_cast<OutputPixelType>(dPixel));
...
...
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