How to use the pulse2percept.stimuli.images.ImageStimulus function in pulse2percept

To help you get started, we’ve selected a few pulse2percept 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 pulse2percept / pulse2percept / pulse2percept / stimuli / images.py View on Github external
elif thresh.lower() == 'minimum':
                img = img > threshold_minimum(img, **kwargs)
            elif thresh.lower() == 'local':
                img = img > threshold_local(img, **kwargs)
            elif thresh.lower() == 'otsu':
                img = img > threshold_otsu(img, **kwargs)
            elif thresh.lower() == 'isodata':
                img = img > threshold_isodata(img, **kwargs)
            else:
                raise ValueError("Unknown threshold method '%s'." % thresh)
        elif np.isscalar(thresh):
            img = self.data.reshape(self.img_shape) > thresh
        else:
            raise TypeError("Threshold type must be str or float, not "
                            "%s." % type(thresh))
        return ImageStimulus(img, electrodes=self.electrodes,
                             metadata=self.metadata)
github pulse2percept / pulse2percept / pulse2percept / stimuli / images.py View on Github external
Number of columns by which to shift the CoM.
            Positive: to the right, negative: to the left
        shift_rows : float
            Number of rows by which to shift the CoM.
            Positive: downward, negative: upward

        Returns
        -------
        stim : `ImageStimulus`
            A copy of the stimulus object containing the shifted image

        """
        img = self.data.reshape(self.img_shape)
        tf = SimilarityTransform(translation=[shift_cols, shift_rows])
        img = img_warp(img, tf.inverse)
        return ImageStimulus(img, electrodes=self.electrodes,
                             metadata=self.metadata)
github pulse2percept / pulse2percept / pulse2percept / stimuli / images.py View on Github external
Parameters
        ----------
        func : function
            The function to apply to the image. Must accept a 2D or 3D image
            and return an image with the same dimensions
        **kwargs :
            Additional parameters passed to the function

        Returns
        -------
        stim : `ImageStimulus`
            A copy of the stimulus object with the new image
        """
        img = func(self.data.reshape(self.img_shape), **kwargs)
        return ImageStimulus(img, electrodes=self.electrodes,
                             metadata=self.metadata)
github pulse2percept / pulse2percept / pulse2percept / stimuli / images.py View on Github external
"""
        # Calculate center of mass:
        img = self.data.reshape(self.img_shape)
        m = img_moments(img, order=1)
        # No area found:
        if np.isclose(m[0, 0], 0):
            return img
        # Center location:
        if loc is None:
            loc = np.array(self.img_shape[::-1]) / 2.0 - 0.5
        # Shift the image by -centroid, +image center:
        transl = (loc[0] - m[0, 1] / m[0, 0], loc[1] - m[1, 0] / m[0, 0])
        tf_shift = SimilarityTransform(translation=transl)
        img = img_warp(img, tf_shift.inverse)
        return ImageStimulus(img, electrodes=self.electrodes,
                             metadata=self.metadata)
github pulse2percept / pulse2percept / pulse2percept / stimuli / images.py View on Github external
def __init__(self, resize=None, electrodes=None, metadata=None,
                 as_gray=False):
        # Load logo from data dir:
        module_path = dirname(__file__)
        source = join(module_path, 'data', 'bionic-vision-lab.png')
        # Call ImageStimulus constructor:
        super(LogoBVL, self).__init__(source, format="PNG",
                                      resize=resize,
                                      as_gray=as_gray,
                                      electrodes=electrodes,
                                      metadata=metadata,
                                      compress=False)


class LogoUCSB(ImageStimulus):
    """UCSB logo

    Load a 324x727 white-on-black logo of the University of California, Santa
    Barbara.

    .. versionadded:: 0.7

    Parameters
    ----------
    resize : (height, width) or None
        A tuple specifying the desired height and the width of the image
        stimulus.

    electrodes : int, string or list thereof; optional, default: None
        Optionally, you can provide your own electrode names. If none are
        given, electrode names will be numbered 0..N.
github pulse2percept / pulse2percept / pulse2percept / stimuli / images.py View on Github external
A copy of the stimulus object with the filtered image
        """
        if not isinstance(filt, str):
            raise TypeError("'filt' must be a string, not %s." % type(filt))
        img = self.data.reshape(self.img_shape)
        if filt.lower() == 'sobel':
            img = sobel(img, **kwargs)
        elif filt.lower() == 'scharr':
            img = scharr(img, **kwargs)
        elif filt.lower() == 'canny':
            img = canny(img, **kwargs)
        elif filt.lower() == 'median':
            img = median(img, **kwargs)
        else:
            raise ValueError("Unknown filter '%s'." % filt)
        return ImageStimulus(img, electrodes=self.electrodes,
                             metadata=self.metadata)
github pulse2percept / pulse2percept / pulse2percept / stimuli / images.py View on Github external
-------
        stim : `ImageStimulus`
            A copy of the stimulus object with all grayscale values inverted
            in the range [0, 1].

        Notes
        -----
        *  A four-channel image is interpreted as RGBA (e.g., a PNG), and the
           alpha channel will be blended with the color black.

        """
        img = self.data.reshape(self.img_shape)
        if img.ndim == 3 and img.shape[2] == 4:
            # Blend the background with black:
            img = rgba2rgb(img, background=(0, 0, 0))
        return ImageStimulus(rgb2gray(img), electrodes=electrodes,
                             metadata=self.metadata)
github pulse2percept / pulse2percept / pulse2percept / stimuli / images.py View on Github external
Returns
        -------
        stim : `ImageStimulus`
            A copy of the stimulus object containing the resized image

        """
        height, width = shape
        if height < 0 and width < 0:
            raise ValueError('"height" and "width" cannot both be -1.')
        if height < 0:
            height = int(self.img_shape[0] * width / self.img_shape[1])
        if width < 0:
            width = int(self.img_shape[1] * height / self.img_shape[0])
        img = img_resize(self.data.reshape(self.img_shape), (height, width))

        return ImageStimulus(img, electrodes=electrodes,
                             metadata=self.metadata)