Skip to content

Commit bf14387

Browse files
committed
ENH: Wrap LabelSetMeasures in LabelOverlapMeasuresImageFilter
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.
1 parent 0150e46 commit bf14387

File tree

5 files changed

+40
-16
lines changed

5 files changed

+40
-16
lines changed

Modules/Filtering/ImageStatistics/include/itkLabelOverlapMeasuresImageFilter.h

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@
2525

2626
namespace itk
2727
{
28+
/** \class LabelOverlapLabelSetMeasures
29+
* \brief Metrics stored per label
30+
* \ingroup ITKImageStatistics
31+
*/
32+
class LabelOverlapLabelSetMeasures
33+
{
34+
public:
35+
// default constructor/copy/move etc...
36+
37+
SizeValueType m_Source{ 0 };
38+
SizeValueType m_Target{ 0 };
39+
SizeValueType m_Union{ 0 };
40+
SizeValueType m_Intersection{ 0 };
41+
SizeValueType m_SourceComplement{ 0 };
42+
SizeValueType m_TargetComplement{ 0 };
43+
};
2844

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

76-
/** \class LabelSetMeasures
77-
* \brief Metrics stored per label
78-
* \ingroup ITKImageStatistics
79-
*/
80-
class LabelSetMeasures
81-
{
82-
public:
83-
// default constructor/copy/move etc...
92+
#ifndef ITK_FUTURE_LEGACY_REMOVE
93+
/** Type to use for computations. */
94+
using LabelSetMeasures = LabelOverlapLabelSetMeasures;
95+
#endif // !ITK_FUTURE_LEGACY_REMOVE
8496

85-
SizeValueType m_Source{ 0 };
86-
SizeValueType m_Target{ 0 };
87-
SizeValueType m_Union{ 0 };
88-
SizeValueType m_Intersection{ 0 };
89-
SizeValueType m_SourceComplement{ 0 };
90-
SizeValueType m_TargetComplement{ 0 };
91-
};
9297

9398
/** Type of the map used to store data per label */
94-
using MapType = std::unordered_map<LabelType, LabelSetMeasures>;
99+
using MapType = std::unordered_map<LabelType, LabelOverlapLabelSetMeasures>;
95100
using MapIterator = typename MapType::iterator;
96101
using MapConstIterator = typename MapType::const_iterator;
97102

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
itk_wrap_module(ITKImageStatistics)
2+
if(ITK_WRAP_PYTHON)
3+
set(WRAPPER_SUBMODULE_ORDER itkLabelOverlapMeasuresImageFilter_LabelSetMeasures)
4+
list(APPEND WRAPPER_SWIG_LIBRARY_FILES "${CMAKE_CURRENT_LIST_DIR}/itkLabelOverlapMeasuresImageFilter.i")
5+
endif()
26
itk_auto_load_and_end_wrap_submodules()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
%include <std_unordered_map.i>
2+
3+
%template(hashmapUCLOLSM) std::unordered_map< unsigned char, itk::LabelOverlapLabelSetMeasures >;
4+
%template(hashmapSCLOLSM) std::unordered_map< signed char, itk::LabelOverlapLabelSetMeasures >;
5+
%template(hashmapUSLOLSM) std::unordered_map< unsigned short, itk::LabelOverlapLabelSetMeasures >;
6+
%template(hashmapSSLOLSM) std::unordered_map< signed short, itk::LabelOverlapLabelSetMeasures >;
7+
%template(hashmapULLOLSM) std::unordered_map< unsigned long, itk::LabelOverlapLabelSetMeasures >;
8+
%template(hashmapSLLOLSM) std::unordered_map< signed long, itk::LabelOverlapLabelSetMeasures >;
9+
%template(hashmapULLLOLSM) std::unordered_map< unsigned long long, itk::LabelOverlapLabelSetMeasures >;
10+
%template(hashmapSLLLOLSM) std::unordered_map< signed long long, itk::LabelOverlapLabelSetMeasures >;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set(WRAPPER_AUTO_INCLUDE_HEADERS OFF)
2+
itk_wrap_include("itkLabelOverlapMeasuresImageFilter.h")
3+
itk_wrap_simple_class("itk::LabelOverlapLabelSetMeasures")
4+
set(WRAPPER_AUTO_INCLUDE_HEADERS ON)

Wrapping/Generators/Python/PyBase/pyBase.i

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ from . import _ITKCommonPython
2323
%include <std_pair.i>
2424
%include <std_vector.i>
2525
%include <std_map.i>
26+
%include <std_unordered_map.i>
2627
%include <std_list.i>
2728
%include <std_set.i>
2829

0 commit comments

Comments
 (0)