本文整理匯總了Python中pylinac.core.image.Image.invert方法的典型用法代碼示例。如果您正苦於以下問題:Python Image.invert方法的具體用法?Python Image.invert怎麽用?Python Image.invert使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pylinac.core.image.Image
的用法示例。
在下文中一共展示了Image.invert方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: film
# 需要導入模塊: from pylinac.core.image import Image [as 別名]
# 或者: from pylinac.core.image.Image import invert [as 別名]
#.........這裏部分代碼省略.........
@classmethod
def from_image_UI(cls):
"""Construct a Starshot instance and get the image via a UI dialog box.
.. versionadded:: 0.6
"""
obj = cls()
obj.load_image_UI()
return obj
def load_image_UI(self):
"""Load the image by using a UI dialog box."""
path = get_filepath_UI()
if path:
self.load_image(path)
@property
def start_point(self):
"""The start point of the wobble search algorithm.
After analysis this point is the wobble center.
"""
return self.circle_profile.center
def _check_image_inversion(self):
"""Check the image for proper inversion, i.e. that pixel value increases with dose.
Notes
-----
Inversion is checked by the following:
- Summing the image along both horizontal and vertical directions.
- If the maximum point of both horizontal and vertical is in the middle 1/3, the image is assumed to be correct.
- Otherwise, invert the image.
"""
# sum the image along each axis
x_sum = np.sum(self.image.array, 0)
y_sum = np.sum(self.image.array, 1)
# determine the point of max value for each sum profile
xmaxind = np.argmax(x_sum)
ymaxind = np.argmax(y_sum)
# If that maximum point isn't near the center (central 1/3), invert image.
center_in_central_third = ((xmaxind > len(x_sum) / 3 and xmaxind < len(x_sum) * 2 / 3) and
(ymaxind > len(y_sum) / 3 and ymaxind < len(y_sum) * 2 / 3))
if not center_in_central_third:
self.image.invert()
def _auto_set_start_point(self):
"""Set the algorithm starting point automatically.
Notes
-----
The determination of an automatic start point is accomplished by finding the Full-Width-80%-Max.
Finding the maximum pixel does not consistently work, esp. in the presence of a pin prick. The
FW80M is a more consistent metric for finding a good start point.
"""
# sum the image along each axis within the central 1/3 (avoids outlier influence from say, gantry shots)
top_third = int(self.image.array.shape[0]/3)
bottom_third = int(top_third * 2)
left_third = int(self.image.array.shape[1]/3)
right_third = int(left_third * 2)
central_array = self.image.array[top_third:bottom_third, left_third:right_third]
示例2: Test_Image_Methods
# 需要導入模塊: from pylinac.core.image import Image [as 別名]
# 或者: from pylinac.core.image.Image import invert [as 別名]
class Test_Image_Methods(unittest.TestCase):
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)
def test_remove_edges(self):
"""Remove the edges from a pixel array."""
crop = 15
orig_shape = self.img.shape
orig_dpi = self.img.dpi
self.img.remove_edges(crop)
new_shape = self.img.shape
new_dpi = self.img.dpi
self.assertEqual(new_shape[0]+crop*2, orig_shape[0])
# ensure original metadata is still the same
self.assertEqual(new_dpi, orig_dpi)
def test_median_filter(self):
filter_size = 3
self.sm_arr.median_filter(filter_size)
self.assertEqual(self.sm_arr.array[0, 0], 1)
filter_size = 0.03
self.sm_arr.median_filter(filter_size)
self.assertRaises(ValueError, self.img.median_filter, 1.1)
def test_ground(self):
old_min_val = copy.copy(self.dcm.array.min())
ground_val = self.dcm.ground()
self.assertEqual(old_min_val, ground_val)
# test that array was also changed
self.assertAlmostEqual(self.dcm.array.min(), 0)
def test_resize(self):
new_size = (200, 300)
self.img.resize(new_size)
self.assertEqual(self.img.shape, new_size)
def test_invert(self):
self.img.invert()
def test_dist2edge_min(self):
dist = self.sm_arr.dist2edge_min(Point(1,3))
self.assertEqual(dist, 1)
dist = self.sm_arr.dist2edge_min((1,3))
self.assertEqual(dist, 1)
def test_center(self):
self.assertIsInstance(self.img.center, Point)
img_known_center = Point(512, 1702)
dcm_known_center = Point(512, 384)
self.assertEqual(self.img.center.x, img_known_center.x)
self.assertEqual(self.dcm.center.y, dcm_known_center.y)
def test_SID(self):
self.assertEqual(self.dcm.SID, 1050)
self.assertRaises(TypeError, setattr, self.dcm, 'SID', '105')
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)
def test_plot(self):
self.img.plot() # shouldn't raise
示例3: film
# 需要導入模塊: from pylinac.core.image import Image [as 別名]
# 或者: from pylinac.core.image.Image import invert [as 別名]
#.........這裏部分代碼省略.........
if path_list:
self.load_multiple_images(path_list)
@classmethod
def from_image_UI(cls):
"""Construct a Starshot instance and get the image via a UI dialog box.
.. versionadded:: 0.6
"""
obj = cls()
obj.load_image_UI()
return obj
def load_image_UI(self):
"""Load the image by using a UI dialog box."""
path = get_filepath_UI()
if path:
self.load_image(path)
def _check_image_inversion(self):
"""Check the image for proper inversion, i.e. that pixel value increases with dose."""
# sum the image along each axis
x_sum = np.sum(self.image.array, 0)
y_sum = np.sum(self.image.array, 1)
# determine the point of max value for each sum profile
xmaxind = np.argmax(x_sum)
ymaxind = np.argmax(y_sum)
# If that maximum point isn't near the center (central 1/3), invert image.
center_in_central_third = ((xmaxind > len(x_sum) / 3 and xmaxind < len(x_sum) * 2 / 3) and
(ymaxind > len(y_sum) / 3 and ymaxind < len(y_sum) * 2 / 3))
if not center_in_central_third:
self.image.invert()
def _get_reasonable_start_point(self):
"""Set the algorithm starting point automatically.
Notes
-----
The determination of an automatic start point is accomplished by finding the Full-Width-80%-Max.
Finding the maximum pixel does not consistently work, esp. in the presence of a pin prick. The
FW80M is a more consistent metric for finding a good start point.
"""
# sum the image along each axis within the central 1/3 (avoids outlier influence from say, gantry shots)
top_third = int(self.image.array.shape[0]/3)
bottom_third = int(top_third * 2)
left_third = int(self.image.array.shape[1]/3)
right_third = int(left_third * 2)
central_array = self.image.array[top_third:bottom_third, left_third:right_third]
x_sum = np.sum(central_array, 0)
y_sum = np.sum(central_array, 1)
# Calculate Full-Width, 80% Maximum
fwxm_x_point = SingleProfile(x_sum).get_FWXM_center(80) + left_third
fwxm_y_point = SingleProfile(y_sum).get_FWXM_center(80) + top_third
# find maximum points
x_max = np.unravel_index(np.argmax(central_array), central_array.shape)[1] + left_third
y_max = np.unravel_index(np.argmax(central_array), central_array.shape)[0] + top_third
# which one is closer to the center
fwxm_dist = Point(fwxm_x_point, fwxm_y_point).dist_to(self.image.center)
max_dist = Point(x_max, y_max).dist_to(self.image.center)
示例4: PicketFence
# 需要導入模塊: from pylinac.core.image import Image [as 別名]
# 或者: from pylinac.core.image.Image import invert [as 別名]
#.........這裏部分代碼省略.........
for mlc_num, mlc in enumerate(self.pickets[0].mlc_meas):
below_tol = True
if self._action_lvl_set:
below_action = True
for picket in self.pickets:
if not picket.mlc_passed(mlc_num):
below_tol = False
if self._action_lvl_set and not picket.mlc_passed_action(mlc_num):
below_action = False
if below_tol:
if self._action_lvl_set and not below_action:
color = 'm'
else:
color = 'g'
else:
color = 'r'
if self.orientation == orientations['UD']:
r = Rectangle(max(self.image.shape)*2, self._sm_lf_meas_wdth, (mlc.center.x, mlc.center.y))
else:
r = Rectangle(self._sm_lf_meas_wdth, max(self.image.shape) * 2, (mlc.center.x, mlc.center.y))
r.add_to_axes(ax.axes, edgecolor='none', fill=True, alpha=0.1, facecolor=color)
plt.xlim([0, self.image.shape[1]])
plt.ylim([0, self.image.shape[0]])
plt.axis('off')
if show:
plt.show()
def save_analyzed_image(self, filename, guard_rails=True, mlc_peaks=True, overlay=True, **kwargs):
"""Save the analyzed figure to a file."""
self.plot_analyzed_image(guard_rails, mlc_peaks, overlay, show=False)
plt.savefig(filename, **kwargs)
def return_results(self):
"""Return results of analysis. Use with print()."""
pass_pct = self.percent_passing
string = "Picket Fence Results: \n{:2.1f}% " \
"Passed\nMedian Error: {:2.3f}mm \n" \
"Max Error: {:2.3f}mm on Picket: {}, Leaf: {}".format(pass_pct, self.abs_median_error, self.max_error,
self.max_error_picket,
self.max_error_leaf)
return string
def _check_inversion(self):
"""Check the image for inversion (pickets are valleys, not peaks) by sampling the 4 image corners.
If the average value of the four corners is above the average pixel value, then it is very likely inverted.
"""
outer_edge = 10
inner_edge = 30
TL_corner = self.image.array[outer_edge:inner_edge, outer_edge:inner_edge]
BL_corner = self.image.array[-inner_edge:-outer_edge, -inner_edge:-outer_edge]
TR_corner = self.image.array[outer_edge:inner_edge, outer_edge:inner_edge]
BR_corner = self.image.array[-inner_edge:-outer_edge, -inner_edge:-outer_edge]
corner_avg = np.mean((TL_corner, BL_corner, TR_corner, BR_corner))
if corner_avg > np.mean(self.image.array.flatten()):
self.image.invert()
def _threshold(self):
"""Threshold the image by subtracting the minimum value. Allows for more accurate image orientation determination.
"""
col_prof = np.median(self.image.array, 0)
col_prof = Profile(col_prof)
row_prof = np.median(self.image.array, 1)
row_prof = Profile(row_prof)
_, r_peak_idx = row_prof.find_peaks(min_peak_distance=0.01, exclude_lt_edge=0.05, exclude_rt_edge=0.05)
_, c_peak_idx = col_prof.find_peaks(min_peak_distance=0.01, exclude_lt_edge=0.05, exclude_rt_edge=0.05)
min_val = self.image.array[r_peak_idx[0]:r_peak_idx[-1], c_peak_idx[0]:c_peak_idx[-1]].min()
self._analysis_array = self.image.array.copy()
self._analysis_array[self._analysis_array < min_val] = min_val
self._analysis_array -= min_val
# @property
# def _analysis_array(self):
# return getattr(self, '_aa', self.image.array.copy())
#
# @_analysis_array.setter
# def _analysis_array(self, array):
# if array.shape != self.image.shape:
# raise ValueError("Array size is not the same as the original image")
# self._aa = array
def _find_orientation(self):
"""Determine the orientation of the radiation strips by examining percentiles of the sum of each axes of the image.
A high standard deviation is a surrogate for the axis the pickets are along.
"""
row_sum = np.sum(self._analysis_array, 0)
col_sum = np.sum(self._analysis_array, 1)
row80, row90 = np.percentile(row_sum, [80, 90])
col80, col90 = np.percentile(col_sum, [80, 90])
row_range = row90 - row80
col_range = col90 - col80
# The true picket side will have a greater difference in
# percentiles than will the non-picket size.
if row_range < col_range:
self.orientation = orientations['LR']
else:
self.orientation = orientations['UD']