当前位置: 首页>>代码示例>>Python>>正文


Python image.Image类代码示例

本文整理汇总了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)
开发者ID:darcymason,项目名称:pylinac,代码行数:9,代码来源:test_image.py

示例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
开发者ID:oblasi,项目名称:pylinac,代码行数:32,代码来源:cbct.py

示例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)
开发者ID:spidersaint,项目名称:pylinac,代码行数:7,代码来源:test_image.py

示例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))
开发者ID:darcymason,项目名称:pylinac,代码行数:18,代码来源:_test_all_starshots.py

示例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)
开发者ID:oblasi,项目名称:pylinac,代码行数:9,代码来源:starshot.py

示例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)
开发者ID:darcymason,项目名称:pylinac,代码行数:55,代码来源:winston_lutz.py

示例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)
开发者ID:gitter-badger,项目名称:pylinac,代码行数:11,代码来源:starshot.py

示例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()
开发者ID:victorgabr,项目名称:pylinac,代码行数:11,代码来源:cbct.py

示例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)
开发者ID:gitter-badger,项目名称:pylinac,代码行数:12,代码来源:starshot.py

示例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))
开发者ID:darcymason,项目名称:pylinac,代码行数:12,代码来源:flatsym.py

示例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()
开发者ID:darcymason,项目名称:pylinac,代码行数:13,代码来源:picketfence.py

示例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()
开发者ID:gitter-badger,项目名称:pylinac,代码行数:15,代码来源:picketfence.py

示例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()
开发者ID:Jothy,项目名称:RTQA,代码行数:16,代码来源:PicketFenceSumImg.py

示例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)
开发者ID:spidersaint,项目名称:pylinac,代码行数:22,代码来源:test_image.py

示例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.")
开发者ID:darcymason,项目名称:pylinac,代码行数:24,代码来源:vmat.py


注:本文中的pylinac.core.image.Image类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。