Skip to content

Commit

Permalink
ENH: automatic threshold calculators
Browse files Browse the repository at this point in the history
This is the code of the insight journal contribution "Histogram-based
thresholding - some missing methods".

  http://www.insight-journal.org/browse/publication/811
  http://hdl.handle.net/10380/3279

The Otsu filters and calculators have also been modified to use the
architecture of the other calculators.
The histogram is no more computed by the calculator. This is delegated
to another filter, such as ImageToHistogramFilter. This change lets us
easily implementing the multithreading and the ability to mask the
image to compute the histogram, for example by using
MaskedImageToHistogramFilter or by using the histogram attached to a
LabelObject.

The old OtsuThresholdImageCalculator is available in the
ITKV3Compatibility module.

Patch 15 - Changed itkTypeMacro superclass field from ImageToImageFilter
to HistogramThresholdImageFilter in all subclasses

Removed some redundant include files

added methods for setting number of histogram bins and turning
AutoMinimumMaximum on/off. Still need methods for setting
minimum and maximum explicitly. Not sure of the appropriate
way of doing this with the decorator structures.

Added required number of inputs and outputs.

Patch 16 - Rebased after the removal of the Testing/Data submodule.

Patch 17 - Added my (Richard Beare) complete affiliation. Also changed
the strategy for derived classes that include calculators with different
parameters. This change is intended for discussion. I have removed the
virtual method - ConfigureCalculator - and included a pointer to the
calculator in the derived class. This eliminated dynamic_casts inside the
derived class as well as the local variables in the derived class. However
it leads to the need for explicit Set/Get methods, rather than ones
created using macros. Perhaps there are macros that can help that I am
unaware of? The example is the Intermodes filter.

Note - we also need a new test for intermodes filter using
SetUseInterMode(false)

Change-Id: I697873136fbca86258626284eae5df7b552c6241
  • Loading branch information
glehmann authored and hjmjohnson committed Oct 30, 2011
1 parent 764f5ee commit fb95a5e
Show file tree
Hide file tree
Showing 109 changed files with 5,841 additions and 249 deletions.
221 changes: 221 additions & 0 deletions Documentation/Migration/OtsuCalculatorAndFilterNormalization.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Change SYSTEM "http://ij.itk.org/itkfaq/ITKMigration.dtd">

<!--**
**
** OtsuCalculatorAndFilterNormalization.xml
**
** >>>>>>>>>>>>>>>>>>>>>>>>>>>>
** THIS FILE HAS BEEN AUTOMATICALLY GENERATED. EDIT IT BEFORE COMMITING
** <<<<<<<<<<<<<<<<<<<<<<<<<<<
**
** Please, make sure this file validates the following w3c test before committing it: http://validator.w3.org
**-->
<Change>
<!--**
** Title for the online migration page
**-->
<Title>
Otsu Calculator And Filter Normalization
</Title>

<!--**
** The author of the change
**-->
<Author>
Gaëtan Lehmann
</Author>

<!--**
** Date of creation for the XML document
**-->
<Date>
2011-09-05
</Date>

<!--**
** Plain text description of the change
** Extracted from git commit messages
**-->
<Description>
<![CDATA[
The Otsu filters and calculators have been modified to use the
architecture of the other threshold calculators.
The histogram is no more computed by the calculator; it is delegated
to another filter, such as ImageToHistogramFilter. As a consequence, the template
parameter used for the Otsu calculator is the histogram type.
The Otsu filter is using the usual maximum pixel value inside the objects and the minimum
pixel values outside the objects. The values were swapped before this change.
The Otsu filter doesn't let the user choose the number of bins in the histogram anymore.
This choice is delegated to the ImageToHistogramFilter used internally, and is available
by reconstructing the minipipeline
ImageToHistogramFilter -> OtsuThresholdCalculator -> BinaryThresholdImageFilter.
]]>
</Description>

<!--**
** Sample code snippets
** Extracted from git diff of changed files in Examples and Testing
**-->
<SampleCode>
<Old>
<![CDATA[
]]>
</Old>

<New>
<![CDATA[
]]>
</New>

</SampleCode>

<!--**
** The change-ids for all commits in the topic branch
**-->
<Gerrit-ChangeId>
I697873136fbca86258626284eae5df7b552c6241
</Gerrit-ChangeId>

