@@ -441,19 +441,19 @@ def xarray_from_image(image):
441
441
import numpy as np
442
442
443
443
array_view = itk .array_view_from_image (image )
444
- spacing = itk .spacing (image )
445
- origin = itk .origin (image )
446
- size = itk .size (image )
444
+ l_spacing = itk .spacing (image )
445
+ l_origin = itk .origin (image )
446
+ l_size = itk .size (image )
447
447
direction = np .flip (itk .array_from_matrix (image .GetDirection ()))
448
448
spatial_dimension = image .GetImageDimension ()
449
449
450
450
spatial_dims = ("x" , "y" , "z" )
451
451
coords = {}
452
- for index , dim in enumerate (spatial_dims [:spatial_dimension ]):
452
+ for l_index , dim in enumerate (spatial_dims [:spatial_dimension ]):
453
453
coords [dim ] = np .linspace (
454
- origin [ index ],
455
- origin [ index ] + (size [ index ] - 1 ) * spacing [ index ],
456
- size [ index ],
454
+ l_origin [ l_index ],
455
+ l_origin [ l_index ] + (l_size [ l_index ] - 1 ) * l_spacing [ l_index ],
456
+ l_size [ l_index ],
457
457
dtype = np .float64 ,
458
458
)
459
459
@@ -491,17 +491,17 @@ def image_from_xarray(data_array):
491
491
is_vector = "c" in data_array .dims
492
492
itk_image = itk .image_view_from_array (data_array .values , is_vector = is_vector )
493
493
494
- origin = [0.0 ] * spatial_dimension
495
- spacing = [1.0 ] * spatial_dimension
496
- for index , dim in enumerate (spatial_dims ):
494
+ l_origin = [0.0 ] * spatial_dimension
495
+ l_spacing = [1.0 ] * spatial_dimension
496
+ for l_index , dim in enumerate (spatial_dims ):
497
497
coords = data_array .coords [dim ]
498
498
if coords .shape [0 ] > 1 :
499
- origin [ index ] = float (coords [0 ])
500
- spacing [ index ] = float (coords [1 ]) - float (coords [0 ])
501
- spacing .reverse ()
502
- itk_image .SetSpacing (spacing )
503
- origin .reverse ()
504
- itk_image .SetOrigin (origin )
499
+ l_origin [ l_index ] = float (coords [0 ])
500
+ l_spacing [ l_index ] = float (coords [1 ]) - float (coords [0 ])
501
+ l_spacing .reverse ()
502
+ itk_image .SetSpacing (l_spacing )
503
+ l_origin .reverse ()
504
+ itk_image .SetOrigin (l_origin )
505
505
if "direction" in data_array .attrs :
506
506
direction = data_array .attrs ["direction" ]
507
507
itk_image .SetDirection (np .flip (direction ))
@@ -524,12 +524,12 @@ def vtk_image_from_image(image):
524
524
# Always set Scalars for (future?) multi-component volume rendering
525
525
vtk_image .GetPointData ().SetScalars (data_array )
526
526
dim = image .GetImageDimension ()
527
- spacing = [1.0 ,] * 3
528
- spacing [:dim ] = image .GetSpacing ()
529
- vtk_image .SetSpacing (spacing )
530
- origin = [0.0 ,] * 3
531
- origin [:dim ] = image .GetOrigin ()
532
- vtk_image .SetOrigin (origin )
527
+ l_spacing = [1.0 ,] * 3
528
+ l_spacing [:dim ] = image .GetSpacing ()
529
+ vtk_image .SetSpacing (l_spacing )
530
+ l_origin = [0.0 ,] * 3
531
+ l_origin [:dim ] = image .GetOrigin ()
532
+ vtk_image .SetOrigin (l_origin )
533
533
dims = [1 ,] * 3
534
534
dims [:dim ] = itk .size (image )
535
535
vtk_image .SetDimensions (dims )
@@ -568,12 +568,12 @@ def image_from_vtk_image(vtk_image):
568
568
image = itk .image_view_from_array (array , is_vector )
569
569
570
570
dim = image .GetImageDimension ()
571
- spacing = [1.0 ] * dim
572
- spacing [:dim ] = vtk_image .GetSpacing ()[:dim ]
573
- image .SetSpacing (spacing )
574
- origin = [0.0 ] * dim
575
- origin [:dim ] = vtk_image .GetOrigin ()[:dim ]
576
- image .SetOrigin (origin )
571
+ l_spacing = [1.0 ] * dim
572
+ l_spacing [:dim ] = vtk_image .GetSpacing ()[:dim ]
573
+ image .SetSpacing (l_spacing )
574
+ l_origin = [0.0 ] * dim
575
+ l_origin [:dim ] = vtk_image .GetOrigin ()[:dim ]
576
+ image .SetOrigin (l_origin )
577
577
# Todo: Add Direction with VTK 9
578
578
return image
579
579
@@ -623,7 +623,7 @@ def class_(obj):
623
623
return obj .__class__
624
624
625
625
626
- def python_type (obj ):
626
+ def python_type (object_ref ):
627
627
"""Returns the Python type name of an object
628
628
629
629
The Python name corresponding to the given instantiated object is printed.
@@ -651,37 +651,37 @@ def in_itk(name):
651
651
else :
652
652
return name
653
653
654
- def recursive (obj , level ):
654
+ def recursive (l_obj , level ):
655
655
try :
656
- T , P = template (obj )
656
+ T , P = template (l_obj )
657
657
name = in_itk (T .__name__ )
658
658
parameters = []
659
659
for t in P :
660
660
parameters .append (recursive (t , level + 1 ))
661
661
return name + "[" + "," .join (parameters ) + "]"
662
662
except KeyError :
663
- if isinstance (obj , itkCType ): # Handles CTypes differently
664
- return "itk." + obj .short_name
665
- elif hasattr (obj , "__name__" ):
663
+ if isinstance (l_obj , itkCType ): # Handles CTypes differently
664
+ return "itk." + l_obj .short_name
665
+ elif hasattr (l_obj , "__name__" ):
666
666
# This should be where most ITK types end up.
667
- return in_itk (obj .__name__ )
667
+ return in_itk (l_obj .__name__ )
668
668
elif (
669
- not isinstance (obj , type )
670
- and type (obj ) != itkTemplate .itkTemplate
669
+ not isinstance (l_obj , type )
670
+ and type (l_obj ) != itkTemplate .itkTemplate
671
671
and level != 0
672
672
):
673
- # obj should actually be considered a value, not a type,
673
+ # l_obj should actually be considered a value, not a type,
674
674
# or it is already an itkTemplate type.
675
675
# A value can be an integer that is a template parameter.
676
676
# This does not happen at the first level of the recursion
677
677
# as it is not possible that this object would be a template
678
678
# parameter. Checking the level `0` allows e.g. to find the
679
679
# type of an object that is a `list` or an `int`.
680
- return str (obj )
680
+ return str (l_obj )
681
681
else :
682
- return in_itk (type (obj ).__name__ )
682
+ return in_itk (type (l_obj ).__name__ )
683
683
684
- return recursive (obj , 0 )
684
+ return recursive (object_ref , 0 )
685
685
686
686
687
687
def image_intensity_min_max (image_or_filter ):
@@ -1107,11 +1107,13 @@ class __templated_class_and_parameters__:
1107
1107
to instantiate.
1108
1108
"""
1109
1109
1110
- def __init__ (self , templated_class , template_parameters ):
1111
- self .__templated_class__ = templated_class
1112
- self .__template_parameters__ = template_parameters
1113
- if "check_template_parameters" in dir (templated_class .__cls__ ):
1114
- templated_class .__cls__ .check_template_parameters (template_parameters )
1110
+ def __init__ (self , l_templated_class , l_template_parameters ):
1111
+ self .__templated_class__ = l_templated_class
1112
+ self .__template_parameters__ = l_template_parameters
1113
+ if "check_template_parameters" in dir (l_templated_class .__cls__ ):
1114
+ l_templated_class .__cls__ .check_template_parameters (
1115
+ l_template_parameters
1116
+ )
1115
1117
1116
1118
def New (self , * args , ** kargs ):
1117
1119
"""A New() method to mimic the ITK default behavior, even if the
@@ -1199,7 +1201,7 @@ def clear(self):
1199
1201
"""
1200
1202
self .filters = []
1201
1203
1202
- def GetOutput (self , index = 0 ):
1204
+ def GetOutput (self , l_index = 0 ):
1203
1205
"""Return the output of the pipeline
1204
1206
1205
1207
If another output is needed, use
@@ -1212,11 +1214,11 @@ def GetOutput(self, index=0):
1212
1214
else :
1213
1215
filter = self .filters [- 1 ]
1214
1216
if hasattr (filter , "__getitem__" ):
1215
- return filter [index ]
1217
+ return filter [l_index ]
1216
1218
try :
1217
- return filter .GetOutput (index )
1219
+ return filter .GetOutput (l_index )
1218
1220
except Exception :
1219
- if index == 0 :
1221
+ if l_index == 0 :
1220
1222
return filter .GetOutput ()
1221
1223
else :
1222
1224
raise ValueError ("Index can only be 0 on that object" )
0 commit comments