本文整理匯總了Python中pylinac.core.image.Image.median_filter方法的典型用法代碼示例。如果您正苦於以下問題:Python Image.median_filter方法的具體用法?Python Image.median_filter怎麽用?Python Image.median_filter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pylinac.core.image.Image
的用法示例。
在下文中一共展示了Image.median_filter方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: film
# 需要導入模塊: from pylinac.core.image import Image [as 別名]
# 或者: from pylinac.core.image.Image import median_filter [as 別名]
class Starshot:
"""Class that can determine the wobble in a "starshot" image, be it gantry, collimator,
couch or MLC. The image can be DICOM or a scanned film (TIF, JPG, etc).
Attributes
----------
image : :class:`~pylinac.core.image.Image`
circle_profile : :class:`~pylinac.starshot.StarProfile`
lines : list of :class:`~pylinac.core.geometry.Line` instances
wobble : :class:`~pylinac.starshot.Wobble`
Examples
--------
Run the demo:
>>> Starshot().run_demo()
Typical session:
>>> img_path = r"C:/QA/Starshots/Coll.jpeg"
>>> mystar = Starshot(img_path)
>>> mystar.analyze()
>>> print(mystar.return_results())
>>> mystar.plot_analyzed_image()
"""
def __init__(self, filepath=None):
# self.image = Image # The image array and image property structure
self.circle_profile = StarProfile() # a circular profile which will detect radiation line locations
self.lines = [] # a list which will hold Line instances representing radiation lines.
self.wobble = Wobble() # A Circle representing the radiation wobble
self.tolerance = Tolerance(1, 'pixels')
if filepath is not None:
self.load_image(filepath)
@classmethod
def from_demo_image(cls):
"""Construct a Starshot instance and load the demo image.
.. versionadded:: 0.6
"""
obj = cls()
obj.load_demo_image()
return obj
def load_demo_image(self):
"""Load the starshot demo image.
The Pylinac package comes with compressed demo images.
When called, the function unpacks the demo image and loads it.
Parameters
----------
cleanup : boolean
If True (default), the extracted demo file is deleted (but not the compressed version).
If False, leaves the extracted file alone after loading. Useful when using the demo image a lot,
or you don't mind using the extra space.
"""
demo_folder = osp.join(osp.dirname(__file__), 'demo_files', 'starshot')
demo_file = osp.join(demo_folder, '10X_collimator.tif')
# demo_file = osp.join(demo_folder, 'DHMC_starshot.dcm')
self.load_image(demo_file)
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)
@classmethod
def from_multiple_images(cls, filepath_list):
"""Construct a Starshot instance and load in and combine multiple images.
.. versionadded:: 0.6
"""
obj = cls()
obj.load_multiple_images(filepath_list)
return obj
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)
@classmethod
def from_multiple_images_UI(cls):
"""Construct a Starshot instance and load in and combine multiple images via a UI dialog box.
.. versionadded:: 0.6
#.........這裏部分代碼省略.........
示例2: PicketFence
# 需要導入模塊: from pylinac.core.image import Image [as 別名]
# 或者: from pylinac.core.image.Image import median_filter [as 別名]
#.........這裏部分代碼省略.........
@property
def num_pickets(self):
"""Return the number of pickets determined."""
return len(self.pickets)
@classmethod
def from_demo_image(cls, filter=None):
"""Construct a PicketFence instance using the demo image.
.. versionadded:: 0.6
"""
obj = cls()
obj.load_demo_image(filter=filter)
return obj
def load_demo_image(self, filter=None):
"""Load the demo image that is included with pylinac."""
im_open_path = osp.join(osp.dirname(__file__), 'demo_files', 'picket_fence', 'EPID-PF-LR.dcm')
self.load_image(im_open_path, filter=filter)
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._clear_attrs()
self._check_for_noise()
@classmethod
def from_image_UI(cls, filter=None):
"""Construct a PicketFence instance and load an image using a dialog box.
.. versionadded:: 0.6
"""
obj = cls()
obj.load_image_UI(filter=filter)
return obj
def load_image_UI(self, filter=None):
"""Load the image using a UI dialog box."""
path = get_filepath_UI()
self.load_image(path, filter=filter)
def _check_for_noise(self):
"""Check if the image has extreme noise (dead pixel, etc) by comparing
min/max to 1/99 percentiles and smoothing if need be."""
while self._has_noise():
self.image.median_filter()
def _has_noise(self):
"""Helper method to determine if there is spurious signal in the image."""
min = self.image.array.min()
max = self.image.array.max()
near_min, near_max = np.percentile(self.image.array, [0.5, 99.5])
max_is_extreme = max > near_max * 2
min_is_extreme = (min < near_min) and (abs(near_min - min) > 0.2 * near_max)
return max_is_extreme or min_is_extreme
示例3: PicketFence
# 需要導入模塊: from pylinac.core.image import Image [as 別名]
# 或者: from pylinac.core.image.Image import median_filter [as 別名]
#.........這裏部分代碼省略.........
@property
def num_pickets(self):
"""Return the number of pickets determined."""
return len(self.pickets)
@classmethod
def from_demo_image(cls, filter=None):
"""Construct a PicketFence instance using the demo image.
.. versionadded:: 0.6
"""
obj = cls()
obj.load_demo_image(filter=filter)
return obj
def load_demo_image(self, filter=None):
"""Load the demo image that is included with pylinac."""
im_open_path = osp.join(osp.dirname(__file__), 'demo_files', 'picket_fence', 'EPID-PF-LR.dcm')
self.load_image(im_open_path, filter=filter)
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()
@classmethod
def from_image_UI(cls, filter=None):
"""Construct a PicketFence instance and load an image using a dialog box.
.. versionadded:: 0.6
"""
obj = cls()
obj.load_image_UI(filter=filter)
return obj
def load_image_UI(self, filter=None):
"""Load the image using a UI dialog box."""
path = get_filepath_UI()
self.load_image(path, filter=filter)
def _check_for_noise(self):
"""Check if the image has extreme noise (dead pixel, etc) by comparing
min/max to 1/99 percentiles and smoothing if need be."""
while self._has_noise():
self.image.median_filter()
def _has_noise(self):
"""Helper method to determine if there is spurious signal in the image."""
min = self.image.array.min()
max = self.image.array.max()
near_min, near_max = np.percentile(self.image.array, [0.5, 99.5])
max_is_extreme = max > near_max * 2
min_is_extreme = (min < near_min) and (abs(near_min - min) > 0.2 * near_max)
return max_is_extreme or min_is_extreme
示例4: PicketFence
# 需要導入模塊: from pylinac.core.image import Image [as 別名]
# 或者: from pylinac.core.image.Image import median_filter [as 別名]
#.........這裏部分代碼省略.........
@property
def num_pickets(self):
"""Return the number of pickets determined."""
return len(self.pickets)
@classmethod
def from_demo_image(cls, filter=None):
"""Construct a PicketFence instance using the demo image.
.. versionadded:: 0.6
"""
obj = cls()
obj.load_demo_image(filter=filter)
return obj
def load_demo_image(self, filter=None):
"""Load the demo image that is included with pylinac."""
im_open_path = osp.join(osp.dirname(__file__), 'demo_files', 'picket_fence', 'EPID-PF-LR.dcm')
self.load_image(im_open_path, filter=filter)
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()
@classmethod
def from_image_UI(cls, filter=None):
"""Construct a PicketFence instance and load an image using a dialog box.
.. versionadded:: 0.6
"""
obj = cls()
obj.load_image_UI(filter=filter)
return obj
def load_image_UI(self, filter=None):
"""Load the image using a UI dialog box."""
path = get_filepath_UI()
self.load_image(path, filter=filter)
@classmethod
def from_multiple_images(cls, path_list):
"""Load and superimpose multiple images and instantiate a Starshot object.
.. versionadded:: 0.9
Parameters
----------
path_list : iterable
An iterable of path locations to the files to be loaded/combined.
"""
obj = cls()
obj.load_multiple_images(path_list)
return obj