Inconsistent results using SimpleITK ChangeLabelLabelMap

Hi I use SimpleITK python, and this is issue is specific to the python wrapper.

I frequently use loops to create remapping dictionary for labelmaps. However, I get an error from ITK :slight_smile:

 in method 'ChangeLabelLabelMap', argument 2 of type 'std::map< double,double,std::less< double >,std::allocator< std::pair< double const,double > > 

when using loops. Below script will illustrate the issue:

img = sitk.Image([10,10], sitk.sitkLabelUInt16)

img[1,2] = 1

remapping = {x:0 for x in np.arange(1, 3)}
result = sitk.ChangeLabelLabelMap(img, remapping)


remapping2 = {1:0, 2:0}
print(remapping == remapping2)

result = sitk.ChangeLabelLabelMap(img, remapping2)
result[1,2]

The issue here is that np.arange returns an iterable of type numpy.in64 and not of int, or float or another type that is implicitly convertible by SWIG to the std::map< double,double> type. The solution is to either use the Python range method or explicitly do a conversion on x in the dictionary generator expression.