Overlay model with original image in slicer

Hi, I have the following MWE code in slicer. I want to show the 3D grid of the image along with the image. I use the vtkExtractEdges and pass that to a vtkTubeFilter.
When I visualize the result, the extracted grid is much smaller than the original image? What gives ? Please see image below.

Thanks

import os

nodeName = "MyNewVolume"
imageSize = [4, 6, 4]
voxelType=vtk.VTK_UNSIGNED_CHAR
imageOrigin = [0.0, 0.0, 0.0]
imageSpacing = [13.0, 13.0, 13.0]
imageDirections = [[1,0,0], [0,1,0], [0,0,1]]
fillVoxelValue = 500

# Create an empty image volume, filled with fillVoxelValue
imageData = vtk.vtkImageData()
imageData.SetDimensions(imageSize)
imageData.AllocateScalars(voxelType, 1)
imageData.GetPointData().GetScalars().Fill(fillVoxelValue)

extractEdges = vtk.vtkExtractEdges()
extractEdges.SetInputData(imageData) 

# Tube the edges
tubes = vtk.vtkTubeFilter()
tubes.SetInputConnection(extractEdges.GetOutputPort())
tubes.SetRadius(0.008)
tubes.SetNumberOfSides(32)

model = slicer.modules.models.logic().AddModel(tubes.GetOutputPort())

# Create volume node
volumeNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLScalarVolumeNode", nodeName)
volumeNode.SetOrigin(imageOrigin)
volumeNode.SetSpacing(imageSpacing)
volumeNode.SetIJKToRASDirections(imageDirections)
volumeNode.SetAndObserveImageData(imageData)
volumeNode.CreateDefaultDisplayNodes()
volumeNode.CreateDefaultStorageNode()

Looks like you need to apply the spacing to expand the result of the tube filter. For example, you could get the IJKToRAS matrix from the volumeNode and use it for a linear transform you could apply to the model node.

HI Pieper,
thanks for your answer. I just wondered why the scaling is not applied automatically. Is my VTK code having an issue ?

Thanks

GT

Yes, you need to take the image spacing into account when to map your tube from local space to world (patient) space. The edges are being extracted from the image data which doesn’t include the ijkToRAS information which is only added at the MRML level.