[vtkusers] Problems using vtkConnectivityFilter on Image Data
David Gobbi
david.gobbi at gmail.com
Fri Nov 6 17:36:42 EST 2015
Hi Darya,
The math for the indices should be the other way around.
If you already have the voxel indices, then compute the point
coordinates like this:
x = origin[0] + xyz[0]*spacing[0]
etc. for y and z
seed.InsertNextPoint(x,y,z)
Also, of course, if ThresholdByUpper(1) doesn't work, then also
try ThresholdByLower(1). The names of those two methods always
confuses me, and I always forget which method does what...
- David
On Fri, Nov 6, 2015 at 12:40 PM, Darya Yelshyna <darya.yelshyna at yahoo.com>
wrote:
> I guess I figured out what are real coordinates, but I still don't get my
> connected region. This is my code:
>
> seed = vtk.vtkPoints()
> i = (xyz[0] - origin[0]) / spacing[0]
> j = (xyz[1] - origin[1]) / spacing[1]
> k = (xyz[2] - origin[2]) / spacing[2]
> seed.InsertNextPoint(i, j, k)
>
> connectFilter = vtk.vtkImageThresholdConnectivity()
> connectFilter.SetInputConnection(dilateFilter.GetOutputPort())
> connectFilter.SetSeedPoints(seed)
> connectFilter.ThresholdByUpper(1)
> connectFilter.ReplaceInOn()
> connectFilter.SetInValue(1)
> connectFilter.ReplaceOutOn()
> connectFilter.SetOutValue(0)
> connectFilter.Update()
>
> My image is a vtkImageData CT head scan with values 0 and 1. The value 1
> corresponds to segmented head and some artifacts, which I want to remove
> (they are disconnected from the head). My xyz point is a voxel that lies
> within the head region ( I checked, its value is 1 in the dilateFilter
> output). The output from vtkImageThresholdConnectivity is a image filled
> with 0. What am I doing wrong?
>
> Thank you all in advance.
>
> Best regards,
> Darya
>
>
>
> On Friday, November 6, 2015 7:06 PM, Darya Yelshyna <
> darya.yelshyna at yahoo.com> wrote:
>
>
> Thank you so much for your reply!
> I am using Python wrapping to access VTK and I don't know how to
> add vtkImageConnectivityFilter. I am trying to
> use vtkImageThresholdConnectivity and I am a little confused with setting
> the seed. The seeds should be in real data coordinates, not in voxel
> index locations. How do I retrieve these coordinates from X, Y and Z
> indexes?
>
> Sorry for inconveniece.
>
> Best regards,
> Darya
>
>
>
> On Friday, November 6, 2015 5:49 PM, David Gobbi <david.gobbi at gmail.com>
> wrote:
>
>
> Hi Darya,
>
> The vtkConnectivityFilter is meant for use on mesh data. It suspect
> that when you used it on image data, it caused your computer to run
> out of memory.
>
> I have a connectivity filter that I wrote specifically for images, but it
> is on github. I haven't contributed it to VTK yet. But you can try it
> if you are interested:
>
> https://github.com/dgobbi/AIRS/tree/master/ImageSegmentation
>
> You can also try the vtkImageThresholdConnectivity filter that comes
> with VTK:
> http://www.vtk.org/doc/nightly/html/classvtkImageThresholdConnectivity.html
>
> - David
>
>
>
> On Fri, Nov 6, 2015 at 10:36 AM, Darya Yelshyna via vtkusers <
> vtkusers at vtk.org> wrote:
>
> Hi everyone!
>
> I was trying to apply vtkConnectivityFilter to vtkImageData, but the
> program crashes at this step.
> "This application has requested the Runtime to terminate it in an unusual
> way." This is this a part of my code:
>
> dilateFilter = vtk.vtkImageContinuousDilate3D()
> dilateFilter.SetKernelSize(5, 5, 5)
> dilateFilter.SetInputConnection(logic2.GetOutputPort())
> dilateFilter.Update()
>
> connectFilter = vtk.vtkConnectivityFilter()
> connectFilter.SetExtractionModeToLargestRegion()
> connectFilter.SetInputConnection(dilateFilter.GetOutputPort())
> connectFilter.Update()
>
> I don't understand what is happening.. Can anybody help me?
>
> Thank you in advance.
>
> Best regards,
> Darya
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20151106/816a5c67/attachment.html>
More information about the vtkusers
mailing list