Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUpClass(cls):
cls.dcm = image.load(dcm_path)
def test_nonsense(self):
with self.assertRaises(FileNotFoundError):
image.load('blahblah')
def _load_images(image_paths):
image1 = image.load(image_paths[0])
image2 = image.load(image_paths[1])
return image1, image2
calc_individual_maps : bool
Not yet implemented.
If True, separate pixel maps for the distance-to-agreement and dose-to-agreement are created.
Returns
-------
numpy.ndarray
A num_mlc_leaves-x-400/resolution numpy array.
"""
# calc fluences if need be
if not self._actual_fluence.is_map_calced() or resolution != self._actual_fluence.resolution:
self._actual_fluence.calc_map(resolution)
if not self._expected_fluence.is_map_calced() or resolution != self._expected_fluence.resolution:
self._expected_fluence.calc_map(resolution)
actual_img = image.load(self._actual_fluence.array, dpi=25.4 / resolution)
expected_img = image.load(self._expected_fluence.array, dpi=25.4 / resolution)
gamma_map = actual_img.gamma(expected_img, doseTA=doseTA, distTA=distTA, threshold=threshold)
# calculate standard metrics
self.avg_gamma = np.nanmean(gamma_map)
if np.isnan(self.avg_gamma):
self.avg_gamma = 0
pixels_passing = np.sum(gamma_map[~np.isnan(gamma_map)] < 1)
all_calcd_pixels = np.sum(gamma_map[~np.isnan(gamma_map)] >= 0)
self.pass_prcnt = pixels_passing / all_calcd_pixels * 100
gamma_map = np.nan_to_num(gamma_map)
self.passfail_array = gamma_map >= 1
self.distTA = distTA
self.doseTA = doseTA
self.threshold = threshold
directory : str
The path to the images.
use_filenames: bool
Whether to try to use the file name to determine axis values.
Useful for Elekta machines that do not include that info in the DICOM data.
"""
super().__init__()
if isinstance(directory, list):
for file in directory:
if is_dicom_image(file):
img = WLImage(file, use_filenames)
self.append(img)
elif not osp.isdir(directory):
raise ValueError("Invalid directory passed. Check the correct method and file was used.")
else:
image_files = image.retrieve_image_files(directory)
for file in image_files:
img = WLImage(file, use_filenames)
self.append(img)
if len(self) < 2:
raise ValueError("<2 valid WL images were found in the folder/file. Ensure you chose the correct folder/file for analysis")
# reorder list based on increasing gantry angle, collimator angle, then couch angle
self.sort(key=lambda i: (i.gantry_angle, i.collimator_angle, i.couch_angle))
def __init__(self, filepath: str, **kwargs):
"""
Parameters
----------
filepath : str
The path to the image file.
kwargs
Passed to :func:`~pylinac.core.image.load`.
"""
self.image = image.load(filepath, **kwargs)
self.wobble = Wobble()
self.tolerance = 1
if self.image.dpmm is None:
raise ValueError("DPI was not a tag in the image nor was it passed in. Please pass a DPI value")
if self.image.sid is None:
raise ValueError("Source-to-Image distance was not an image tag and was not passed in. Please pass an SID value.")
----------
folderpath : str
String that points to the CBCT image folder location.
check_uid : bool
Whether to enforce raising an error if more than one UID is found in the dataset.
Raises
------
NotADirectoryError : If folder str passed is not a valid directory.
FileNotFoundError : If no CT images are found in the folder
"""
self.origin_slice = 0
self.catphan_roll = 0
if not osp.isdir(folderpath):
raise NotADirectoryError("Path given was not a Directory/Folder")
self.dicom_stack = image.DicomImageStack(folderpath, check_uid=check_uid)
self.localize()
def _check_inversion(self):
"""Check the inversion by using the histogram of the phantom region"""
roi = self._phantom_ski_region_calc()
phantom_array = self.image.array[roi.bbox[0]:roi.bbox[2], roi.bbox[1]:roi.bbox[3]]
phantom_sub_image = image.load(phantom_array)
phantom_sub_image.crop(int(phantom_sub_image.shape[0]*0.1))
p5 = np.percentile(phantom_sub_image, 0.5)
p50 = np.percentile(phantom_sub_image, 50)
p95 = np.percentile(phantom_sub_image, 99.5)
dist_to_5 = abs(p50 - p5)
dist_to_95 = abs(p50 - p95)
if dist_to_5 > dist_to_95:
self.image.invert()
if not is_round(bb_regionprops):
raise ValueError
if not is_modest_size(bw_bb_img, self.rad_field_bounding_box):
raise ValueError
if not is_symmetric(bw_bb_img):
raise ValueError
except (IndexError, ValueError):
max_thresh -= 0.05 * spread
if max_thresh < hmin:
raise ValueError("Unable to locate the BB. Make sure the field edges do not obscure the BB and that there is no artifacts in the images.")
else:
found = True
# determine the center of mass of the BB
inv_img = image.load(self.array)
# we invert so BB intensity increases w/ attenuation
inv_img.check_inversion_by_histogram(percentiles=(99.99, 50, 0.01))
bb_rprops = measure.regionprops(bw_bb_img, intensity_image=inv_img)[0]
return Point(bb_rprops.weighted_centroid[1], bb_rprops.weighted_centroid[0])