Example #1
0
    def build(self):
        import imageio

        pixels = imageio.imread(self.filepath)
        pixels = channels_to_front(pixels)

        transparent_types = {'.png'}
        filepath = Path(self.filepath)
        if pixels.shape[0] == 4 and filepath.suffix in transparent_types:
            # If normalise is False, then we return the alpha as an extra
            # channel, which can be useful if the alpha channel has semantic
            # meanings!
            if self.normalise:
                p = normalize_pixels_range(pixels[:3])
                return MaskedImage(p,
                                   mask=pixels[-1].astype(np.bool),
                                   copy=False)
            else:
                return Image(pixels, copy=False)

        # Assumed not to have an Alpha channel
        if self.normalise:
            return Image(normalize_pixels_range(pixels), copy=False)
        else:
            return Image(pixels, copy=False)
def _pil_to_numpy(pil_image, normalize, convert=None):
    p = pil_image.convert(convert) if convert else pil_image
    p = channels_to_front(p)
    if normalize:
        return normalize_pixels_range(p)
    else:
        return p
Example #3
0
def _pil_to_numpy(pil_image, normalise, convert=None):
    p = pil_image.convert(convert) if convert else pil_image
    p = channels_to_front(p)
    if normalise:
        return normalize_pixels_range(p)
    else:
        return p
Example #4
0
 def _pil_to_numpy(self, normalise, convert=None):
     p = self._pil_image.convert(convert) if convert else self._pil_image
     p = channels_to_front(p)
     if normalise:
         return normalise_pixels_range(p)
     else:
         return p
Example #5
0
        def imageio_to_menpo(imio_reader, index):
            pixels = imio_reader.get_data(index)
            pixels = channels_to_front(pixels)

            if self.normalise:
                return Image(normalise_pixels_range(pixels), copy=False)
            else:
                return Image(pixels, copy=False)
Example #6
0
        def imageio_to_menpo(imio_reader, index):
            pixels = imio_reader.get_data(index)
            pixels = channels_to_front(pixels)

            if self.normalise:
                return Image(normalise_pixels_range(pixels), copy=False)
            else:
                return Image(pixels, copy=False)
def imageio_importer(filepath, asset=None, normalize=True, **kwargs):
    r"""
    Imports images using the imageio library - which is actually fairly similar
    to our importing logic - but contains the necessary plugins to import lots
    of interesting image types like RAW images.

    Parameters
    ----------
    filepath : `Path`
        Absolute filepath of the image.
    asset : `object`, optional
        An optional asset that may help with loading. This is unused for this
        implementation.
    normalize : `bool`, optional
        If ``True``, normalize between 0.0 and 1.0 and convert to float. If
        ``False`` just return whatever imageio imports.
    \**kwargs : `dict`, optional
        Any other keyword arguments.

    Returns
    -------
    image : :map:`Image` or subclass
        The imported image.
    """
    import imageio

    pixels = imageio.imread(str(filepath))
    pixels = channels_to_front(pixels)

    transparent_types = {'.png'}
    if pixels.shape[0] == 4 and filepath.suffix in transparent_types:
        # If normalize is False, then we return the alpha as an extra
        # channel, which can be useful if the alpha channel has semantic
        # meanings!
        if normalize:
            p = normalize_pixels_range(pixels[:3])
            return MaskedImage(p, mask=pixels[-1].astype(np.bool),
                               copy=False)
        else:
            return Image(pixels, copy=False)

    # Assumed not to have an Alpha channel
    if normalize:
        return Image(normalize_pixels_range(pixels), copy=False)
    else:
        return Image(pixels, copy=False)
Example #8
0
def imageio_importer(filepath, asset=None, normalise=True, **kwargs):
    r"""
    Imports images using the imageio library - which is actually fairly similar
    to our importing logic - but contains the necessary plugins to import lots
    of interesting image types like RAW images.

    Parameters
    ----------
    filepath : `Path`
        Absolute filepath of the image.
    asset : `object`, optional
        An optional asset that may help with loading. This is unused for this
        implementation.
    normalise : `bool`, optional
        If ``True``, normalise between 0.0 and 1.0 and convert to float. If
        ``False`` just return whatever imageio imports.
    \**kwargs : `dict`, optional
        Any other keyword arguments.

    Returns
    -------
    image : :map:`Image` or subclass
        The imported image.
    """
    import imageio

    pixels = imageio.imread(str(filepath))
    pixels = channels_to_front(pixels)

    transparent_types = {'.png'}
    if pixels.shape[0] == 4 and filepath.suffix in transparent_types:
        # If normalise is False, then we return the alpha as an extra
        # channel, which can be useful if the alpha channel has semantic
        # meanings!
        if normalise:
            p = normalize_pixels_range(pixels[:3])
            return MaskedImage(p, mask=pixels[-1].astype(np.bool),
                               copy=False)
        else:
            return Image(pixels, copy=False)

    # Assumed not to have an Alpha channel
    if normalise:
        return Image(normalize_pixels_range(pixels), copy=False)
    else:
        return Image(pixels, copy=False)
Example #9
0
    def imageio_to_menpo(imio_reader, index):
        pixels = imio_reader.get_data(index)
        pixels = channels_to_front(pixels)

        if pixels.shape[0] == 4:
            # If normalize is False, then we return the alpha as an extra
            # channel, which can be useful if the alpha channel has semantic
            # meanings!
            if normalize:
                p = normalize_pixels_range(pixels[:3])
                return MaskedImage(p, mask=pixels[-1].astype(bool), copy=False)
            else:
                return Image(pixels, copy=False)

        # Assumed not to have an Alpha channel
        if normalize:
            return Image(normalize_pixels_range(pixels), copy=False)
        else:
            return Image(pixels, copy=False)
Example #10
0
    def imageio_to_menpo(imio_reader, index):
        pixels = imio_reader.get_data(index)
        pixels = channels_to_front(pixels)

        if pixels.shape[0] == 4:
            # If normalise is False, then we return the alpha as an extra
            # channel, which can be useful if the alpha channel has semantic
            # meanings!
            if normalise:
                p = normalize_pixels_range(pixels[:3])
                return MaskedImage(p, mask=pixels[-1].astype(np.bool),
                                   copy=False)
            else:
                return Image(pixels, copy=False)

        # Assumed not to have an Alpha channel
        if normalise:
            return Image(normalize_pixels_range(pixels), copy=False)
        else:
            return Image(pixels, copy=False)