當前位置: 首頁>>代碼示例>>Python>>正文


Python Image.load方法代碼示例

本文整理匯總了Python中pylinac.core.image.Image.load方法的典型用法代碼示例。如果您正苦於以下問題:Python Image.load方法的具體用法?Python Image.load怎麽用?Python Image.load使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pylinac.core.image.Image的用法示例。


在下文中一共展示了Image.load方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_all

# 需要導入模塊: from pylinac.core.image import Image [as 別名]
# 或者: from pylinac.core.image.Image import load [as 別名]
 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))
開發者ID:darcymason,項目名稱:pylinac,代碼行數:20,代碼來源:_test_all_starshots.py

示例2: load_image

# 需要導入模塊: from pylinac.core.image import Image [as 別名]
# 或者: from pylinac.core.image.Image import load [as 別名]
    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.load(filepath)
開發者ID:darcymason,項目名稱:pylinac,代碼行數:11,代碼來源:starshot.py

示例3: _find_bb

# 需要導入模塊: from pylinac.core.image import Image [as 別名]
# 或者: from pylinac.core.image.Image import load [as 別名]
    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)
開發者ID:darcymason,項目名稱:pylinac,代碼行數:57,代碼來源:winston_lutz.py

示例4: __init__

# 需要導入模塊: from pylinac.core.image import Image [as 別名]
# 或者: from pylinac.core.image.Image import load [as 別名]
 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))
開發者ID:darcymason,項目名稱:pylinac,代碼行數:14,代碼來源:flatsym.py

示例5: load_image

# 需要導入模塊: from pylinac.core.image import Image [as 別名]
# 或者: from pylinac.core.image.Image import load [as 別名]
    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.load(file_path)
        if isinstance(filter, int):
            self.image.median_filter(size=filter)
        self._check_for_noise()
        self.image.check_inversion()
開發者ID:darcymason,項目名稱:pylinac,代碼行數:18,代碼來源:picketfence.py

示例6: load_image

# 需要導入模塊: from pylinac.core.image import Image [as 別名]
# 或者: from pylinac.core.image.Image import load [as 別名]
    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.")
開發者ID:darcymason,項目名稱:pylinac,代碼行數:26,代碼來源:vmat.py

示例7: load_demo_image

# 需要導入模塊: from pylinac.core.image import Image [as 別名]
# 或者: from pylinac.core.image.Image import load [as 別名]
 def load_demo_image(self):
     """Load the demo image."""
     demo_file = osp.join(osp.dirname(__file__), 'demo_files', 'flatsym', 'flatsym_demo.dcm')
     self.image = Image.load(demo_file)
開發者ID:darcymason,項目名稱:pylinac,代碼行數:6,代碼來源:flatsym.py

示例8: setUpClass

# 需要導入模塊: from pylinac.core.image import Image [as 別名]
# 或者: from pylinac.core.image.Image import load [as 別名]
 def setUpClass(cls):
     image = Image.load(cls.image_file_location)
     cls.profile = cls.klass(cls.center_point, cls.radius, image.array)
開發者ID:vandonova,項目名稱:amazon_art,代碼行數:5,代碼來源:test_profile.py

示例9: setUp

# 需要導入模塊: from pylinac.core.image import Image [as 別名]
# 或者: from pylinac.core.image.Image import load [as 別名]
 def setUp(self):
     self.img = Image.load(tif_path)
     self.dcm = Image.load(dcm_path)
     array = np.arange(42).reshape(6, 7)
     self.arr = Image.load(array)
開發者ID:darcymason,項目名稱:pylinac,代碼行數:7,代碼來源:test_image.py

示例10: test_nonsense

# 需要導入模塊: from pylinac.core.image import Image [as 別名]
# 或者: from pylinac.core.image.Image import load [as 別名]
 def test_nonsense(self):
     with self.assertRaises(TypeError):
         Image.load('blahblah')
開發者ID:darcymason,項目名稱:pylinac,代碼行數:5,代碼來源:test_image.py

示例11: test_array

# 需要導入模塊: from pylinac.core.image import Image [as 別名]
# 或者: from pylinac.core.image.Image import load [as 別名]
 def test_array(self):
     arr = np.arange(36).reshape(6, 6)
     img = Image.load(arr)
     self.assertIsInstance(img, ArrayImage)
開發者ID:darcymason,項目名稱:pylinac,代碼行數:6,代碼來源:test_image.py

示例12: test_file

# 需要導入模塊: from pylinac.core.image import Image [as 別名]
# 或者: from pylinac.core.image.Image import load [as 別名]
 def test_file(self):
     img = Image.load(tif_path)
     self.assertIsInstance(img, FileImage)
開發者ID:darcymason,項目名稱:pylinac,代碼行數:5,代碼來源:test_image.py

示例13: test_dicom

# 需要導入模塊: from pylinac.core.image import Image [as 別名]
# 或者: from pylinac.core.image.Image import load [as 別名]
 def test_dicom(self):
     img = Image.load(dcm_path)
     self.assertIsInstance(img, DicomImage)
開發者ID:darcymason,項目名稱:pylinac,代碼行數:5,代碼來源:test_image.py

示例14: setUpClass

# 需要導入模塊: from pylinac.core.image import Image [as 別名]
# 或者: from pylinac.core.image.Image import load [as 別名]
 def setUpClass(cls):
     cls.dcm = Image.load(dcm_path)
開發者ID:darcymason,項目名稱:pylinac,代碼行數:4,代碼來源:test_image.py


注:本文中的pylinac.core.image.Image.load方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。