'Transforms the image samples in X into a matrix of patch data.
Parameters
X : array, shape = (n_samples, image_height, image_width) or
(n_samples, image_height, image_width, n_channels)
Array of images from which to extract patches. For color images,
the last dimension specifies the channel: a RGB image would have
`n_channels=3`.
Returns
patches : array, shape = (n_patches, patch_height, patch_width) or
(n_patches, patch_height, patch_width, n_channels)
The collection of patches extracted from the images, where
`n_patches` is either `n_samples * max_patches` or the total
number of patches that can be extracted.'

def transform(self, X):

    self.random_state = check_random_state(self.random_state)
    (n_images, i_h, i_w) = X.shape[:3]
    X = np.reshape(X, (n_images, i_h, i_w, (-1)))
    n_channels = X.shape[(-1)]
    if (self.patch_size is None):
        patch_size = ((i_h // 10), (i_w // 10))
    else:
        patch_size = self.patch_size
    (p_h, p_w) = patch_size
    n_patches = _compute_n_patches(i_h, i_w, p_h, p_w, self.max_patches)
    patches_shape = (((n_images * n_patches),) + patch_size)
    if (n_channels > 1):
        patches_shape += (n_channels,)
    patches = np.empty(patches_shape)
    for (ii, image) in enumerate(X):
        patches[(ii * n_patches):((ii + 1) * n_patches)] = extract_patches_2d(image, patch_size, self.max_patches, self.random_state)
    return patches
