I experimented a bit with different iteration schemes in vigra, and ended up in stealing the one used in labelVolume: Some nested functions that split the multi array into a list of iterators, shapes and accessors. I am not quite sure why this works so much better than the CoupledIterator approach (about a factor of 10 I’d say), but I will stick to that. The original algorithm from which I’m stealing is regrettably just for 3-dimensional arrays, but I wanted to be a bit more generic.

The new and improved mergeLabels function calls itself recursively for every slice of the outermost dimension. This takes about 1.5 times as long, but we don’t have to keep several versions of the merging function for different dimensions lying around. What also helped in improving speed is to bind singleton dimensions — this could be an indicator that the recursive function calls are not inline’d and therefore causing the .5 overhead.

I keep this improvements separate from the current developments in lazyflow (aka OpLazyConnectedComponents) because I wanted to just mess around with this. For the next week I will return to making the operator work smoothly and for general dimensions — I got the feeling that I spend to much time looking at template error messages.

Selah.

Follow-Up: http://burgerdev.de/getting-there/