def _find_HU_slice(self): """Using a brute force search of the images, find the median HU linearity slice. This method walks through all the images and takes a collapsed circle profile where the HU linearity ROIs are. If the profile contains both low (<800) and high (>800) HU values and most values are the same (i.e. its not an artifact, then it can be assumed it is an HU linearity slice. The median of all applicable slices is the center of the HU slice. Returns ------- int The middle slice of the HU linearity module. """ hu_slices = [] for image_number in range(self.num_images): image = self.images[:, :, image_number] slice = Slice(self, Image.from_array(image)) try: slice.find_phan_center() except ValueError: # a slice without the phantom in view continue else: circle_prof = CollapsedCircleProfile(slice.phan_center, radius=120/self.fov_ratio) circle_prof.get_profile(image, width_ratio=0.05, num_profiles=5) prof = circle_prof.y_values # determine if the profile contains both low and high values and that most values are the same if (np.percentile(prof, 2) < 800) and (np.percentile(prof, 98) > 800) and (np.percentile(prof, 80) - np.percentile(prof, 30) < 40): hu_slices.append(image_number) center_hu_slice = int(np.median(hu_slices)) return center_hu_slice
def __init__(self, settings): super().__init__(settings) self.scale_by_FOV() self.image = Image.from_array(combine_surrounding_slices(self.settings.images, self.settings.SR_slice_num, mode='max')) self.LP_MTF = OrderedDict() # holds lp:mtf data for idx, radius in enumerate(self.radius2profs): c = SR_Circle_ROI(idx, self.image.array, radius=radius) self.add_ROI(c) super().find_phan_center()
def __init__(self, settings): super().__init__(settings) self.scale_by_FOV() self.image = Image.from_array(combine_surrounding_slices(self.settings.images, self.settings.UN_slice_num)) HU_ROIp = partial(HU_ROI, slice_array=self.image.array, tolerance=settings.hu_tolerance, radius=self.obj_radius, dist_from_center=self.dist2objs) # center has distance of 0, thus doesn't use partial center = HU_ROI('Center', 0, 0, self.image.array, self.obj_radius, dist_from_center=0, tolerance=settings.hu_tolerance) right = HU_ROIp('Right', 0, 0) top = HU_ROIp('Top', -90, 0) left = HU_ROIp('Left', 180, 0) bottom = HU_ROIp('Bottom', 90, 0) self.add_ROI(center, right, top, left, bottom) super().find_phan_center()
def __init__(self, settings): super().__init__(settings) self.scale_by_FOV() self.image = Image.from_array(combine_surrounding_slices(self.settings.images, self.settings.HU_slice_num)) HU_ROIp = partial(HU_ROI, slice_array=self.image.array, radius=self.object_radius, dist_from_center=self.dist2objs, tolerance=settings.hu_tolerance) air = HU_ROIp('Air', 90, -1000) pmp = HU_ROIp('PMP', 120, -200) ldpe = HU_ROIp('LDPE', 180, -100) poly = HU_ROIp('Poly', -120, -35) acrylic = HU_ROIp('Acrylic', -60, 120) delrin = HU_ROIp('Delrin', 0, 340) teflon = HU_ROIp('Teflon', 60, 990) self.add_ROI(air, pmp, ldpe, poly, acrylic, delrin, teflon) super().find_phan_center()
def test_open(self): """Test the open class method.""" # load a tif file img = Image(img_path) self.assertEqual(img.im_type, IMAGE) # load a dicom file img2 = Image(dcm_path) self.assertEqual(img2.im_type, DICOM) # try loading a bad file bad_file = osp.abspath(__file__) self.assertRaises(TypeError, Image, bad_file) # not a valid parameter bad_input = 3.5 self.assertRaises(TypeError, Image, bad_input) # load an array dcm = dicom.read_file(dcm_path) img = Image.from_array(dcm.pixel_array) self.assertEqual(img.im_type, ARRAY)
def __init__(self, settings): super().__init__(settings) self.tolerance = settings.scaling_tolerance self.scale_by_FOV() self.image = Image.from_array(combine_surrounding_slices(self.settings.images, self.settings.HU_slice_num, mode='median')) GEO_ROIp = partial(GEO_ROI, slice_array=self.image.array, radius=self.obj_radius, dist_from_center=self.dist2objs) tl = GEO_ROIp(name='Top-Left', angle=-135) tr = GEO_ROIp(name='Top-Right', angle=-45) br = GEO_ROIp(name='Bottom-Right', angle=45) bl = GEO_ROIp(name='Bottom-Left', angle=135) self.add_ROI(tl, tr, br, bl) # Construct the Lines, mapping to the nodes they connect to lv = GEO_Line('Left-Vert', tl, bl) bh = GEO_Line('Bottom-Horiz', bl, br) rv = GEO_Line('Right-Vert', tr, br) th = GEO_Line('Top-Horiz', tl, tr) self.add_line(lv, bh, rv, th) super().find_phan_center()
def __init__(self, settings): super().__init__(settings) self.image = Image.from_array(combine_surrounding_slices(self.settings.images, self.settings.LC_slice_num))
def setUp(self): self.img = Image(img_path) self.dcm = Image(dcm_path) small_array = np.arange(42).reshape(6,7) self.sm_arr = Image.from_array(small_array)