Write to output volume slice by slice or subvolume by subvolume in a pipeline

Hi all,

I have 3D data on which I want to do operations that are independent of each other along the third dimension. I could for example work independently on 2D slices in the two first dimensions or on subvolumes which have only a limited extend in the third dimension.

I would like to build a low-latency pipeline of filters, say A and B, that perform this kind of operations on slices or subvolumes and iteratively construct the output, e.g. slice by slice or subvolume by subvolume.

I have tried to connect source -> A -> B and in each iteration in a loop set a single slice or subvolume as a requested region of B. The problem is that the output of B gets reallocated every time I change the requested region so that the buffered region is only as large as the requested region. All my previously computed data is lost here.

Ideally, I would like B to output INTO a volume that I keep (without an extra copy). The design of ITK seems to put responsibility of allocating output on the producer, so this might not be possible.

What options do I have here?

Have you looked at the SliceBySliceImageFilter, it should do exactly what you are looking to do. There is an associated Insight Journal Article: “Slice by slice filtering with ITK

Alternatively you could look at using the PasteImageFilter with the “InPlace” option enabled. Computing the proper index, and sizes can be a tedious operation. Efficient use of buffers and reuse of memory is a complex problem, and very application and pipeline dependent. I would recommend not prematurely optimizing this.