<!--**
** List of all changed files from the topic branch
**-->
<FileList>
Modules/Filtering/Thresholding/include/itkHuangThresholdCalculator.h
Modules/Filtering/Thresholding/include/itkHuangThresholdCalculator.hxx
Modules/Filtering/Thresholding/include/itkHuangThresholdImageFilter.h
Modules/Filtering/Thresholding/include/itkHuangThresholdImageFilter.hxx
Modules/Filtering/Thresholding/include/itkIntermodesThresholdCalculator.h
Modules/Filtering/Thresholding/include/itkIntermodesThresholdCalculator.hxx
Modules/Filtering/Thresholding/include/itkIntermodesThresholdImageFilter.h
Modules/Filtering/Thresholding/include/itkIntermodesThresholdImageFilter.hxx
Modules/Filtering/Thresholding/include/itkIsoDataThresholdCalculator.h
Modules/Filtering/Thresholding/include/itkIsoDataThresholdCalculator.hxx
Modules/Filtering/Thresholding/include/itkIsoDataThresholdImageFilter.h
Modules/Filtering/Thresholding/include/itkIsoDataThresholdImageFilter.hxx
Modules/Filtering/Thresholding/include/itkKittlerIllingworthThresholdCalculator.h
Modules/Filtering/Thresholding/include/itkKittlerIllingworthThresholdCalculator.hxx
Modules/Filtering/Thresholding/include/itkKittlerIllingworthThresholdImageFilter.h
Modules/Filtering/Thresholding/include/itkKittlerIllingworthThresholdImageFilter.hxx
Modules/Filtering/Thresholding/include/itkLiThresholdCalculator.h
Modules/Filtering/Thresholding/include/itkLiThresholdCalculator.hxx
Modules/Filtering/Thresholding/include/itkLiThresholdImageFilter.h
Modules/Filtering/Thresholding/include/itkLiThresholdImageFilter.hxx
Modules/Filtering/Thresholding/include/itkMaximumEntropyThresholdCalculator.h
Modules/Filtering/Thresholding/include/itkMaximumEntropyThresholdCalculator.hxx
Modules/Filtering/Thresholding/include/itkMaximumEntropyThresholdImageFilter.h
Modules/Filtering/Thresholding/include/itkMaximumEntropyThresholdImageFilter.hxx
Modules/Filtering/Thresholding/include/itkMomentsThresholdCalculator.h
Modules/Filtering/Thresholding/include/itkMomentsThresholdCalculator.hxx
Modules/Filtering/Thresholding/include/itkMomentsThresholdImageFilter.h
Modules/Filtering/Thresholding/include/itkMomentsThresholdImageFilter.hxx
Modules/Filtering/Thresholding/include/itkOtsuThresholdCalculator.h
Modules/Filtering/Thresholding/include/itkOtsuThresholdCalculator.hxx
Modules/Filtering/Thresholding/include/itkOtsuThresholdImageCalculator.h
Modules/Filtering/Thresholding/include/itkOtsuThresholdImageCalculator.hxx
Modules/Filtering/Thresholding/include/itkOtsuThresholdImageFilter.h
Modules/Filtering/Thresholding/include/itkOtsuThresholdImageFilter.hxx
Modules/Filtering/Thresholding/include/itkRenyiEntropyThresholdCalculator.h
Modules/Filtering/Thresholding/include/itkRenyiEntropyThresholdCalculator.hxx
Modules/Filtering/Thresholding/include/itkRenyiEntropyThresholdImageFilter.h
Modules/Filtering/Thresholding/include/itkRenyiEntropyThresholdImageFilter.hxx
Modules/Filtering/Thresholding/include/itkShanbhagThresholdCalculator.h
Modules/Filtering/Thresholding/include/itkShanbhagThresholdCalculator.hxx
Modules/Filtering/Thresholding/include/itkShanbhagThresholdImageFilter.h
Modules/Filtering/Thresholding/include/itkShanbhagThresholdImageFilter.hxx
Modules/Filtering/Thresholding/include/itkThresholdCalculator.h
Modules/Filtering/Thresholding/include/itkTriangleThresholdCalculator.h
Modules/Filtering/Thresholding/include/itkTriangleThresholdCalculator.hxx
Modules/Filtering/Thresholding/include/itkTriangleThresholdImageFilter.h
Modules/Filtering/Thresholding/include/itkTriangleThresholdImageFilter.hxx
Modules/Filtering/Thresholding/include/itkYenThresholdCalculator.h
Modules/Filtering/Thresholding/include/itkYenThresholdCalculator.hxx
Modules/Filtering/Thresholding/include/itkYenThresholdImageFilter.h
Modules/Filtering/Thresholding/include/itkYenThresholdImageFilter.hxx
Modules/Filtering/Thresholding/test/Baseline/itkHuangThresholdImageFilterTest.png.md5
Modules/Filtering/Thresholding/test/Baseline/itkIntermodesThresholdImageFilterTest.png.md5
Modules/Filtering/Thresholding/test/Baseline/itkIsoDataThresholdImageFilterTest.png.md5
Modules/Filtering/Thresholding/test/Baseline/itkKittlerIllingworthThresholdImageFilterTest.png.md5
Modules/Filtering/Thresholding/test/Baseline/itkLiThresholdImageFilterTest.png.md5
Modules/Filtering/Thresholding/test/Baseline/itkMaximumEntropyThresholdImageFilterTest.png.md5
Modules/Filtering/Thresholding/test/Baseline/itkMomentsThresholdImageFilterTest.png.md5
Modules/Filtering/Thresholding/test/Baseline/itkOtsuThresholdImageFilterTest.png.md5
Modules/Filtering/Thresholding/test/Baseline/itkRenyiEntropyThresholdImageFilterTest.png.md5
Modules/Filtering/Thresholding/test/Baseline/itkShanbhagThresholdImageFilterTest.png.md5
Modules/Filtering/Thresholding/test/Baseline/itkTriangleThresholdImageFilterTest.png.md5
Modules/Filtering/Thresholding/test/Baseline/itkYenThresholdImageFilterTest.png.md5
Modules/Filtering/Thresholding/test/CMakeLists.txt
Modules/Filtering/Thresholding/test/itkHuangThresholdImageFilterTest.cxx
Modules/Filtering/Thresholding/test/itkIntermodesThresholdImageFilterTest.cxx
Modules/Filtering/Thresholding/test/itkIsoDataThresholdImageFilterTest.cxx
Modules/Filtering/Thresholding/test/itkKittlerIllingworthThresholdImageFilterTest.cxx
Modules/Filtering/Thresholding/test/itkLiThresholdImageFilterTest.cxx
Modules/Filtering/Thresholding/test/itkMaximumEntropyThresholdImageFilterTest.cxx
Modules/Filtering/Thresholding/test/itkMomentsThresholdImageFilterTest.cxx
Modules/Filtering/Thresholding/test/itkOtsuMultipleThresholdsImageFilterTest.cxx
Modules/Filtering/Thresholding/test/itkOtsuThresholdImageCalculatorTest.cxx
Modules/Filtering/Thresholding/test/itkOtsuThresholdImageFilterTest.cxx
Modules/Filtering/Thresholding/test/itkRenyiEntropyThresholdImageFilterTest.cxx
Modules/Filtering/Thresholding/test/itkShanbhagThresholdImageFilterTest.cxx
Modules/Filtering/Thresholding/test/itkTriangleThresholdImageFilterTest.cxx
Modules/Filtering/Thresholding/test/itkYenThresholdImageFilterTest.cxx
Modules/Nonunit/IntegratedTest/test/itkAlgorithmsPrintTest2.cxx
Modules/Nonunit/Review/test/itkN4MRIBiasFieldCorrectionImageFilterTest.cxx
Modules/Numerics/Statistics/include/itkHistogram.h
Modules/Numerics/Statistics/include/itkHistogram.hxx
Modules/Numerics/Statistics/include/itkImageToHistogramFilter.hxx
Wrapping/WrapITK/Libraries/ITKThresholding/CMakeLists.txt
Wrapping/WrapITK/Libraries/ITKThresholding/itkHuangThresholdCalculator.wrap
Wrapping/WrapITK/Libraries/ITKThresholding/itkHuangThresholdImageFilter.wrap
Wrapping/WrapITK/Libraries/ITKThresholding/itkIntermodesThresholdCalculator.wrap
Wrapping/WrapITK/Libraries/ITKThresholding/itkIntermodesThresholdImageFilter.wrap
Wrapping/WrapITK/Libraries/ITKThresholding/itkIsoDataThresholdCalculator.wrap
Wrapping/WrapITK/Libraries/ITKThresholding/itkIsoDataThresholdImageFilter.wrap
Wrapping/WrapITK/Libraries/ITKThresholding/itkKittlerIllingworthThresholdCalculator.wrap
Wrapping/WrapITK/Libraries/ITKThresholding/itkKittlerIllingworthThresholdImageFilter.wrap
Wrapping/WrapITK/Libraries/ITKThresholding/itkLiThresholdCalculator.wrap
Wrapping/WrapITK/Libraries/ITKThresholding/itkLiThresholdImageFilter.wrap
Wrapping/WrapITK/Libraries/ITKThresholding/itkMaximumEntropyThresholdCalculator.wrap
Wrapping/WrapITK/Libraries/ITKThresholding/itkMaximumEntropyThresholdImageFilter.wrap
Wrapping/WrapITK/Libraries/ITKThresholding/itkMomentsThresholdCalculator.wrap
Wrapping/WrapITK/Libraries/ITKThresholding/itkMomentsThresholdImageFilter.wrap
Wrapping/WrapITK/Libraries/ITKThresholding/itkOtsuThresholdCalculator.wrap
Wrapping/WrapITK/Libraries/ITKThresholding/itkOtsuThresholdImageCalculator.wrap
Wrapping/WrapITK/Libraries/ITKThresholding/itkOtsuThresholdImageFilter.wrap
Wrapping/WrapITK/Libraries/ITKThresholding/itkRenyiEntropyThresholdCalculator.wrap
Wrapping/WrapITK/Libraries/ITKThresholding/itkRenyiEntropyThresholdImageFilter.wrap
Wrapping/WrapITK/Libraries/ITKThresholding/itkShanbhagThresholdCalculator.wrap
Wrapping/WrapITK/Libraries/ITKThresholding/itkShanbhagThresholdImageFilter.wrap
Wrapping/WrapITK/Libraries/ITKThresholding/itkThresholdCalculator.wrap
Wrapping/WrapITK/Libraries/ITKThresholding/itkTriangleThresholdCalculator.wrap
Wrapping/WrapITK/Libraries/ITKThresholding/itkTriangleThresholdImageFilter.wrap
Wrapping/WrapITK/Libraries/ITKThresholding/itkYenThresholdCalculator.wrap
Wrapping/WrapITK/Libraries/ITKThresholding/itkYenThresholdImageFilter.wrap
</FileList>

