[vtkusers] Extracting largest region works with vtkPolyDataConnectivityFilter, but not with vtkConnectivityFilter
lackodan at outlook.com
Wed Jun 8 11:56:57 EDT 2016
First of all, it's amazing how fast you and the other contributers on this list respond. Thanks for making the time!
While your filter does indeed look better (and even has comprehensive comments explaining each step), I suspect it would not be easy to use with my precompiled VTK-version in Anaconda. If I'm not mistaking, to use custom VTK classes, you need a custom VTK build, right? I don't think that will be possible. I'm on a tight time schedule (I need to finish my current project ASAP so I have a chance at finishing my PhD thesis before August) and I only have a basic image processing background, so I'm currrently looking for the fastest and easiest solution.
This might be a very obvious question, but with vtkImageConnectivityFilter, how would I know which seed point to use? Should I look at the image in Paraview (or use a vtkPicker) to find the coordinates of the region I'd like to extract?
From: david.gobbi at gmail.com
Date: Wed, 8 Jun 2016 09:06:14 -0600
Subject: Re: [vtkusers] Extracting largest region works with vtkPolyDataConnectivityFilter, but not with vtkConnectivityFilter
To: lackodan at outlook.com
CC: vtkusers at vtk.org
Within VTK proper, there's the vtkImageThresholdConnectivity filter, but itrequires you to seed the regions you want, it can't just give you the largest:http://www.vtk.org/doc/nightly/html/classvtkImageThresholdConnectivity.html
I have a better filter called simply "vtkImageConnectivityFilter", but it hasn'tmade its way into VTK yet:https://github.com/dgobbi/AIRS/blob/master/ImageSegmentation/vtkImageConnectivityFilter.h
On Wed, Jun 8, 2016 at 8:52 AM, D L <lackodan at outlook.com> wrote:
Today, I'm having some trouble understanding how to use vtkConnectivityFilter in python 2.7 and VTK6.3. I've consulted a number of resources and examples, including:
However, I still can't figure out how to use the filter. I have a number of operations in mind, but let's start with extracting the largest region. From the available documentation, I assumed that this could be done by using vtkConnectivityFilter.SetExtractionModeToLargestRegion(). However, when I apply this to a (segmented and thresholded) MRI image to remove some noise, it just extracts the entire image. On the other hand, if I convert it to a surface first, using vtkMarchingCubes, and then apply a vtkPolyDataConnectivityFilter, that does give me the expected result...
Here's a minimal example I'm using to test and compare:
niftiReader = vtk.vtkNIFTIImageReader()
thresholdedImage = niftiReader.GetOutput()
# vtkConnectivityFilter - doesn't work
connectivity = vtk.vtkConnectivityFilter()
print("\nvtkConnectivityFilter number of extracted regions: " +
# outputs 1
# Connectivity filter produces an unstructured grid; convert back
# to image data for further use.
probeFilter = vtk.vtkProbeFilter()
marchingCubes = vtk.vtkMarchingCubes()
marchingCubes.GenerateValues(1,1,1) # input was thresholded with 1 as output value
stlWriter = vtk.vtkSTLWriter()
# vtkPolyDataConnectivityFilter - works as expected
marchingCubes2 = vtk.vtkMarchingCubes()
connectivity2 = vtk.vtkPolyDataConnectivityFilter()
print("\nvtkPolyDataConnectivityFilter number of extracted regions: " +
# outputs 1673
stlWriter2 = vtk.vtkSTLWriter()
The input volume can downloaded here: https://onedrive.live.com/redir?resid=C74503A42DE708!3267&authkey=!AMjKnLDNfJzYxGo&ithint=file%2cnii
The end result when using vtkConnectivityFilter: https://onedrive.live.com/redir?resid=C74503A42DE708!3269&authkey=!ACgeZNYmu0yYYTQ&ithint=file%2cstl
The end result when using vtkPolyDataConnectivityFilter: https://onedrive.live.com/redir?resid=C74503A42DE708!3268&authkey=!ADAeoPw8O09APE8&ithint=file%2cstl
The reason I want to apply the connectivity filter before surface extraction is that I would like to so some other morphological operations on the image first (e.g. closing and flood fill). At first, I assumed it might have something to do with scalar connectivity, but using vtkConnectivityFilter.SetScalarConnectivityOff() didn't change anything.
Could someone with a better understanding of VTK please explain?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the vtkusers