Giter VIP home page Giter VIP logo

Comments (9)

dave3d avatar dave3d commented on May 27, 2024

Let me check on it. It should be do-able. I think it's a matter of transforming the mesh points from volume space to world space using the volume's transform.

I'm glad to hear that you find the script useful.

from dicom2stl.

TviNet avatar TviNet commented on May 27, 2024

I tried to find a transform that I can apply to the mesh but I am unable to figure this out.

For two example meshes I printed the vtkImageData and vtkPolyData information. (vtkImageData is obtained after the sitk2vtk step and vtkPolyData after the extractSurface using vtkContourFilter)
Shown here are parts that I think are relevant.
The bounds don't make sense to me. The Y axis bound seem to neither be in the voxel (exceed 522) or world coordinates (exceed 147/254).

Mesh1:
    vtkImageData:
        Bounds:
                Xmin,Xmax: (-147.322, 146.758)
                Ymin,Ymax: (-214.399, 174.409)
                Zmin,Zmax: (-126.483, 181.907)
        Spacing: (0.564453, 0.564453, 5.17649)
        Origin: (-147.322, 115.459, -126.483)
        Direction: (1, 0, 0, 0, -0.965926, 0.258819, 0, 0.258819, 0.965926)
        Dimensions: (522, 606, 45)
    vtkPolyData:
        Bounds:
                Xmin,Xmax: (-74.9306, 99.202)
                Ymin,Ymax: (125.76, 382.868)
                Zmin,Zmax: (-99.3009, 74.1012)
        Number Of Points: 354850


Mesh2:
    vtkImageData:
         Bounds:
                  Xmin,Xmax: (-127.951, 127.461)
                  Ymin,Ymax: (-129.751, 125.661)
                  Zmin,Zmax: (-91.75, 133.25)
        Spacing: (0.490234, 0.490234, 5)
        Origin: (-127.951, 125.661, -91.75)
        Direction: (1, 0, 0, 0, -1, 0, 0, 0, 1)
        Dimensions: (522, 522, 46)
    vtkPolyData:
        Bounds:Number Of Points: 457570
                Xmin,Xmax: (-70.4708, 70.4706)
                Ymin,Ymax: (164.512, 357.909)
                Zmin,Zmax: (-70.4951, 101.995)
        Number Of Points: 457570

from dicom2stl.

dave3d avatar dave3d commented on May 27, 2024

Something wacky is going on there. The X and Z ranges of your meshes are contained within the volume ranges, as they should be. But the Y ranges are not.

But the mesh coordinates are certainly not in volume space, otherwise they would range within your voxel index ranges, i.e. not be negative numbers.

from dicom2stl.

dave3d avatar dave3d commented on May 27, 2024

Oh, the one thing I don't see is the Direction vector for the vtkImageData objects. the Origin, Spacing, and Direction define the geometry of the image in world space. The transform is defined be the Origin and the Direction.

from dicom2stl.

TviNet avatar TviNet commented on May 27, 2024

The Direction vector for both is
Direction: (1, 0, 0, 0, -1, 0, 0, 0, 1)

Would this mean that vtkPolyData is already in world coordinates and so the scaling is accurate?

from dicom2stl.

TviNet avatar TviNet commented on May 27, 2024

I have updated my earlier comment with the values for the following example meshes.
I have the output stl mesh on the top and the dicom visualized below. Mesh1 is on the left and Mesh2 is on the right.
If the values are not in volume space (due to negative numbers), then the world space still seems to be on a different scale.

from dicom2stl.

dave3d avatar dave3d commented on May 27, 2024

It clearly isn't properly handling the negative Y row in the direction vector. I'll see if I can make a similar example and figure out why. A possible work-around, for now, is to flip the sign of all the Y values in the vertices of the meshes.

from dicom2stl.

dave3d avatar dave3d commented on May 27, 2024

I've look into it a bit, and I think VTK is not properly using the image's direction information when doing iso-surface extraction. VTK only started even keeping a direction vector field for images with version 9, so it wouldn't surprise me if there are issues. I will investigate it further and see if I can fix it. Or I could write a script to work around the problem.

from dicom2stl.

dave3d avatar dave3d commented on May 27, 2024

I've added a new command line option to the script "--regularize". What that does is to resample the volume so that the orientation matrix is identity. Also the new volume will have cubic (uniformly spaced) voxels.

This option should allow us to work around the fact that VTK doesn't yet support the direction matrix when using the Marching Cubes filter.

Try it out and let me know if it works for you.

from dicom2stl.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.