menpo/image/masked.py
def from_vector(self, vector, n_channels=None):
        r"""
        Takes a flattened vector and returns a new image formed by reshaping
        the vector to the correct pixels and channels. Note that the only
        region of the image that will be filled is the masked region.

        On masked images, the vector is always copied.

        The ``n_channels`` argument is useful for when we want to add an extra
        channel to an image but maintain the shape. For example, when
        calculating the gradient.

        Note that landmarks are transferred in the process.

        Parameters
        ----------
        vector : ``(n_pixels,)``
            A flattened vector of all pixels and channels of an image.
        n_channels : `int`, optional
            If given, will assume that vector is the same shape as this image,
            but with a possibly different number of channels.

        Returns
        -------
        image : :class:`MaskedImage`
            New image of same shape as this image and the number of
            specified channels.
        """
        # This is useful for when we want to add an extra channel to an image
        # but maintain the shape. For example, when calculating the gradient
        n_channels = self.n_channels if n_channels is None else n_channels
        # Creates zeros of size (M x N x ... x n_channels)
        if self.mask.all_true():
            # we can just reshape the array!
            image_data = vector.reshape((self.shape + (n_channels,)))
        else:
            image_data = np.zeros(self.shape + (n_channels,))
            pixels_per_channel = vector.reshape((-1, n_channels))
            image_data[self.mask.mask] = pixels_per_channel
        new_image = MaskedImage(image_data, mask=self.mask)
        new_image.landmarks = self.landmarks
        return new_image
r"""
        Takes a flattened vector and returns a new image formed by reshaping
        the vector to the correct pixels and channels. Note that the only
        region of the image that will be filled is the masked region.

        On masked images, the vector is always copied.

        The ``n_channels`` argument is useful for when we want to add an extra
        channel to an image but maintain the shape. For example, when
        calculating the gradient.

        Note that landmarks are transferred in the process.

        Parameters
        ----------
        vector : ``(n_pixels,)``
            A flattened vector of all pixels and channels of an image.
        n_channels : `int`, optional
            If given, will assume that vector is the same shape as this image,
            but with a possibly different number of channels.

        Returns
        -------
        image : :class:`MaskedImage`
            New image of same shape as this image and the number of
            specified channels.
        
r"""
Takes a flattened vector and returns a new image formed by reshaping
the vector to the correct pixels and channels. Note that the only
region of the image that will be filled is the masked region.

On masked images, the vector is always copied.

The ``n_channels`` argument is useful for when we want to add an extra
channel to an image but maintain the shape. For example, when
calculating the gradient.

Note that landmarks are transferred in the process.

Parameters

vector : ``(n_pixels,)``
A flattened vector of all pixels and channels of an image.
n_channels : `int`, optional
If given, will assume that vector is the same shape as this image,
but with a possibly different number of channels.

Returns

image : :class:`MaskedImage`
New image of same shape as this image and the number of
specified channels.
r " " " Takes a flattened vector and returns a new image formed by reshaping the vector to the correct pixels and channels . Note that the only region of the image that will be filled is the masked region . On masked images the vector is always copied . The ` ` n_channels ` ` argument is useful for when we want to add an extra channel to an image but maintain the shape . For example when calculating the gradient . Note that landmarks are transferred in the process . Parameters vector : ` ` ( n_pixels ) ` ` A flattened vector of all pixels and channels of an image . n_channels : ` int ` optional If given will assume that vector is the same shape as this image but with a possibly different number of channels . Returns image : : class : ` MaskedImage ` New image of same shape as this image and the number of specified channels .
def from_vector(self, vector, n_channels=None):
        n_channels = self.n_channels if n_channels is None else n_channels
        if self.mask.all_true():
            image_data = vector.reshape((self.shape + (n_channels,)))
        else:
            image_data = np.zeros(self.shape + (n_channels,))
            pixels_per_channel = vector.reshape((-1, n_channels))
            image_data[self.mask.mask] = pixels_per_channel
        new_image = MaskedImage(image_data, mask=self.mask)
        new_image.landmarks = self.landmarks
        return new_image
def from_vector ( self , vector , n_channels = None ) : n_channels = self . n_channels if n_channels is None else n_channels if self . mask . all_true ( ) : image_data = vector . reshape ( ( self . shape + ( n_channels , ) ) ) else : image_data = np . zeros ( self . shape + ( n_channels , ) ) pixels_per_channel = vector . reshape ( ( - 1 , n_channels ) ) image_data [ self . mask . mask ] = pixels_per_channel new_image = MaskedImage ( image_data , mask = self . mask ) new_image . landmarks = self . landmarks return new_image
r"""
Takes a flattened vector and returns a new image formed by reshaping
the vector to the correct pixels and channels.
r " " " Takes a flattened vector and returns a new image formed by reshaping the vector to the correct pixels and channels .
r"""
        Takes a flattened vector and returns a new image formed by reshaping
        the vector to the correct pixels and channels. Note that the only
        region of the image that will be filled is the masked region.

        On masked images, the vector is always copied.

        The ``n_channels`` argument is useful for when we want to add an extra
        channel to an image but maintain the shape. For example, when
        calculating the gradient.

        Note that landmarks are transferred in the process.

        Parameters
        ----------
        vector : ``(n_pixels,)``
            A flattened vector of all pixels and channels of an image.
        n_channels : `int`, optional
            If given, will assume that vector is the same shape as this image,
            but with a possibly different number of channels.

        Returns
        -------
        image : :class:`MaskedImage`
            New image of same shape as this image and the number of
            specified channels.
        """ # This is useful for when we want to add an extra channel to an image # but maintain the shape. For example, when calculating the gradient # Creates zeros of size (M x N x ... x n_channels) # we can just reshape the array!
self
vector
n_channels