Hello,
I am new at 3D slicer but I am trying to improve the resolution of the line drawn with the Draw effect in the SegmentEditor module by interpolating between two consecutive points so that the line or the shape drawn can appear to have a higher resolution and less pixelated. However, when I do that, I don’t get any errors relating to the code but I don’t notice any difference in the line drawn and the pixelation appears to be the same. Is there a better way to improve pixelation that I am perhaps unaware of? Should I be accessing the cells from the polyData attribute and changing its size ?
Here is my interpolation method:
def interpolatePoints(self, point1, point2, numPoints=10):
"""
Interpolate numPoints equally spaced points between point1 and point2
"""
pts = []
for i in range(numPoints):
t = i / (numPoints - 1) # t va de 0 à 1
point = np.array(point1)*(1-t) + np.array(point2)*t # interpolation linéaire
pts.append(point.tolist())
return pts
I call it in the apply method like so:
def apply(self):
lines = self.polyData.GetLines()
lineExists = lines.GetNumberOfCells() > 0
if lineExists:
# Close the polyline back to the first point
idList = vtk.vtkIdList()
idList.InsertNextId(self.polyData.GetNumberOfPoints() - 1)
idList.InsertNextId(0)
self.polyData.InsertNextCell(vtk.VTK_LINE, idList)
# Get modifier labelmap qui représente la segmentation actuelle
modifierLabelmap = self.scriptedEffect.defaultModifierLabelmap()
# Apply poly data on modifier labelmap
segmentationNode = self.scriptedEffect.parameterSetNode().GetSegmentationNode()
# Interpolation before applying mask
for i in range(1, self.rasPoints.GetNumberOfPoints()):
lastPoint = self.rasPoints.GetPoint(i)
firstPoint = self.rasPoints.GetPoint(i - 1)
interpolatedPoints = self.interpolatePoints(firstPoint, lastPoint)
for point in interpolatedPoints:
self.rasPoints.InsertNextPoint(point)
# Appliquer le polydata sur le modifierLabelmap en utilisant la méthode appendPolyMask qui permet d'ajouter le tracé à la segmentation
num_cells = self.polyData.GetNumberOfCells()
print(f"Number of cells in polyData: {num_cells}")
# Access the cells in the polydata
cellArray = self.polyData.GetLines()
# Iterate through cells and get their size
for cellId in range(cellArray.GetNumberOfCells()):
cellSize = cellArray.GetCellSize(cellId)
print(f"Size of cell {cellId}: {cellSize}")
self.scriptedEffect.appendPolyMask(modifierLabelmap, self.polyData, self.sliceWidget, segmentationNode)
self.resetPolyData()
if lineExists:
self.scriptedEffect.saveStateForUndo()
self.scriptedEffect.modifySelectedSegmentByLabelmap(modifierLabelmap, slicer.qSlicerSegmentEditorAbstractEffect.ModificationModeAdd)
Thanks in advance.