vtkimagereslice with vtkimageslab very slow when thickness

Hi everybody,

I am making a curve surface reconstruction successfully with vtkimagereslice and appending every output of the curve to the final image (for each 2 points of the curve i reslice). I use that to obtain a panoramic view. The problem comes when i use vtkimageslab that this process becomes very slow. As i need to make an average of the output slices i cannot use the trick of dimension 2. If i reduce the number of points i get undesired lines.

The problem i have is that everytime i scroll the curve i need to create this panoramic view to get another area of the image. And as this curve is represented as an spline when i modify the spline i also need to update the panoramic view. So i need to have it as fast as possible (real time). I wonder if there is any way to optimize and make this faster.

I was thinking to compute the reconstruction once and keep it in memory and when i scroll, just make the slab (average) of the slices without the reconstruction which is already done. And only to compute it again when the spline representing the curve is moved and released. But the image can be very large so i do not think this is the best way to do it. Any idea?
Thanks

You an create a “straigthened volume” as shown in this script - see how the vtkImageAppend filter is used. You can display/scrolling this volume is real-time.

If you have your application in Python, you can compute projection image using numpy. For example panoramicVolumeArray[0, :, :] = np.flip(straightenedVolumeArray.mean(2).T) produces a projection like this:

You still need to recompute the straightened volume from scratch if the curve is changed. To speed that up, probably you would need to implement resampling on the GPU (or develop hand-crafted assembly code for CPU) for extracting oblique slices from the volume, as not much room left for optimization in vtkImageReslice filter.

Thank you very much for your quick answer. I have checked the script but i am not very familiar with slicer 3d programming. I wonder if the script is doing the same as i do. The problems comes when the thickness is >10. It takes 3 seconds to compute it and i would like to minimize this time otherwise when i scroll, it is hard to follow. So i wonder if slicer 3d is doing something else to optimize the extraction of the volume with thickness. Or it is just resampling the image as you mentioned.

Thank you very much

What is done in the script I referenced above is different in a couple of important aspects.

In general, you cannot compute perpendicular direction by simply setting Z component to 0. Instead, you can use a Frenet-Serret frame.

You can precompute all the slice positions and store it in a volume (that’s the “straightened” volume in my example script). Depending on what resolution you choose, this may take a few seconds, but after that you can traverse the spline and show intersections immediately (no need to compute anything).

You can compute projection image from averaging along one axis instead of thick resampling. This only takes a fraction of a second (I’ve used numpy mean function in the example).

So, the only time-consuming operation is to compute all the orthogonal slices to the dental curve when you modify the curve. To provide interactive update while editing the curve, you can do a quick sparse computation, then if the curve is not modified for a second then start a full-resolution computation in the background.

You can give it a try how the script works in Slicer. Just download a recent preview release, open the Python interactor (hit Ctrl-3) and copy-paste the example script.

Thank you i will try it with the optimizations you suggested. Thank you very much !!

Hi i have changed my implementation based on this script, but i still find vtkimagereslice very slow computing all the slices.

I am using a division of the curve of 0.5mm, and it takes 4 seconds to compute all slices with an output image of [201,615,246].

I reduced the resolution by dividing the curve by 1mm but it is still 3 seconds.

But I also found that when i change the input data of the vtkimageresliceviewer takes almost the same time as the slice calculations.

So for the first case (slices resliced each 0.5mm): it would take 4s (calculating the orthogonal planes) + 3 seconds (setting the input in the vtkimageresliceviewer)

and the second case (slices resliced each 1mm): 2 seconds (planes) + 2 seconds (viewer). So i wonder if the vtkimagereslice is the best opction for curve reformatting of the surface.

Thank you very much

Curved planar reformatting is computationally intensive. 4-6 seconds for a high-resolution image is normal, I wouldn’t expect anything much faster. You can write a GPU-based filter for faster reslicing or implement progressive rendering (render at much lower resolution first to give immediate feedback to the user when curve is changed; continue with full-resolution computation in the background, and update the rendering with the accurate result when it is ready a couple of seconds later).

Thank you very much, i thought vtk used gpu by default. I will try to implement a gpu-based reslicer in the future and by now, i will reduce the lenght of the curve and i will add a loading message when the new image is reconstructed and i will scroll the volume in memory in real time.

Thanks !!

1 Like