Skip to content

Commit

Permalink
Add CatPhan604
Browse files Browse the repository at this point in the history
  • Loading branch information
alanphys authored and alanphys committed Feb 21, 2018
1 parent 8cdd9b8 commit 96f420d
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 9 deletions.
10 changes: 8 additions & 2 deletions .checkignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# Ignore test folder
tests/*
# Ignore folders
tests/*
env/*
demo_files/*
__pycache__/*

# Ignore files
*.old
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Folders to ignore
env/*
tests/*
**/pylinac.egg-info
**/demo_files
**/__pycache__

#Files to ignore
*.old
.directory
2 changes: 1 addition & 1 deletion pylinac/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
raise ValueError("Pylinac is only supported on Python 3.x. It seems you are using Python 2; please use a different interpreter.")

# import shortcuts
from pylinac.ct import CatPhan504, CatPhan600, CatPhan503
from pylinac.ct import CatPhan504, CatPhan600, CatPhan503, CatPhan604
from pylinac.core import decorators, geometry, image, io, mask, profile, roi, utilities
from pylinac.core.utilities import clear_data_files, assign2machine
from pylinac.flatsym import BeamImage
Expand Down
57 changes: 51 additions & 6 deletions pylinac/ct.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ def phan_center(self):
class CatPhanModule(Slice, ROIManagerMixin):
"""Base class for a CTP module.
"""
combine_method = 'mean'
num_slices = 0
combine_method = 'max'
num_slices = 1

def __init__(self, catphan, tolerance, offset=0):
"""
Expand Down Expand Up @@ -308,6 +308,23 @@ def __init__(self, catphan, offset, hu_tolerance, thickness_tolerance, scaling_t
},
'background ROI angles': [-30, -150, -210, 30]
}
elif isinstance(catphan, CatPhan604):
self.hu = {
'distance to ROIs': 58.7/self.mm_per_pixel,
'ROI radius': 5/self.mm_per_pixel,
'ROIs': {
'Air': {'value': -1000, 'angle': -90},
'PMP': {'value': -200, 'angle': -120},
'50Bone': {'value': 725, 'angle': -150},
'LDPE': {'value': -100, 'angle': 180},
'Poly': {'value': -35, 'angle': 120},
'Acrylic': {'value': 120, 'angle': 60},
'20Bone': {'value': 240, 'angle': 30},
'Delrin': {'value': 340, 'angle': 0},
'Teflon': {'value': 990, 'angle': -60},
},
'background ROI angles': [-30, -210]
}
self.bg_hu_rois = OrderedDict()
self.hu_rois = OrderedDict()

Expand Down Expand Up @@ -633,6 +650,9 @@ def preprocess(self, catphan):
elif isinstance(catphan, CatPhan600):
self.start_angle = np.pi - 0.1
self.ccw = False
elif isinstance(catphan, CatPhan604):
self.start_angle = np.pi
self.ccw = True

@property
@lru_cache(maxsize=1)
Expand Down Expand Up @@ -1065,9 +1085,9 @@ def find_origin_slice(self):
The middle slice of the HU linearity module.
"""
hu_slices = []
for image_number in range(0, self.num_images, 2):
for image_number in range(0, self.num_images):
slice = Slice(self, image_number, combine=False)
# print(image_number)
#print(image_number)
# slice.image.plot()
try:
center = slice.phan_center
Expand All @@ -1079,9 +1099,10 @@ def find_origin_slice(self):
# determine if the profile contains both low and high values and that most values are the same
low_end, high_end = np.percentile(prof, [2, 98])
median = np.median(prof)
if (low_end < median - 400) and (high_end > median + 400) and (
if (low_end < median - 800) and (high_end > median + 800) and (
np.percentile(prof, 80) - np.percentile(prof, 20) < 100):
hu_slices.append(image_number)
#print(image_number)

if not hu_slices:
raise ValueError("No slices were found that resembled the HU linearity module")
Expand All @@ -1092,6 +1113,7 @@ def find_origin_slice(self):
hu_slices = hu_slices[((c + ln/2) >= hu_slices) & (hu_slices >= (c - ln/2))]
center_hu_slice = int(round(np.median(hu_slices)))
if self._is_within_image_extent(center_hu_slice):
#print(center_hu_slice)
return center_hu_slice

@lru_cache(maxsize=1)
Expand Down Expand Up @@ -1325,7 +1347,7 @@ class CatPhan503(CatPhanBase):
def run_demo(cls, show=True):
"""Run the CBCT demo using high-quality head protocol images."""
obj = cls.from_demo_images()
obj.analyze()
obj.analyze()
print(obj.results())
obj.plot_analyzed_image(show)
# cbct = CatPhan503.from_demo_images()
Expand Down Expand Up @@ -1357,6 +1379,29 @@ def run_demo(show=True):
cbct.plot_analyzed_image(show)


class CatPhan604(CatPhanBase):
"""A class for loading and analyzing CT DICOM files of a CatPhan 604. Can be from a CBCT or CT scanner
Analyzes: Uniformity (CTP486), High-Contrast Spatial Resolution (CTP528),
Image Scaling & HU Linearity (CTP404), and Low contrast (CTP515).
"""
_demo_url = 'CatPhan604.zip'
_model = '604'
catphan_radius_mm = 101
modules = {
CTP486: {'offset': -80},
CTP528: {'offset': 40},
CTP515: {'offset': -40}
}

@staticmethod
def run_demo(show=True):
"""Run the CBCT demo using high-quality head protocol images."""
cbct = CatPhan604.from_demo_images()
cbct.analyze()
print(cbct.results())
cbct.plot_analyzed_image(show)


class CatPhan600(CatPhanBase):
"""A class for loading and analyzing CT DICOM files of a CatPhan 600.
Analyzes: Uniformity (CTP486), High-Contrast Spatial Resolution (CTP528),
Expand Down
9 changes: 9 additions & 0 deletions pylinac/py_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from tkinter import *
from tkinter.ttk import *
from tkinter import filedialog
from tkinter import messagebox
import os.path as osp
import webbrowser

Expand Down Expand Up @@ -403,7 +404,15 @@ def init_tg51(self):


def gui():

def on_exit():
if messagebox.askokcancel("Quit", "Do you want to quit?"):
root.quit()

root = Tk()
root.title('Pylinac GUI ' + __version__)
root.protocol("WM_DELETE_WINDOW", on_exit)
app = PylinacGUI(master=root)
app.mainloop()
root.destroy()
del root

0 comments on commit 96f420d

Please sign in to comment.