Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)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)
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)
"""
# 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)
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.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)
-------
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)
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)