本文整理匯總了Python中pylinac.core.image.Image類的典型用法代碼示例。如果您正苦於以下問題:Python Image類的具體用法?Python Image怎麽用?Python Image使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Image類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_multiples
def test_multiples(self):
paths = [dcm_path, dcm_path, dcm_path]
img = Image.load_multiples(paths)
self.assertIsInstance(img, DicomImage)
# test non-superimposable images
paths = [dcm_path, tif_path]
with self.assertRaises(ValueError):
Image.load_multiples(paths)
示例2: _find_HU_slice
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
示例3: test_combine_multiples
def test_combine_multiples(self):
bad_img_path = [dcm_path, img_path]
self.assertRaises(AttributeError, Image.from_multiples, bad_img_path)
good_img_path = [img_path, img_path]
combined_img = Image.from_multiples(good_img_path)
self.assertIsInstance(combined_img, Image)
示例4: test_all
def test_all(self):
futures = []
start = time.time()
with concurrent.futures.ProcessPoolExecutor() as exec:
for pdir, sdir, files in os.walk(self.image_bank_dir):
for file in files:
filepath = osp.join(pdir, file)
try:
Image.load(filepath)
except:
pass
else:
future = exec.submit(run_star, filepath)
futures.append(future)
for future in concurrent.futures.as_completed(futures):
print(future.result())
end = time.time() - start
print('Processing of {} files took {}s'.format(len(futures), end))
示例5: load_image
def load_image(self, filepath):
"""Load the image via the file path.
Parameters
----------
filepath : str
Path to the file to be loaded.
"""
self.image = Image(filepath)
示例6: _find_bb
def _find_bb(self):
"""Find the BB within the radiation field. Iteratively searches for a circle-like object
by lowering a low-pass threshold value until found.
Returns
-------
Point
The weighted-pixel value location of the BB.
"""
def is_boxlike(array):
"""Whether the binary object's dimensions are symmetric, i.e. box-like"""
ymin, ymax, xmin, xmax = get_bounding_box(array)
y = abs(ymax - ymin)
x = abs(xmax - xmin)
if x > max(y * 1.05, y+3) or x < min(y * 0.95, y-3):
return False
return True
# get initial starting conditions
hmin = np.percentile(self.array, 5)
hmax = self.array.max()
spread = hmax - hmin
max_thresh = hmax
# search for the BB by iteratively lowering the low-pass threshold value until the BB is found.
found = False
while not found:
try:
lower_thresh = hmax - spread / 2
t = np.where((max_thresh > self) & (self >= lower_thresh), 1, 0)
labeled_arr, num_roi = ndimage.measurements.label(t)
roi_sizes, bin_edges = np.histogram(labeled_arr, bins=num_roi + 1)
bw_node_cleaned = np.where(labeled_arr == np.argsort(roi_sizes)[-3], 1, 0)
expected_fill_ratio = np.pi / 4
actual_fill_ratio = get_filled_area_ratio(bw_node_cleaned)
if (expected_fill_ratio * 1.1 < actual_fill_ratio) or (actual_fill_ratio < expected_fill_ratio * 0.9):
raise ValueError
if not is_boxlike(bw_node_cleaned):
raise ValueError
except (IndexError, ValueError):
max_thresh -= 0.05 * spread
if max_thresh < hmin:
raise ValueError("Unable to locate the BB")
else:
found = True
# determine the center of mass of the BB
inv_img = Image.load(self.array)
inv_img.invert()
x_arr = np.abs(np.average(bw_node_cleaned, weights=inv_img, axis=0))
x_com = SingleProfile(x_arr).fwxm_center(interpolate=True)
y_arr = np.abs(np.average(bw_node_cleaned, weights=inv_img, axis=1))
y_com = SingleProfile(y_arr).fwxm_center(interpolate=True)
return Point(x_com, y_com)
示例7: load_multiple_images
def load_multiple_images(self, filepath_list):
"""Load multiple images via the file path.
.. versionadded:: 0.5.1
Parameters
----------
filepath_list : sequence
An iterable sequence of filepath locations.
"""
self.image = Image.from_multiples(filepath_list)
示例8: __init__
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()
示例9: load_image
def load_image(self, filepath):
"""Load the image via the file path.
Parameters
----------
filepath : str
Path to the file to be loaded.
"""
self.image = Image(filepath)
# apply filter if it's a large image to reduce noise
if self.image.shape[0] > 1100:
self.image.median_filter(0.002)
示例10: __init__
def __init__(self, filepath=None):
"""
Parameters
----------
filepath : None, str
If None, image must be loaded later.
If a str, path to the image file.
"""
if filepath is not None and is_valid_file(filepath):
self.image = Image.load(filepath)
else:
self.image = np.zeros((1,1))
示例11: load_multiple_images
def load_multiple_images(self, path_list):
"""Load and superimpose multiple images.
.. versionadded:: 0.9
Parameters
----------
path_list : iterable
An iterable of path locations to the files to be loaded/combined.
"""
self.image = Image.load_multiples(path_list, method='mean')
self._check_for_noise()
self.image.check_inversion()
示例12: load_image
def load_image(self, file_path, filter=None):
"""Load the image
Parameters
----------
file_path : str
Path to the image file.
filter : int, None
If None (default), no filtering will be done to the image.
If an int, will perform median filtering over image of size *filter*.
"""
self.image = Image(file_path)
if isinstance(filter, int):
self.image.array = spfilt.median_filter(self.image.array, size=filter)
self._clear_attrs()
示例13: load_image
def load_image(self, file_path, filter=None):
"""Load the image
Parameters
----------
file_path : str
Path to the image file.
filter : int, None
If None (default), no filtering will be done to the image.
If an int, will perform median filtering over image of size *filter*.
"""
self.image = Image(file_path)
if isinstance(filter, int):
self.image.median_filter(size=filter)
self._check_for_noise()
self.image.check_inversion()
示例14: test_open
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)
示例15: load_image
def load_image(self, file_path, im_type=None):
"""Load the image directly by the file path.
Parameters
----------
file_path : str, file-like object
The path to the DICOM image or I/O stream.
im_type : {'open', 'mlcs', None}
Specifies what image type is being loaded in. If None, will try to determine the type from the name.
The name must have 'open' or 'dmlc' in the name.
"""
img = Image.load(file_path)
if im_type is not None:
if _is_open_type(im_type):
self.image_open = img
elif _is_dmlc_type(im_type):
self.image_dmlc = img
else:
# try to guess type by the name
imtype = self._try_to_guess_image_type(osp.basename(file_path))
if imtype is not None:
self.load_image(file_path, imtype)
else:
raise ValueError("Image type was not given nor could it be determined from the path name. Please enter and image type.")