<!--**
** If the migration can be accomplished by a simple string
** substitution, then use the following construct to define
** the substitution rule.
**
** <MigrationFix-Automatic>
** <Old>
** <![CDATA[MipsleledName]]>
** </Old>
** <New>
** <![CDATA[MisspelledName]]>
** </New>
** </MigrationFix-Automatic>
**-->

<!--**
** If the migration can NOT be accomplished by a simple string
** substitution, but potential problem spots can be identified,
** use the following construct to define a migration flag rule.
**
** <MigrationFix-Manual>
** OldFunctionName
** </MigrationFix-Manual>
**-->

</Change>
16 changes: 0 additions & 16 deletions Examples/Filtering/OtsuThresholdImageFilter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -168,19 +168,6 @@ int main( int argc, char * argv[] )
// Software Guide : EndCodeSnippet


// Software Guide : BeginLatex
//
// The method \code{SetNumberOfHistogramBins()} defines the number of bins
// to be used for computing the histogram. This histogram will be used
// internally in order to compute the Otsu threshold.
//
// Software Guide : EndLatex

// Software Guide : BeginCodeSnippet
filter->SetNumberOfHistogramBins( 128 );
// Software Guide : EndCodeSnippet


// Software Guide : BeginLatex
//
// The execution of the filter is triggered by invoking the \code{Update()}
Expand All @@ -195,7 +182,6 @@ int main( int argc, char * argv[] )
// Software Guide : EndCodeSnippet



