SimpleITK/Design And Proposals/SIP 002

From KitwarePublic
Jump to navigationJump to search

SIP 002 - Data Bridge for SimpleITK

Introduction

SimpleITK is an emerging useful tool for image analysis, segmentation and registration by providing a simplified interface to ITK in variety of programming language. However, many users implement and develop their image processing methods with the N-dimensional array object and functions of the Numpy package in parallel.

To support data transparency between the functions of SimpleITK and NumPy, SimpleITK provides functional integration with NumPy-based script and a method of data-conversion between SimpleITK’s image data and the N-dimensional array object of NumPy. But, there is a significant performance bottleneck in the data-conversion which is based on the operation of data copy. The performance bottleneck can be increased with the size of handling image data and the number of data-conversion.

We wish to remove the performance bottleneck by allowing SimpleITK’s image and the arrays of NumPy to share pointers to the same memory symmetrically with copy-on-write semantics. In addition, we wish these enhancements will deliver the performance improvements to many existing SimpleITK’s scripts through a simple library update.

Comments

Brad Lowekamp: What exactly are the proposed interfaces? Currently there is sitk::GetArrayFromImage(), and you are proposing keeping that with enhancements. Is there also going to be a new more Pythonic interface? Can the Image directly be a buffer object so that is can be passed to methods which use this interface? Or could we a method such as sit.Image.from_array or numpy.asarray(sitk.Image(...))?

Reduce data-copy operations in the data conversion

Reduction data-copy operation in the data conversion can be accomplished by developing and/or improving existing data handling methods in ITK and SimpleITK to enable copy-on-write sharing of data between SimpleITK’s image data and other common data object of Python libraries used for scientific computing and image processing. NumPy is our primarily considered library because the N-dimensional data array of the NumPy package can be integrated with and expanded to other libraries such as Pandas and libdynd.

In terms of technical approach, this work will include implementing the buffer interface [1] and improving the ITK ImportImageContainer [2] for sharing a data pointer between SimpleITK’s image data and the N-dimensional array object of NumPy.

The improved data handling methods in SimpleITK will expose an image data of SimpleITK with the buffer interface [3]. This method of data handling will utilized the buffer and memoryview constructs in CPython 2 [4] and the buffer protocol in CPython 3 [5].

Comments

Brad Lowekamp:

 * What are the specific copy-on-write policies?
 * Should the exported array be read only?
 * Will there be an option to get a writable array to modify an existing image in place?

"