Skip to content

Commit

Permalink
ENH: Wrap LabelSetMeasures in LabelOverlapMeasuresImageFilter
Browse files Browse the repository at this point in the history
This exposes the return value from
itk::LabelOverlapMeasuresImageFilter::GetLabelSetMeasures()
as a Python dictionary instead of
<Swig Object of type 'std::unordered_map< unsigned char,itkLabelOverlapMeasuresImageFilterIUC3::LabelSetMeasures > *'>
This is needed for convenient use of the class from Python.
The class has been un-nested to make wrapping easier/possible.
  • Loading branch information
dzenanz committed Sep 20, 2023
1 parent 0150e46 commit bf14387
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@

namespace itk
{
/** \class LabelOverlapLabelSetMeasures
* \brief Metrics stored per label
* \ingroup ITKImageStatistics
*/
class LabelOverlapLabelSetMeasures
{
public:
// default constructor/copy/move etc...

SizeValueType m_Source{ 0 };
SizeValueType m_Target{ 0 };
SizeValueType m_Union{ 0 };
SizeValueType m_Intersection{ 0 };
SizeValueType m_SourceComplement{ 0 };
SizeValueType m_TargetComplement{ 0 };
};

/** \class LabelOverlapMeasuresImageFilter
* \brief Computes overlap measures between the set same set of labels of
Expand Down Expand Up @@ -73,25 +89,14 @@ class ITK_TEMPLATE_EXPORT LabelOverlapMeasuresImageFilter : public ImageSink<TLa
/** Type to use for computations. */
using RealType = typename NumericTraits<LabelType>::RealType;

/** \class LabelSetMeasures
* \brief Metrics stored per label
* \ingroup ITKImageStatistics
*/
class LabelSetMeasures
{
public:
// default constructor/copy/move etc...
#ifndef ITK_FUTURE_LEGACY_REMOVE
/** Type to use for computations. */
using LabelSetMeasures = LabelOverlapLabelSetMeasures;
#endif // !ITK_FUTURE_LEGACY_REMOVE

SizeValueType m_Source{ 0 };
SizeValueType m_Target{ 0 };
SizeValueType m_Union{ 0 };
SizeValueType m_Intersection{ 0 };
SizeValueType m_SourceComplement{ 0 };
SizeValueType m_TargetComplement{ 0 };
};

/** Type of the map used to store data per label */
using MapType = std::unordered_map<LabelType, LabelSetMeasures>;
using MapType = std::unordered_map<LabelType, LabelOverlapLabelSetMeasures>;
using MapIterator = typename MapType::iterator;
using MapConstIterator = typename MapType::const_iterator;

Expand Down
4 changes: 4 additions & 0 deletions Modules/Filtering/ImageStatistics/wrapping/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
itk_wrap_module(ITKImageStatistics)
if(ITK_WRAP_PYTHON)
set(WRAPPER_SUBMODULE_ORDER itkLabelOverlapMeasuresImageFilter_LabelSetMeasures)
list(APPEND WRAPPER_SWIG_LIBRARY_FILES "${CMAKE_CURRENT_LIST_DIR}/itkLabelOverlapMeasuresImageFilter.i")
endif()
itk_auto_load_and_end_wrap_submodules()
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
%include <std_unordered_map.i>

%template(hashmapUCLOLSM) std::unordered_map< unsigned char, itk::LabelOverlapLabelSetMeasures >;
%template(hashmapSCLOLSM) std::unordered_map< signed char, itk::LabelOverlapLabelSetMeasures >;
%template(hashmapUSLOLSM) std::unordered_map< unsigned short, itk::LabelOverlapLabelSetMeasures >;
%template(hashmapSSLOLSM) std::unordered_map< signed short, itk::LabelOverlapLabelSetMeasures >;
%template(hashmapULLOLSM) std::unordered_map< unsigned long, itk::LabelOverlapLabelSetMeasures >;
%template(hashmapSLLOLSM) std::unordered_map< signed long, itk::LabelOverlapLabelSetMeasures >;
%template(hashmapULLLOLSM) std::unordered_map< unsigned long long, itk::LabelOverlapLabelSetMeasures >;
%template(hashmapSLLLOLSM) std::unordered_map< signed long long, itk::LabelOverlapLabelSetMeasures >;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set(WRAPPER_AUTO_INCLUDE_HEADERS OFF)
itk_wrap_include("itkLabelOverlapMeasuresImageFilter.h")
itk_wrap_simple_class("itk::LabelOverlapLabelSetMeasures")
set(WRAPPER_AUTO_INCLUDE_HEADERS ON)
1 change: 1 addition & 0 deletions Wrapping/Generators/Python/PyBase/pyBase.i
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ from . import _ITKCommonPython
%include <std_pair.i>
%include <std_vector.i>
%include <std_map.i>
%include <std_unordered_map.i>
%include <std_list.i>
%include <std_set.i>

Expand Down

0 comments on commit bf14387

Please sign in to comment.