Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap LabelSetMeasures in LabelOverlapMeasuresImageFilter #4221

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
@@ -0,0 +1,39 @@
/*=========================================================================
*
* 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.
*
*=========================================================================*/
#ifndef itkLabelOverlapLabelSetMeasures_h
#define itkLabelOverlapLabelSetMeasures_h

#include "itkIntTypes.h"

namespace itk
{
/** \class LabelOverlapLabelSetMeasures
* \brief Metrics stored per label
* \ingroup ITKImageStatistics
*/
struct LabelOverlapLabelSetMeasures
{
SizeValueType m_Source{ 0 };
SizeValueType m_Target{ 0 };
SizeValueType m_Union{ 0 };
SizeValueType m_Intersection{ 0 };
SizeValueType m_SourceComplement{ 0 };
SizeValueType m_TargetComplement{ 0 };
};
} // namespace itk
#endif // itkLabelOverlapLabelSetMeasures_h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

#include "itkImageSink.h"
#include "itkNumericTraits.h"
#include "itkLabelOverlapLabelSetMeasures.h"
#include <mutex>
#include <unordered_map>

namespace itk
{

/** \class LabelOverlapMeasuresImageFilter
* \brief Computes overlap measures between the set same set of labels of
* pixels of two images. Background is assumed to be 0.
Expand Down Expand Up @@ -73,25 +73,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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4106f7a97659761a7fd42594a4f19aa9dad312445a1c9ff63f397f0c32cb952ee5d6ba6c6582951d883e6f40587091437a872c5fce966670d57f4984125c7a5d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eb93426d1ee5f00d722979fd9dbfd8701f27bbb4256522e3d25c4db0f88f33b6a2db1ce572613e38c1a91787ca911e2399d206a137f7e987421b357bd5925b5d
2 changes: 2 additions & 0 deletions Modules/Filtering/ImageStatistics/wrapping/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
itk_wrap_module(ITKImageStatistics)
set(WRAPPER_SUBMODULE_ORDER itkLabelOverlapLabelSetMeasures)
list(APPEND WRAPPER_SWIG_LIBRARY_FILES "${CMAKE_CURRENT_LIST_DIR}/itkLabelOverlapLabelSetMeasuresInstantiations.i")
itk_auto_load_and_end_wrap_submodules()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
itk_wrap_simple_class("itk::LabelOverlapLabelSetMeasures")
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
%include <std_unordered_map.i>

%{
#include "itkLabelOverlapMeasuresImageFilter.h"
%}

%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 >;
12 changes: 12 additions & 0 deletions Modules/Filtering/ImageStatistics/wrapping/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
set(test_input_dir ${itk-module_SOURCE_DIR}/test/Input)

# let's make sure 3D uchar images are wrapped
list(FIND ITK_WRAP_IMAGE_DIMS 3 wrap_3_index)
if(ITK_WRAP_PYTHON AND ITK_WRAP_unsigned_char AND wrap_3_index GREATER -1)
itk_python_add_test(NAME LabelOverlapMeasuresImageFilterTest
TEST_DRIVER_ARGS
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/itkLabelOverlapMeasuresImageFilterTest.py
DATA{${test_input_dir}/DzZ_T1.seg.nrrd}
DATA{${test_input_dir}/DzZ_Seeds.seg.nrrd}
)
endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# ==========================================================================
#
# 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.
#
# ==========================================================================*/


import itk
from sys import argv

itk.auto_progress(2)

ref = itk.imread(argv[1], itk.UC)
seg = itk.imread(argv[2], itk.UC)

lom_filter = itk.LabelOverlapMeasuresImageFilter[itk.Image[itk.UC, 3]].New()
lom_filter.SetTargetImage(seg)
lom_filter.SetSourceImage(ref)
lom_filter.UpdateLargestPossibleRegion()
lsm = lom_filter.GetLabelSetMeasures()
for label, measure in lsm.items():
print(f"Label: {label}, i: {measure.m_Intersection}, u: {measure.m_Union}")
1 change: 1 addition & 0 deletions Wrapping/Generators/Python/PyBase/pyBase.i
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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
Loading