skimage 0.17.2

NotesParametersReturnsBackRef
view_as_windows(arr_in, window_shape, step=1)

Windows are overlapping views of the input array, with adjacent windows shifted by a single row or column (or an index of a higher dimension).

Notes

One should be very careful with rolling views when it comes to memory usage. Indeed, although a 'view' has the same memory footprint as its base array, the actual array that emerges when this 'view' is used in a computation is generally a (much) larger array than the original, especially for 2-dimensional arrays and above.

For example, let us consider a 3 dimensional array of size (100, 100, 100) of float64 . This array takes about 8*100**3 Bytes for storage which is just 8 MB. If one decides to build a rolling view on this array with a window of (3, 3, 3) the hypothetical size of the rolling view (if one was to reshape the view for example) would be 8*(100-3+1)**3*3**3 which is about 203 MB! The scaling becomes even worse as the dimension of the input array becomes larger.

Parameters

arr_in : ndarray

N-d input array.

window_shape : integer or tuple of length arr_in.ndim

Defines the shape of the elementary n-dimensional orthotope (better know as hyperrectangle ) of the rolling window view. If an integer is given, the shape will be a hypercube of sidelength given by its value.

step : integer or tuple of length arr_in.ndim

Indicates step size at which extraction shall be performed. If integer is given, then the step is uniform in all dimensions.

Returns

arr_out : ndarray

(rolling) window view of the input array.

Rolling window view of the input n-dimensional array.

Examples

This example is valid syntax, but we were not able to check execution
>>> import numpy as np
... from skimage.util.shape import view_as_windows
... A = np.arange(4*4).reshape(4,4)
... A array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11], [12, 13, 14, 15]])
This example is valid syntax, but we were not able to check execution
>>> window_shape = (2, 2)
... B = view_as_windows(A, window_shape)
... B[0, 0] array([[0, 1], [4, 5]])
This example is valid syntax, but we were not able to check execution
>>> B[0, 1]
array([[1, 2],
       [5, 6]])
This example is valid syntax, but we were not able to check execution
>>> A = np.arange(10)
... A array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
This example is valid syntax, but we were not able to check execution
>>> window_shape = (3,)
... B = view_as_windows(A, window_shape)
... B.shape (8, 3)
This example is valid syntax, but we were not able to check execution
>>> B
array([[0, 1, 2],
       [1, 2, 3],
       [2, 3, 4],
       [3, 4, 5],
       [4, 5, 6],
       [5, 6, 7],
       [6, 7, 8],
       [7, 8, 9]])
This example is valid syntax, but we were not able to check execution
>>> A = np.arange(5*4).reshape(5, 4)
... A array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11], [12, 13, 14, 15], [16, 17, 18, 19]])
This example is valid syntax, but we were not able to check execution
>>> window_shape = (4, 3)
... B = view_as_windows(A, window_shape)
... B.shape (2, 2, 4, 3)
This example is valid syntax, but we were not able to check execution
>>> B  # doctest: +NORMALIZE_WHITESPACE
array([[[[ 0,  1,  2],
         [ 4,  5,  6],
         [ 8,  9, 10],
         [12, 13, 14]],
        [[ 1,  2,  3],
         [ 5,  6,  7],
         [ 9, 10, 11],
         [13, 14, 15]]],
       [[[ 4,  5,  6],
         [ 8,  9, 10],
         [12, 13, 14],
         [16, 17, 18]],
        [[ 5,  6,  7],
         [ 9, 10, 11],
         [13, 14, 15],
         [17, 18, 19]]]])
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

skimage.util.shape.view_as_windows

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /skimage/util/shape.py#98
type: <class 'function'>
Commit: