Skip to content

Commit

Permalink
fixed CT to structure registration
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Douglass authored and Michael Douglass committed Apr 27, 2024
1 parent 8da53a4 commit 5e821ec
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ __pycache__/proton.cpython-310.pyc
__pycache__/constants.cpython-310.pyc
__pycache__/__init__.cpython-310.pyc
__pycache__/node_groups.cpython-310.pyc
test.py
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Michael Douglass
Copyright (c) 2024 Michael Douglass

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 6 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def execute(self, context):

# Sort those filtered DICOM CT slices by their instance number using sort_by_instance_number function
sorted_images = sort_by_instance_number(filtered_images)
CT_volume, spacing, slice_position, slice_spacing, image_origin = extract_dicom_data(sorted_images)
CT_volume, spacing, slice_position, slice_spacing, image_origin, image_orientation, image_columns = extract_dicom_data(sorted_images)

#If spacing is invalid, set to slice spacing of 1 mm
if slice_spacing == 0:
Expand All @@ -164,6 +164,10 @@ def execute(self, context):
origin = np.asarray(origin)
volume_dim = np.shape(CT_volume)

print('Origin:', origin)
print('Volume Dimensions:', volume_dim)
print('Spacing:', spacing)

# Print out some information about your sorted slices
#print(f"Number of slices: {len(sorted_images)}")
#print(f"First slice instance number: {sorted_images[0].InstanceNumber}")
Expand Down Expand Up @@ -191,7 +195,7 @@ def execute(self, context):

# Add the volume to the scene
bpy.ops.object.volume_import(filepath=str(dir_path.joinpath("CT.vdb")), files=[])
bpy.context.active_object.location = origin/1000
#bpy.context.active_object.location = origin/1000


#DICOM_object = easybpy.get_selected_object()
Expand Down
16 changes: 14 additions & 2 deletions dicom_util.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
# dicom_utilities.py

import os
import pydicom

import numpy as np

try:

import pydicom

except ImportError:

print("pydicom is not installed. Please install it using the command 'pip install pydicom'")

pydicom = None


#Checks if the DICOM file is a RTDose file.
def is_dose_file(ds):
Expand Down Expand Up @@ -122,10 +132,12 @@ def extract_dicom_data(images):
slice_position.append(images[i].ImagePositionPatient)
slice_spacing = images[i].SliceThickness
image_origin = images[i].ImagePositionPatient
image_orientation = images[i].ImageOrientationPatient
image_columns = images[i].Columns
print(slice_spacing)
dicom_3d_array = np.asarray(dicom_3d_array)
dicom_3d_array = np.flipud(dicom_3d_array)
return dicom_3d_array, spacing, slice_position, slice_spacing, image_origin
return dicom_3d_array, images[0].PixelSpacing, slice_position, images[0].SliceThickness, images[0].ImagePositionPatient, images[0].ImageOrientationPatient, images[0].Columns


def filter_by_series_uid(images, series_uid):
Expand Down

0 comments on commit 5e821ec

Please sign in to comment.