Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,45 +130,6 @@ class ITK_TEMPLATE_EXPORT RGBGibbsPriorFilter : public MRFImageFilter<TInputImag
void
SetClassifier(typename ClassifierType::Pointer ptrToClassifier);

/** Set the number of classes. */
void
SetNumberOfClasses(const unsigned int numberOfClasses) override
{
itkDebugMacro("setting NumberOfClasses to " << numberOfClasses);
if (this->m_NumberOfClasses != numberOfClasses)
{
this->m_NumberOfClasses = numberOfClasses;
this->Modified();
}
}

/** Get the number of classes. */
[[nodiscard]] unsigned int
GetNumberOfClasses() const override
{
return this->m_NumberOfClasses;
}

/** Set/Get the number of iteration of the Iterated Conditional Mode
* (ICM) algorithm. A default value is set at 50 iterations. */
void
SetMaximumNumberOfIterations(const unsigned int numberOfIterations) override
{
itkDebugMacro("setting MaximumNumberOfIterations to " << numberOfIterations);
if (this->m_MaximumNumberOfIterations != numberOfIterations)
{
this->m_MaximumNumberOfIterations = numberOfIterations;
this->Modified();
}
}

/** Get the number of iterations of the Iterated Conditional Mode
* (ICM) algorithm. */
[[nodiscard]] unsigned int
GetMaximumNumberOfIterations() const override
{
return this->m_MaximumNumberOfIterations;
}

/** Set/Get the threshold for the object size. */
/** @ITKStartGrouping */
Expand Down Expand Up @@ -252,12 +213,6 @@ class ITK_TEMPLATE_EXPORT RGBGibbsPriorFilter : public MRFImageFilter<TInputImag
/** Output. */
LabelledImageType m_LabelledImage{};

/** Number of classes that need to be classified. */
unsigned int m_NumberOfClasses{ 0 };

/** Maximum number of iterations. */
unsigned int m_MaximumNumberOfIterations{ 10 };

typename ClassifierType::Pointer m_ClassifierPtr{};

/** Threshold for the existence of a boundary. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ RGBGibbsPriorFilter<TInputImage, TClassifiedImage>::RGBGibbsPriorFilter()

{
m_StartPoint.Fill(0);
this->SetMaximumNumberOfIterations(10);
}

template <typename TInputImage, typename TClassifiedImage>
Expand Down Expand Up @@ -165,7 +166,7 @@ void
RGBGibbsPriorFilter<TInputImage, TClassifiedImage>::SetClassifier(typename ClassifierType::Pointer ptrToClassifier)
{
m_ClassifierPtr = ptrToClassifier;
m_ClassifierPtr->SetNumberOfClasses(m_NumberOfClasses);
m_ClassifierPtr->SetNumberOfClasses(this->GetNumberOfClasses());
}

template <typename TInputImage, typename TClassifiedImage>
Expand Down Expand Up @@ -683,8 +684,6 @@ RGBGibbsPriorFilter<TInputImage, TClassifiedImage>::PrintSelf(std::ostream & os,
{
Superclass::PrintSelf(os, indent);

os << indent << "NumberOfClasses: " << m_NumberOfClasses << std::endl;
os << indent << "MaximumNumberOfIterations: " << m_MaximumNumberOfIterations << std::endl;
os << indent << "ObjectThreshold: " << m_ObjectThreshold << std::endl;
os << indent << "BoundaryGradient: " << m_BoundaryGradient << std::endl;
os << indent << "CliqueWeight_1: " << m_CliqueWeight_1 << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@ itk_add_test(
ITKMarkovRandomFieldsClassifiersTestDriver
itkRGBGibbsPriorFilterTest
)

set(ITKMarkovRandomFieldsClassifiersGTests itkRGBGibbsPriorFilterGTest.cxx)

creategoogletestdriver(
ITKMarkovRandomFieldsClassifiers
"${ITKMarkovRandomFieldsClassifiers-Test_LIBRARIES}"
"${ITKMarkovRandomFieldsClassifiersGTests}"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/

#include "itkGTest.h"
#include "itkMRFImageFilter.h"
#include "itkRGBGibbsPriorFilter.h"
#include "itkImage.h"
#include "itkVector.h"

namespace
{
constexpr unsigned int NumberOfBands{ 1 };
constexpr unsigned int ImageDimension{ 3 };
using PixelType = itk::Vector<unsigned short, NumberOfBands>;
using InputImageType = itk::Image<PixelType, ImageDimension>;
using LabelImageType = itk::Image<unsigned short, ImageDimension>;
using BaseFilterType = itk::MRFImageFilter<InputImageType, LabelImageType>;
using GibbsFilterType = itk::RGBGibbsPriorFilter<InputImageType, LabelImageType>;
} // namespace

TEST(RGBGibbsPriorFilter, DefaultNumberOfClassesIsZero)
{
auto filter = GibbsFilterType::New();
EXPECT_EQ(filter->GetNumberOfClasses(), 0u);
}

TEST(RGBGibbsPriorFilter, DefaultMaximumNumberOfIterationsIsTen)
{
auto filter = GibbsFilterType::New();
EXPECT_EQ(filter->GetMaximumNumberOfIterations(), 10u);
}

TEST(MRFImageFilter, DefaultMaximumNumberOfIterationsIsFifty)
{
auto filter = BaseFilterType::New();
EXPECT_EQ(filter->GetMaximumNumberOfIterations(), 50u);
}

TEST(RGBGibbsPriorFilter, SetGetNumberOfClassesViaSubclass)
{
auto filter = GibbsFilterType::New();
filter->SetNumberOfClasses(7u);
EXPECT_EQ(filter->GetNumberOfClasses(), 7u);
}

TEST(RGBGibbsPriorFilter, SetGetMaximumNumberOfIterationsViaSubclass)
{
auto filter = GibbsFilterType::New();
filter->SetMaximumNumberOfIterations(25u);
EXPECT_EQ(filter->GetMaximumNumberOfIterations(), 25u);
}

TEST(RGBGibbsPriorFilter, SetGetNumberOfClassesViaBasePointer)
{
auto gibbs = GibbsFilterType::New();
const BaseFilterType * basePtr = gibbs;
BaseFilterType * baseMutable = gibbs;
baseMutable->SetNumberOfClasses(5u);
EXPECT_EQ(basePtr->GetNumberOfClasses(), 5u);
EXPECT_EQ(gibbs->GetNumberOfClasses(), 5u);
}

TEST(RGBGibbsPriorFilter, SetGetMaximumNumberOfIterationsViaBasePointer)
{
auto gibbs = GibbsFilterType::New();
const BaseFilterType * basePtr = gibbs;
BaseFilterType * baseMutable = gibbs;
baseMutable->SetMaximumNumberOfIterations(33u);
EXPECT_EQ(basePtr->GetMaximumNumberOfIterations(), 33u);
EXPECT_EQ(gibbs->GetMaximumNumberOfIterations(), 33u);
}

TEST(RGBGibbsPriorFilter, ModifiedTimeAdvancesOnNumberOfClassesChange)
{
auto filter = GibbsFilterType::New();
filter->SetNumberOfClasses(3u);
const auto t1 = filter->GetMTime();
filter->SetNumberOfClasses(4u);
EXPECT_GT(filter->GetMTime(), t1);
}

TEST(RGBGibbsPriorFilter, ModifiedTimeUnchangedOnIdenticalAssignment)
{
auto filter = GibbsFilterType::New();
filter->SetNumberOfClasses(3u);
const auto t1 = filter->GetMTime();
filter->SetNumberOfClasses(3u);
EXPECT_EQ(filter->GetMTime(), t1);
}
Loading