vtkImageThresholdConnectivity with Fiducial

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

vtkImageThresholdConnectivity with Fiducial

Sebastian
Hi everyone,

I’m trying to use the vtkImageThresholdConnectivity filter in combination with the fiducials of Slicer. Every fiducial Markup should be a seed point.
Unfortunately the resulting outputVolume just contains the OutValue.

Maybe the problem is the conversion of the fiducials’ coordinate System? I tried to convert the Points to RAS, XYZ and IJR, but nothing worked.
Please find the code of my def below.

Thank you very much,
Sebastian


def thresholdConnected(self ,inputVolume, outputVolume, clippingMarkup):

    image = inputVolume.GetImageData()
    print image.GetBounds()

    sliceNode = slicer.mrmlScene.GetNthNodeByClass(0, 'vtkMRMLSliceNode')
    appLogic = slicer.app.applicationLogic()
    sliceLogic = appLogic.GetSliceLogic(sliceNode)
    layerLogic = sliceLogic.GetLabelLayer()

    points = vtk.vtkPoints()
    numberOfPoints = clippingMarkup.GetNumberOfFiducials()

    points.SetNumberOfPoints(numberOfPoints)

    coordsRAS = [0,0,0]
    coordsXYZ = [0,0,0]

    for i in range(numberOfPoints):
      clippingMarkup.GetNthFiducialPosition(i, coordsRAS)
      slicer.vtkMRMLAbstractSliceViewDisplayableManager.ConvertRASToXYZ(sliceNode,coordsRAS,coordsXYZ)
      xyToIJK = layerLogic.GetXYToIJKTransform()
      coordsIJK = xyToIJK.TransformDoublePoint(coordsXYZ)
      points.SetPoint(i, coordsIJK)
      print coordsXYZ, coordsIJK, coordsRAS


    imageThreshold = vtk.vtkImageThresholdConnectivity()
    #imageThreshold = vtk.vtkImageThreshold()
    imageThreshold.SetInputData(image)
    lower = 200;
    upper = 3000;

    imageThreshold.ThresholdBetween(lower, upper)
    imageThreshold.SetSeedPoints(points)
    imageThreshold.ReplaceInOn()
    #imageThreshold.ReplaceOutOn()
    imageThreshold.SetInValue(2000)
    #imageThreshold.SetOutValue(-1000)
    #print imageThreshold.GetNeighborhoodRadius()
    imageThreshold.SetNeighborhoodRadius(100,100,100)
    imageThreshold.Update()

    outputVolume.SetImageDataConnection(imageThreshold.GetOutputPort())
_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: vtkImageThresholdConnectivity with Fiducial

lasso2
I've already implemented a segment editor thresholding effect that uses vtkImageThresholdConnectivity:
https://github.com/lassoan/SlicerSegmentEditorExtraEffects/tree/master/SegmentEditorFloodFilling

You can use this as is or modify it. I haven't included this effect in the segment editor (and other effects that I've implemented, such as Fast marching and Watershed) because - based on my experience - Grow from seeds effect (fast grow-cut) usually works better in practice: 1. you can guide the segmentation by adding more hints (more seeds) interactively,  2. it is very fast.

Andras

-----Original Message-----
From: slicer-devel [mailto:[hidden email]] On Behalf Of Sebastian
Sent: April 7, 2017 15:08
To: SPL Slicer Devel <[hidden email]>
Subject: [slicer-devel] vtkImageThresholdConnectivity with Fiducial

Hi everyone,

I'm trying to use the vtkImageThresholdConnectivity filter in combination with the fiducials of Slicer. Every fiducial Markup should be a seed point.
Unfortunately the resulting outputVolume just contains the OutValue.

Maybe the problem is the conversion of the fiducials' coordinate System? I tried to convert the Points to RAS, XYZ and IJR, but nothing worked.
Please find the code of my def below.

Thank you very much,
Sebastian


def thresholdConnected(self ,inputVolume, outputVolume, clippingMarkup):

    image = inputVolume.GetImageData()
    print image.GetBounds()

    sliceNode = slicer.mrmlScene.GetNthNodeByClass(0, 'vtkMRMLSliceNode')
    appLogic = slicer.app.applicationLogic()
    sliceLogic = appLogic.GetSliceLogic(sliceNode)
    layerLogic = sliceLogic.GetLabelLayer()

    points = vtk.vtkPoints()
    numberOfPoints = clippingMarkup.GetNumberOfFiducials()

    points.SetNumberOfPoints(numberOfPoints)

    coordsRAS = [0,0,0]
    coordsXYZ = [0,0,0]

    for i in range(numberOfPoints):
      clippingMarkup.GetNthFiducialPosition(i, coordsRAS)
      slicer.vtkMRMLAbstractSliceViewDisplayableManager.ConvertRASToXYZ(sliceNode,coordsRAS,coordsXYZ)
      xyToIJK = layerLogic.GetXYToIJKTransform()
      coordsIJK = xyToIJK.TransformDoublePoint(coordsXYZ)
      points.SetPoint(i, coordsIJK)
      print coordsXYZ, coordsIJK, coordsRAS


    imageThreshold = vtk.vtkImageThresholdConnectivity()
    #imageThreshold = vtk.vtkImageThreshold()
    imageThreshold.SetInputData(image)
    lower = 200;
    upper = 3000;

    imageThreshold.ThresholdBetween(lower, upper)
    imageThreshold.SetSeedPoints(points)
    imageThreshold.ReplaceInOn()
    #imageThreshold.ReplaceOutOn()
    imageThreshold.SetInValue(2000)
    #imageThreshold.SetOutValue(-1000)
    #print imageThreshold.GetNeighborhoodRadius()
    imageThreshold.SetNeighborhoodRadius(100,100,100)
    imageThreshold.Update()

    outputVolume.SetImageDataConnection(imageThreshold.GetOutputPort())
_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