Generating a mesh from noisy medical data

Hello everyone, I have some rather noisy medical data (from a 3D Microscope), and I’ve been exploring it with ParaView, and I’d like to export some data into another application that I have that is able to render OBJ files (well aware of the shortcomings of using OBJ). I have a pipeline state that works, but I’d like to reduce the noise – the polygons are all jagged, and for this I really want to get something that gives an overall gist of the data, and then my other tool can be used to look at the details.

While Googling and “chatting” I got some suggestions that maybe some ITK filters would be a good option, so first I wonder, since ITK is more medical oriented, perhaps that is a direction I should be looking, and second, is there a way to access ITK filters from inside ParaView (perhaps using a “Programmable Filter”)?

My current pipeline is basically:
3D-Microscope data.vti
ResampleToImage
Programable Filter (using vtkImageAnisotropicDiffusion3D)
Contour
ExtractSurface
Connectivity
Clean
Triangulate
QuadraticDecimation
ProgrammableFilter (using vtkWindowdSincPolyDataFilter)

Then → Save Data as OBJ
(which I’d like for each region to have it’s own material, but the OBJ writer doesn’t seem to do that, perhaps because it’s a very old format.)

Any general advice? Thanks, Bill

No, at least not with the conventional binary release, although it may be possible with some python magic.

Can you use anything else but OBJ format ? glTF comes to mind.

Okay, Thanks Mathieu. I guess, since to some degree I’d like to get to the point where I can just write a script that processes the data and outputs a model, so maybe I should just look at ITK? I use ParaView because I’m most familiar with it, but if ITK has better tools for medical data, maybe I should consider it.

Regarding OBJ vs. glTF: sure, I could use glTF. My big desire is to better process the data into something that gives an overall impression of the data – and then the user can interrogate further through interaction. So I can work with glTF – it just so happens that I have an OBJ reader in my tool already, but I can work around that.

Thanks.

While ITK is definitely a powerfull tool for medical, it doesnt seem required here.

Using File → ExportScene into glTF at the end of your pipeline instead should do the trick imo.

Well, I guess I may have over emphasized the last stage of what I need. My main desire is a way to import 3D medical data (in this case a 3D Microscope scan), and filter it to where it does a better job of showing some of the 3D structures in the data. I can iso-surface it now with the Contour filter, but it’s very very noisey, and with the pipeline above, I tried to tame that down a bit, but not yet to what I am hoping for.

Could you share a screenshot of what you want to export ?

I suggest starting by installing ITK into a Python virtual environment with pip install itk and then write some scripts to process the data without ParaView at first. Maybe that will get you what you need.

If not, then you might be able to use ParaView’s --venv option to point to your virtual environment with ITK installed and then you would have access to it in a Programmable Filter and other places – if it all works. Since ITK brings with it compiled libraries, it wouldn’t surprise me if you run into some incompatibility that might make it so that you can at least load the ITK python module. Then, if that all works, you’ll have to bridge the gap between the VTK data objects and ITK data objects. It has been a long time since I’ve done this, but maybe you could use their respective NumPy interfaces to do easy data exchange.

Cory, Mathieu, thanks.

Mathieu, I’m attaching a screen shot of the data, and you can see how rough it is. I’m coloring it by RegionID to try to highlight some of the little “floating” blobs. But again, I’m actually less concerned about the exporting than I am the filtering to smooth things out.

Cory, okay, thanks. I suppose I should thus go to the ITK Discourse to find out what filters would be the good ones! I thought maybe there’d be enough cross-over that I could get all my answers from a one-stop shop!

Personally it’s been a long time since I’ve used ITK, and we don’t get many image processing/analysis questions on the ParaView forum. A ParaView-adjacent application, tomviz, is more focused on 3D image data, and has concepts similar to ParaView in terms of loading data, applying operators, and so on.

You might also want to try Slicer to do image processing/analysis with ITK but without programming. It’s similar to ParaView in that it is an end-user application, but it is much more tailored to image data specifically.

Okay, thanks Cory – when you say “Image data”, you’re using the VTK/ParaView terminology for that, whereby an Image can be 3D, yes?

Indeed, yes, a regular grid in 3D, with regular constant between samples in each dimension.

@wsherman there is also GitHub - OpenChemistry/tomviz: Cross platform, open source application for the processing, visualization, and analysis of 3D tomography data which is more ‘near’ paraview style.

@cory.quammen would it be possible to at some point on the small video tutorials that kitware does and publish online, to teaking with ITK inside paraview? I would love to continue working in paraview isntead of swiching to slicer or tomviz, as i have a quite developed workflow inside of it. but right now i really need to use ITK tools, would be great to see some expert giving some dummy examples, as:

  1. install ITK inside paraview
  2. ‘check what ITK can do’
  3. select something interesting from ITK library
  4. bring it back to paraview

please consider this, funny enought just today I made a post about this paraview for image treatment (3D scan, tif format) - #3 by otaolafr and while searching for this the answers on ‘what is possible to do and how to do with paraview +ITK’ is quite sparse….

We’ll definitely consider it if we find ourselves doing work that uses ITK in ParaView.

1 Like

This looks promising on my Mac with a development build of ParaView.

python3 -m venv ~/itkvenv
source ~/itkvenv/bin/activate
pip install ~/itkvenv
bin/paraview.app/Contents/MacOS/paraview --venv ~/itkvenv

Add Wavelet source, add Programmable Filter and set it’s Script to

import itk
itk_image = itk.image_from_vtk_image(inputs[0])

input_type = itk.Image[itk.F,3]
output_type = itk.Image[itk.D,3]
caster = itk.cast_image_filter(itk_image, ttype=(input_type, output_type))
caster.Update()

vtk_result = itk.vtk_image_from_image(caster)
output.ShallowCopy(vtk_result)

The Wavelet source produces a vtkImageData with floats, and this programmable script casts that image to a vtkImageData of doubles.

Input image info:

Output image info (note the array type is “double” instead of “float”):

It’s maybe not the most useful example, but it demonstrates that ITK can be used within ParaView’s Python environment using virtual environments and a pip-installed ITK.

I have not tried this with a binary from paraview.org, but it should work as long as you create your virtual environment such that it installs compatible ITK Python modules. See Install any python package for the ParaView binary release using pip for more info about that.

2 Likes

Great, thanks for checking Cory.

Definitely worth a post in Tips and Tricks - ParaView :slight_smile:

1 Like