// Software Guide : BeginLatex
//
// We print out here the Threshold value that was computed internally by the
Expand All @@ -209,7 +195,6 @@ int main( int argc, char * argv[] )
// Software Guide : EndCodeSnippet



// Software Guide : BeginLatex
//
// \begin{figure}
Expand Down Expand Up @@ -240,4 +225,3 @@ int main( int argc, char * argv[] )

return EXIT_SUCCESS;
}

3 changes: 3 additions & 0 deletions Modules/Compatibility/V3Compatibility/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(ITKV3CompatibilityTests
itkTransformToDeformationFieldSourceTest.cxx
itkTransformToDeformationFieldSourceTest1.cxx
itkDeformationFieldJacobianDeterminantFilterTest.cxx
itkOtsuThresholdImageCalculatorTest.cxx
)

CreateTestDriver(ITKV3Compatibility "${ITKV3Compatibility-Test_LIBRARIES}" "${ITKV3CompatibilityTests}")
Expand Down Expand Up @@ -38,3 +39,5 @@ itk_add_test(NAME itkTransformToDeformationFieldSourceTest02
BSpline ${ITK_TEST_OUTPUT_DIR}/itkTransformToDeformationFieldSourceTestField02.mha DATA{${ITK_DATA_ROOT}/Input/parametersBSpline.txt} ${ITK_TEST_OUTPUT_DIR}/itkTransformToDeformationFieldSourceTestImage02.mha)
itk_add_test(NAME itkExponentialDeformationFieldImageFilterTest
COMMAND ITKV3CompatibilityTestDriver itkExponentialDeformationFieldImageFilterTest)
itk_add_test(NAME itkOtsuThresholdImageCalculatorTest
COMMAND ITKV3CompatibilityTestDriver itkOtsuThresholdImageCalculatorTest)
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#include "itkSize.h"
#include "itkImageRegionIterator.h"

typedef itk::Size<3> SizeType;
typedef itk::Image<short, 3> ImageType;
typedef itk::Size<3> SizeType;
typedef itk::Image<short, 3> ImageType;
typedef itk::OtsuThresholdImageCalculator<ImageType> CalculatorType;
namespace
{
Expand Down
Loading

0 comments on commit fb95a5e

Please sign in to comment.