Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_non_contiguous_array():
"Check that a non-contiguous array raises the appropriate error"
data = np.random.random((10, 10, 10))
data = data[..., 0] # slicing the array makes it non-contiguous
output = to_itk_image(data)
assert isinstance(output, itk.Image)
order : int, optional
Spline order for line profile interpolation. The order has to be in the
range 0-5.
"""
if image_or_array is None:
image_or_array = self.image
if point1 is None:
point1 = self.point1
if point2 is None:
point2 = self.point2
if order is None:
order = self.order
image_from_array = to_itk_image(image_or_array)
if image_from_array:
image_ = image_from_array
else:
image_ = image_or_array
image_array = itk.array_view_from_image(image_)
dimension = image_.GetImageDimension()
distance = np.sqrt(
sum([(point1[ii] - point2[ii])**2 for ii in range(dimension)]))
index1 = tuple(image_.TransformPhysicalPointToIndex(
tuple(point1[:dimension])))
index2 = tuple(image_.TransformPhysicalPointToIndex(
tuple(point2[:dimension])))
num_points = int(np.round(
np.sqrt(sum([(index1[ii] - index2[ii])**2 for ii in range(dimension)])) * 2.1))
coords = [np.linspace(index1[ii], index2[ii], num_points)
for ii in range(dimension)]
pattern : int, optional, default: 3
Size of the checkerboard pattern.
invert : bool, optional, default: False
Swap inputs.
viewer_kwargs : optional
Keyword arguments for the viewer. See help(itkwidgets.view).
"""
itk_image1 = to_itk_image(image1)
if not itk_image1:
itk_image1 = itk.output(image1)
itk_image2 = to_itk_image(image2)
if not itk_image2:
itk_image2 = itk.output(image2)
input1 = itk_image1
input2 = itk_image2
region_image1 = itk_image1.GetLargestPossibleRegion()
region_image2 = itk_image2.GetLargestPossibleRegion()
same_physical_space = \
np.allclose(np.array(itk_image1.GetOrigin()), np.array(itk_image2.GetOrigin())) and \
np.allclose(np.array(itk_image1.GetSpacing()), np.array(itk_image2.GetSpacing())) and \
itk_image1.GetDirection() == itk_image2.GetDirection() and \
np.allclose(np.array(region_image1.GetIndex()), np.array(region_image2.GetIndex())) and \
np.allclose(
np.array(
region_image1.GetSize()), np.array(
region_image2.GetSize()))
image2 : array_like, itk.Image, or vtk.vtkImageData
Second image to use in the checkerboard.
pattern : int, optional, default: 3
Size of the checkerboard pattern.
invert : bool, optional, default: False
Swap inputs.
viewer_kwargs : optional
Keyword arguments for the viewer. See help(itkwidgets.view).
"""
itk_image1 = to_itk_image(image1)
if not itk_image1:
itk_image1 = itk.output(image1)
itk_image2 = to_itk_image(image2)
if not itk_image2:
itk_image2 = itk.output(image2)
input1 = itk_image1
input2 = itk_image2
region_image1 = itk_image1.GetLargestPossibleRegion()
region_image2 = itk_image2.GetLargestPossibleRegion()
same_physical_space = \
np.allclose(np.array(itk_image1.GetOrigin()), np.array(itk_image2.GetOrigin())) and \
np.allclose(np.array(itk_image1.GetSpacing()), np.array(itk_image2.GetSpacing())) and \
itk_image1.GetDirection() == itk_image2.GetDirection() and \
np.allclose(np.array(region_image1.GetIndex()), np.array(region_image2.GetIndex())) and \
np.allclose(
def validate(self, obj, value):
self._source_object = value
image_from_array = to_itk_image(value)
if image_from_array:
return image_from_array
try:
# an itk.Image or a filter that produces an Image
# return itk.output(value)
# Working around traitlets / ipywidgets update mechanism to
# force an update. While the result of __eq__ can indicate it is
# the same object, the actual contents may have changed, as
# indicated by image.GetMTime()
value = itk.output(value)
grafted = value.__New_orig__()
grafted.Graft(value)
return grafted
except BaseException:
self.error(obj, value)