STL conversion to OBJ

Hello! I used the following code snippet to import a STL as a segmentation and export that segmentation into a OBJ.

Issue: Right now the exported OBJ seems to be lower quality than if I did this manually. I feel as though there many be a flaw in my approach. I would love some insight on the code snippet below. Thank you <3

        # Load STL, import as segmentation, and export as OBJ
        stlSegmentationNode = slicer.util.loadSegmentation(inputFolder)
        segmentIDs = vtk.vtkStringArray()
        slicer.vtkSlicerSegmentationsModuleLogic.ExportSegmentsClosedSurfaceRepresentationToFiles(outputFolder, stlSegmentationNode, segmentIDs, "OBJ", True, 1.0, False)

There should be no difference at all. Could you post a screenshot that shows what difference you see between results of different methods?

The original STL is: 347 MB
In essence I would like to replicate this manual process in a module:

  1. Import STL as segmentation
  2. Export the segmentation as a OBJ
    Output OBJ’s look like this
    Manual STL->Segmentation->OBJ: 316 MB
    Script STL->Segmentation->OBJ: 288 MB

I am wondering why the sizes may be different between the manual process and the script.

Probably the difference is that you set size scale of 0.005 on the GUI. Since OBJ is a text-based format, if you change the scale then coordinate values may be longer/shorter (“5” is shorter than “0.005”).

Why did you set scale to 0.005 on the GUI? Normally you should set it to 1.0 (to export in mm), but you can change it if you want to export in meters or inches - but 0.005 does not seem to correspond to any commonly used distance unit.

1 Like

Ohh! My apologies, I completely overlooked how that may be effecting it. I set it to 0.005 thinking it would scale it down (it is arbitrary, since I was just testing it out earlier - didn’t think it would effect the file size). Based on what you are saying it makes most sense to just keep it at 1mm, so I will do so.

Always appreciated! Hope you and your family/friends have been safe <3