Code Monkey home page Code Monkey logo

Comments (2)

cutright avatar cutright commented on September 12, 2024 1

Please see my comment from the dicompyler-core issue you posted, the formats are different. overlap_volume needs a "sets of points" format

I might be easier to write a function to convert dicompyler-core structure coordinates into Shapely objects. Then use Shapely's geometric operations to get intersections. The DVHA code can provide some good inspiration for that.

That said, I haven't tried the following, but seems like it should work. You can use a couple functions already written to get what you need I think.

def dicompyler_roi_coord_to_db_string(coord):
"""
Parameters
----------
coord :
dicompyler structure coordinates from GetStructureCoordinates()
Returns
-------
str
roi string representation of an roi as formatted in the SQL database (roi_coord_string)
"""
contours = []
for z in coord:
for plane in coord[z]:
points = [z]
for point in plane["data"]:
points.append(str(round(point[0], 3)))
points.append(str(round(point[1], 3)))
contours.append(",".join(points))
return ":".join(contours)

def get_planes_from_string(roi_coord_string):
"""
Parameters
----------
roi_coord_string : string: str
roi string representation of an roi as formatted in the SQL database
Returns
-------
dict
a "sets of points" formatted dictionary
"""
planes = {}
contours = roi_coord_string.split(":")
for contour in contours:
contour = contour.split(",")
z = contour.pop(0)
z = round(float(z), 2)
z_str = str(z)
if z_str not in list(planes):
planes[z_str] = []
i, points = 0, []
while i < len(contour):
point = [float(contour[i]), float(contour[i + 1]), z]
points.append(point)
i += 2
planes[z_str].append(points)
return planes

from dvh-analytics.

sama2689 avatar sama2689 commented on September 12, 2024

That works! Leaving this working example below in case anyone else wants to try it.

from dicompylercore import dicomparser, dvh, dvhcalc
from dvha.tools.roi_geometry import overlap_volume
from dvha.tools.roi_formatter import dicompyler_roi_coord_to_db_string, get_planes_from_string

dp = dicomparser.DicomParser("RT-STRUCT.dcm") #parse RTStruct dicom

# i.e. Get a dict of structure information
structures = dp.GetStructures() #can use this structures dict to find structure indices

#extract gtv and format for dvha (with this specific rt-struct file 16 is the gtv index)
gtv_coords=dp.GetStructureCoordinates(16)
gtv_coords_str=dicompyler_roi_coord_to_db_string(gtv_coords)
gtv_planes=get_planes_from_string(gtv_coords_str)

#do the same for ptv (with this specific rt-struct file 18 is the ptv index)
ptv_coords=dp.GetStructureCoordinates(18)
ptv_coords_str=dicompyler_roi_coord_to_db_string(ptv_coords)
ptv_planes=get_planes_from_string(ptv_coords_str)



v=overlap_volume(ptv_planes, gtv_planes)

from dvh-analytics.

Related Issues (20)

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.