current development SimpleITK

I have a script that loads a tiff image using tifffile into numpy and converted to sitk, and apply a transform stack on the image. It works with an older version of SimpleITK but not the latest.

The latest version of SimpleITK installed with:
pip install --upgrade --pre SimpleITK --find-links https://github.com/SimpleITK/SimpleITK/releases/tag/latest

It processes the files up until the 18th transform and then gives this weird error that I don’t get when running the same script with the last release version (simpleitk-1.2.2):

I understand what it’s saying to the extent that there is a mismatch in the images sizes, but I don’t know how to debug it or maybe flush some kind of cache or wait until the image has been fullly read?

the moving image (17, 18)
Debug: ResampleImageFilter (0x7fbe26e9f1a0): Executing ITK filter:
ResampleImageFilter (0x7fbe2710e390)
  RTTI typeinfo:   itk::ResampleImageFilter<itk::Image<unsigned char, 2u>, itk::Image<unsigned char, 2u>, double, double>
  Reference Count: 1
  Modified Time: 18042
  Debug: Off
  Object Name: 
  Observers: 
    DeleteEvent(SimpleMemberCommand)
  Inputs: 
    Primary: (0x7fbe2710b910) *
    ReferenceImage: (0x0)
    Transform: (0x7fbe2710ea40) *
  Indexed Inputs: 
    0: Primary (0x7fbe2710b910)
    1: ReferenceImage (0x0)
  Required Input Names: Primary, Transform
  NumberOfRequiredInputs: 1
  Outputs: 
    Primary: (0x7fbe2710e530)
  Indexed Outputs: 
    0: Primary (0x7fbe2710e530)
  NumberOfRequiredOutputs: 1
  Number Of Work Units: 4
  ReleaseDataFlag: Off
  ReleaseDataBeforeUpdateFlag: Off
  AbortGenerateData: Off
  Progress: 0
  Multithreader: 
    RTTI typeinfo:   itk::PoolMultiThreader
    Reference Count: 1
    Modified Time: 18011
    Debug: Off
    Object Name: 
    Observers: 
      none
    Number of Work Units: 4
    Number of Threads: 4
    Global Maximum Number Of Threads: 128
    Global Default Number Of Threads: 4
    Global Default Threader Type: PoolMultiThreader
    SingleMethod: 0
    SingleData: 0x0
  DynamicMultiThreading: On
  CoordinateTolerance: 1e-06
  DirectionTolerance: 1e-06
  DefaultPixelValue: 243
  Size: [1024, 1024]
  OutputStartIndex: [0, 0]
  OutputSpacing: [4.04, 4.04]
  OutputOrigin: [0, 0]
  OutputDirection: 1 0
0 1

  Transform: 0x7fbe26d4b300
  Interpolator: 0x7fbe2710e850
  Extrapolator: 0x0
  UseReferenceImage: Off


Traceback (most recent call last):
  File "create_stack.py", line 217, in <module>
    main()
  File "create_stack.py", line 178, in main
    mean = utils.get_mean_edges(t_sitk)
  File "/Users/sansomk/code/python/Tools/hist/utils.py", line 205, in resample_1_rgb
    new_image = filter_.Execute(t_sitk)
  File "/Users/sansomk/anaconda3/envs/reg/lib/python3.7/site-packages/SimpleITK/SimpleITK.py", line 59346, in Execute
    return _SimpleITK.ResampleImageFilter_Execute(self, *args)
RuntimeError: Exception thrown in SimpleITK ResampleImageFilter_Execute: /Users/runner/runners/2.164.7/work/1/sitk/Code/Common/src/sitkPimpleImageBase.hxx:75:
sitk::ERROR: The image has a LargestPossibleRegion of ImageRegion (0x7fbe2710ba50)
  Dimension: 2
  Index: [0, 0]
  Size: [1024, 1024]
 while the buffered region is ImageRegion (0x7fbe2710baa0)
  Dimension: 2
  Index: [0, 0]
  Size: [1024, 971]

SimpleITK does not support streamming or unbuffered regions!
1 Like

Hello,

In general the release version should be preferred unless a feature under development is required.

To help debug your problem, when you use the object oriented interface, you can set “DebugOn”, which will print additional information about the ITK filter. You can also print information about the input images before execution too.

