コード例 #1
0
ファイル: vmat.py プロジェクト: carlosqueiroz/pylinac
    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."
                )
コード例 #2
0
 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))
コード例 #3
0
 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))
コード例 #4
0
ファイル: starshot.py プロジェクト: darcymason/pylinac
    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)
コード例 #5
0
    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)
コード例 #6
0
    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
0
 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))
コード例 #8
0
ファイル: picketfence.py プロジェクト: carlosqueiroz/pylinac
    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()
コード例 #9
0
ファイル: picketfence.py プロジェクト: darcymason/pylinac
    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()
コード例 #10
0
ファイル: vmat.py プロジェクト: darcymason/pylinac
    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.")
コード例 #11
0
ファイル: test_image.py プロジェクト: darcymason/pylinac
 def test_array(self):
     arr = np.arange(36).reshape(6, 6)
     img = Image.load(arr)
     self.assertIsInstance(img, ArrayImage)
コード例 #12
0
ファイル: test_profile.py プロジェクト: vandonova/amazon_art
 def setUpClass(cls):
     image = Image.load(cls.image_file_location)
     cls.profile = cls.klass(cls.center_point, cls.radius, image.array)
コード例 #13
0
ファイル: test_image.py プロジェクト: carlosqueiroz/pylinac
 def test_file(self):
     img = Image.load(tif_path)
     self.assertIsInstance(img, FileImage)
コード例 #14
0
ファイル: test_image.py プロジェクト: carlosqueiroz/pylinac
 def test_array(self):
     arr = np.arange(36).reshape(6, 6)
     img = Image.load(arr)
     self.assertIsInstance(img, ArrayImage)
コード例 #15
0
ファイル: test_image.py プロジェクト: carlosqueiroz/pylinac
 def test_nonsense(self):
     with self.assertRaises(TypeError):
         Image.load('blahblah')
コード例 #16
0
ファイル: test_image.py プロジェクト: carlosqueiroz/pylinac
 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)
コード例 #17
0
ファイル: test_image.py プロジェクト: carlosqueiroz/pylinac
 def test_dicom(self):
     img = Image.load(dcm_path)
     self.assertIsInstance(img, DicomImage)
コード例 #18
0
 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)
コード例 #19
0
ファイル: test_image.py プロジェクト: darcymason/pylinac
 def test_file(self):
     img = Image.load(tif_path)
     self.assertIsInstance(img, FileImage)
コード例 #20
0
ファイル: test_image.py プロジェクト: darcymason/pylinac
 def test_dicom(self):
     img = Image.load(dcm_path)
     self.assertIsInstance(img, DicomImage)
コード例 #21
0
ファイル: test_image.py プロジェクト: darcymason/pylinac
 def setUpClass(cls):
     cls.dcm = Image.load(dcm_path)
コード例 #22
0
ファイル: test_image.py プロジェクト: darcymason/pylinac
 def test_nonsense(self):
     with self.assertRaises(TypeError):
         Image.load('blahblah')
コード例 #23
0
ファイル: test_image.py プロジェクト: darcymason/pylinac
 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)
コード例 #24
0
ファイル: test_profile.py プロジェクト: jdschmitt11/pylinac
 def setUpClass(cls):
     image = Image.load(cls.image_file_location)
     cls.profile = cls.klass(cls.center_point, cls.radius, image.array)
コード例 #25
0
ファイル: test_image.py プロジェクト: carlosqueiroz/pylinac
 def setUpClass(cls):
     cls.dcm = Image.load(dcm_path)