15.12.2012 Views

scipy tutorial - Baustatik-Info-Server

scipy tutorial - Baustatik-Info-Server

scipy tutorial - Baustatik-Info-Server

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

SciPy Reference Guide, Release 0.8.dev<br />

>>> print binary_dilation(zeros(a.shape), struct, -1, a, border_value=1)<br />

[[1 0 0 0 0]<br />

[1 1 0 0 0]<br />

[0 0 0 0 0]<br />

[0 0 0 0 0]]<br />

The binary_erosion and binary_dilation functions both have an iterations parameter which allows the<br />

erosion or dilation to be repeated a number of times. Repeating an erosion or a dilation with a given structure n times<br />

is equivalent to an erosion or a dilation with a structure that is n-1 times dilated with itself. A function is provided that<br />

allows the calculation of a structure that is dilated a number of times with itself:<br />

The iterate_structure function returns a structure by dilation of the input structure iteration - 1<br />

times with itself. For instance:<br />

>>> struct = generate_binary_structure(2, 1)<br />

>>> print struct<br />

[[0 1 0]<br />

[1 1 1]<br />

[0 1 0]]<br />

>>> print iterate_structure(struct, 2)<br />

[[0 0 1 0 0]<br />

[0 1 1 1 0]<br />

[1 1 1 1 1]<br />

[0 1 1 1 0]<br />

[0 0 1 0 0]]<br />

If the origin of the original structure is equal to 0, then it is also equal to 0 for the iterated structure. If not,<br />

the origin must also be adapted if the equivalent of the iterations erosions or dilations must be achieved<br />

with the iterated structure. The adapted origin is simply obtained by multiplying with the number of<br />

iterations. For convenience the iterate_structure also returns the adapted origin if the origin<br />

parameter is not None:<br />

>>> print iterate_structure(struct, 2, -1)<br />

(array([[0, 0, 1, 0, 0],<br />

[0, 1, 1, 1, 0],<br />

[1, 1, 1, 1, 1],<br />

[0, 1, 1, 1, 0],<br />

[0, 0, 1, 0, 0]], type=Bool), [-2, -2])<br />

Other morphology operations can be defined in terms of erosion and d dilation. Following functions provide a few of<br />

these operations for convenience:<br />

The binary_opening function implements binary opening of arrays of arbitrary rank with the given<br />

structuring element. Binary opening is equivalent to a binary erosion followed by a binary dilation with<br />

the same structuring element. The origin parameter controls the placement of the structuring element as<br />

described in Filter functions. If no structuring element is provided, an element with connectivity equal to<br />

one is generated using generate_binary_structure. The iterations parameter gives the number<br />

of erosions that is performed followed by the same number of dilations.<br />

The binary_closing function implements binary closing of arrays of arbitrary rank with the given<br />

structuring element. Binary closing is equivalent to a binary dilation followed by a binary erosion with<br />

the same structuring element. The origin parameter controls the placement of the structuring element as<br />

described in Filter functions. If no structuring element is provided, an element with connectivity equal to<br />

one is generated using generate_binary_structure. The iterations parameter gives the number<br />

of dilations that is performed followed by the same number of erosions.<br />

70 Chapter 1. SciPy Tutorial

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!