Please post a minimal self contained example to reproduce your issue. Currently, I can’t even tell what filter is producing this error, much less the parameters used to configure.

I was trying to use the image pickling and transform pickling at the end of the script.
I updated my text with more info. I apologize for not adding more to begin with.
It appears to be in the resample image filter.

I will need to pair it down to simple example, but the main difference I see so far is that the release version uses itk::MultiThreader versus the latest uses itk::PoolMultiThreader

here is a somewhat minimum example:

import SimpleITK as sitk
import numpy as np

def resample_1_rgb_test(in_transform, t_sitk, mean = 0):
  filter_ = sitk.ResampleImageFilter()
  filter_.DebugOn()
  filter_.SetInterpolator(sitk.sitkLinear)
  filter_.SetSize(t_sitk.GetSize())
  filter_.SetReferenceImage(t_sitk)
  filter_.SetTransform(in_transform)
  filter_.SetDefaultPixelValue(mean)
  filter_.SetOutputPixelType(sitk.sitkVectorUInt8)
  new_image = filter_.Execute(t_sitk)
  return new_image

def get_mean_edges(itk_image):
  # get the edge values to determine the mean pixel intensity
  l_side = sitk.GetArrayViewFromImage(itk_image)[0,:].flatten()
  r_side = sitk.GetArrayViewFromImage(itk_image)[-1,:].flatten()
  top_side =  sitk.GetArrayViewFromImage(itk_image)[0][1:-2].flatten()
  bot_side = sitk.GetArrayViewFromImage(itk_image)[-1][1:-2].flatten()
  mean = int(np.concatenate((l_side, r_side, top_side, bot_side)).mean())
  return mean

affine_center = (20, 20, 20)
affine_translation = (5,6) 
size_x = 1024
size_y = 1024
grid_r = sitk.GridSource(outputPixelType=sitk.sitkUInt8,
    size=(size_x, size_y),
    sigma=(0.1, 0.1),
    gridSpacing=(3.0, 3.0),
    gridOffset=(0.0, 0.0),
    spacing=(0.2,0.2))
grid_g = sitk.GridSource(outputPixelType=sitk.sitkUInt8,
    size=(size_x, size_y),
    sigma=(0.5, 0.5),
    gridSpacing=(5.0, 5.0),
    gridOffset=(0.0, 0.0),
    spacing=(0.2,0.2))
grid_b = sitk.GridSource(outputPixelType=sitk.sitkUInt8,
    size=(size_x, size_y),
    sigma=(1.0, 1.0),
    gridSpacing=(13.0, 13.0),
    gridOffset=(0.0, 0.0),
    spacing=(0.2,0.2))

compose_new = sitk.ComposeImageFilter()

grid_rgb = compose_new.Execute(grid_r, grid_g, grid_b)
mean_edges = get_mean_edges(grid_rgb)
# Matrix is represented as a vector-like data in row major order.
composite_transform = sitk.Transform(2, sitk.sitkEuler)
for i in range(20):
  euler2d_transform = sitk.Euler2DTransform()
  euler2d_transform.SetTranslation(affine_translation)
  euler2d_transform.SetAngle(np.random.random_sample()*2.0*np.pi)
  composite_transform.AddTransform(euler2d_transform)
  composite_transform.FlattenTransform()
  trans_image = resample_1_rgb_test(composite_transform,
                                      grid_rgb,
                                      mean = mean_edges )
  #utils.display_image(sitk.GetArrayFromImage(im_mask_t))

If I change the line grid_rgb = compose_new.Execute(grid_r, grid_g, grid_b) to
grid_rgb = compose_new.Execute(grid_r) no exception is thrown.

1 Like

Hello,

Thank you for providing the example. Although the utils modes was not provided and the example couple have been a little smaller :wink:

This was an interesting bug related the new ITKv5 support for streaming in the ResampleImageFilter, and the way SimpleITK runs filters per component some times.

Here is the PR which address the issue:

2 Likes

Ahh missed that one… fixed it up, but you’ve already got the change merged!

Thank you so much for the help, that was faster than any VTK bug fix I ever saw.

2 Likes

Please test the “latest” binaries on Github for the fix. Thanks.

2 Likes

it works! thank you.

1 Like