How to use the pylinac.core.image.ArrayImage 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_array(self):
        arr = np.arange(36).reshape(6, 6)
        img = image.load(arr)
        self.assertIsInstance(img, ArrayImage)
github jrkerns / pylinac / tests_basic / core / test_image.py View on Github external
def test_dpmm(self):
        arr = np.arange(42).reshape(6, 7)
        ai = ArrayImage(arr)

        self.assertIsNone(ai.dpi)

        ai2 = ArrayImage(arr, dpi=20)
        self.assertEqual(ai2.dpi, 20)
        self.assertEqual(ai2.dpmm, 20/25.4)
github jrkerns / pylinac / tests_basic / core / test_image.py View on Github external
def test_dpmm(self):
        arr = np.arange(42).reshape(6, 7)
        ai = ArrayImage(arr)

        self.assertIsNone(ai.dpi)

        ai2 = ArrayImage(arr, dpi=20)
        self.assertEqual(ai2.dpi, 20)
        self.assertEqual(ai2.dpmm, 20/25.4)
github jrkerns / pylinac / pylinac / core / image.py View on Github external
>>> from pylinac.core.image import load
        >>> 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 / core / image.py View on Github external
The calculated gamma map.

        See Also
        --------
        :func:`~pylinac.core.image.equate_images`
        """
        # error checking
        if not is_close(self.dpi, comparison_image.dpi, delta=0.1):
            raise AttributeError(f"The image DPIs to not match: {self.dpi:.2f} vs. {comparison_image.dpi:.2f}")
        same_x = is_close(self.shape[1], comparison_image.shape[1], delta=1.1)
        same_y = is_close(self.shape[0], comparison_image.shape[0], delta=1.1)
        if not (same_x and same_y):
            raise AttributeError(f"The images are not the same size: {self.shape} vs. {comparison_image.shape}")

        # set up reference and comparison images
        ref_img = ArrayImage(copy.copy(self.array))
        ref_img.check_inversion_by_histogram()
        if ground:
            ref_img.ground()
        if normalize:
            ref_img.normalize()
        comp_img = ArrayImage(copy.copy(comparison_image.array))
        comp_img.check_inversion_by_histogram()
        if ground:
            comp_img.ground()
        if normalize:
            comp_img.normalize()

        # invalidate dose values below threshold so gamma doesn't calculate over it
        ref_img.array[ref_img < threshold * np.max(ref_img)] = np.NaN

        # convert distance value from mm to pixels
github jrkerns / pylinac / pylinac / core / image.py View on Github external
# error checking
        if not is_close(self.dpi, comparison_image.dpi, delta=0.1):
            raise AttributeError(f"The image DPIs to not match: {self.dpi:.2f} vs. {comparison_image.dpi:.2f}")
        same_x = is_close(self.shape[1], comparison_image.shape[1], delta=1.1)
        same_y = is_close(self.shape[0], comparison_image.shape[0], delta=1.1)
        if not (same_x and same_y):
            raise AttributeError(f"The images are not the same size: {self.shape} vs. {comparison_image.shape}")

        # set up reference and comparison images
        ref_img = ArrayImage(copy.copy(self.array))
        ref_img.check_inversion_by_histogram()
        if ground:
            ref_img.ground()
        if normalize:
            ref_img.normalize()
        comp_img = ArrayImage(copy.copy(comparison_image.array))
        comp_img.check_inversion_by_histogram()
        if ground:
            comp_img.ground()
        if normalize:
            comp_img.normalize()

        # invalidate dose values below threshold so gamma doesn't calculate over it
        ref_img.array[ref_img < threshold * np.max(ref_img)] = np.NaN

        # convert distance value from mm to pixels
        distTA_pixels = self.dpmm * distTA

        # construct image gradient using sobel filter
        img_x = spf.sobel(ref_img.as_type(np.float32), 1)
        img_y = spf.sobel(ref_img.as_type(np.float32), 0)
        grad_img = np.hypot(img_x, img_y)
github jrkerns / pylinac / pylinac / core / image.py View on Github external
def __sub__(self, other):
        return ArrayImage(self.array - other.array)