How to use the pylinac.core.image.DicomImage function in pylinac

To help you get started, we’ve selected a few pylinac examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jrkerns / pylinac / tests_basic / core / test_image.py View on Github external
def test_load_url(self):
        img = image.load_url(dcm_url)
        self.assertIsInstance(img, DicomImage)
github jrkerns / pylinac / pylinac / vmat.py View on Github external
from .core.pdf import PylinacCanvas
from .core.profile import SingleProfile
from .core.utilities import open_path
from .settings import get_dicom_cmap

DMLC = 'dmlc'
OPEN = 'open'
PROFILE = 'profile'


class VMATBase:
    _url_suffix: str
    _result_header: str
    _result_short_header: str
    SEGMENT_X_POSITIONS_MM: Tuple
    dmlc_image: image.DicomImage
    open_image: image.DicomImage
    segments: List
    _tolerance: float

    def __init__(self, image_paths: Sequence[str]):
        """
        Parameters
        ----------
        image_paths : iterable (list, tuple, etc)
            A sequence of paths to the image files.
        """
        if len(image_paths) != 2:
            raise ValueError("Exactly 2 images (open, DMLC) must be passed")
        image1, image2 = self._load_images(image_paths)
        image1, image2 = self._check_img_inversion(image1, image2)
        self._identify_images(image1, image2)
github jrkerns / pylinac / pylinac / vmat.py View on Github external
from .core.profile import SingleProfile
from .core.utilities import open_path
from .settings import get_dicom_cmap

DMLC = 'dmlc'
OPEN = 'open'
PROFILE = 'profile'


class VMATBase:
    _url_suffix: str
    _result_header: str
    _result_short_header: str
    SEGMENT_X_POSITIONS_MM: Tuple
    dmlc_image: image.DicomImage
    open_image: image.DicomImage
    segments: List
    _tolerance: float

    def __init__(self, image_paths: Sequence[str]):
        """
        Parameters
        ----------
        image_paths : iterable (list, tuple, etc)
            A sequence of paths to the image files.
        """
        if len(image_paths) != 2:
            raise ValueError("Exactly 2 images (open, DMLC) must be passed")
        image1, image2 = self._load_images(image_paths)
        image1, image2 = self._check_img_inversion(image1, image2)
        self._identify_images(image1, image2)
        self.segments = []
github jrkerns / pylinac / pylinac / core / image.py View on Github external
>>> my_image = "C:\QA\image.tif"
        >>> img = load(my_image)  # returns a FileImage
        >>> img.filter(5)

    Loading from an array is just like loading from a file::

        >>> arr = np.arange(36).reshape(6, 6)
        >>> img = load(arr)  # returns an ArrayImage
    """
    if isinstance(path, BaseImage):
        return path

    if _is_array(path):
        return ArrayImage(path, **kwargs)
    elif _is_dicom(path):
        return DicomImage(path, **kwargs)
    elif _is_image_file(path):
        return FileImage(path, **kwargs)
    else:
        raise TypeError(f"The argument `{path}` was not found to be a valid DICOM file, Image file, or array")
github jrkerns / pylinac / pylinac / watcher.py View on Github external
def pdf_filename(self):
        """The name of the file for the PDF results."""
        if self.zip_format:
            return self.base_name + '.pdf'
        else:
            dirname = osp.dirname(self.path[0])
            dcm = DicomImage(self.path[0])
            name = 'VMAT {} - {}.pdf'.format(self.test_type.upper(), dcm.date_created())
            return osp.join(dirname, name)
github jrkerns / pylinac / pylinac / watcher.py View on Github external
def run(cls, files, config, skip_list):
        files = drop_skips(files, skip_list)
        # analyze ZIP archives
        for file in files:
            cond1 = contains_keywords(file, config, cls.config_name)
            cond2 = file.endswith('.zip')
            if cond1 and cond2:
                obj = cls(file, config)
                obj.process()
                skip_list.append(osp.basename(file))
        # analyze directory groups
        if config[cls.config_name]['use-classifier']:
            imgs = [DicomImage(f) for f in files if is_dicom_image(f)]
            uids = [i.metadata.SeriesInstanceUID for i in imgs]
            c = collections.Counter(uids)
            for uid, num in c.items():
                if num == 2:
                    img_uids = [i.path for i in imgs if i.metadata.SeriesInstanceUID == uid]
                    obj = cls(img_uids, config, zip_format=False)
                    obj.process()
                    for img in img_uids:
                        skip_list.append(osp.basename(img))
github jrkerns / pylinac / pylinac / core / image.py View on Github external
dpmm = self._dpi / MM_PER_INCH
        return dpmm

    @property
    def cax(self) -> Point:
        """The position of the beam central axis. If no DICOM translation tags are found then the center is returned."""
        try:
            x = self.center.x - self.metadata.XRayImageReceptorTranslation[0]
            y = self.center.y - self.metadata.XRayImageReceptorTranslation[1]
        except AttributeError:
            return self.center
        else:
            return Point(x, y)


class LinacDicomImage(DicomImage):
    """DICOM image taken on a linac. Also allows passing of gantry/coll/couch values via the filename."""
    gantry_keyword = 'Gantry'
    collimator_keyword = 'Coll'
    couch_keyword = 'Couch'

    _use_filenames: bool

    def __init__(self, path: str, use_filenames: bool=False):
        super().__init__(path)
        self._use_filenames = use_filenames

    @property
    def gantry_angle(self) -> NumberLike:
        """Gantry angle of the irradiation."""
        return self._get_axis(self.gantry_keyword.lower(), 'GantryAngle')