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.

... [0, 0, 0, 2, 0, 0, 0],<br />

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

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

... [0, 0, 0, 0, 0, 0, 1]], numarray.Int8)<br />

>>> print watershed_ift(input, markers)<br />

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

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

[1 1 2 2 2 1 1]<br />

[1 1 2 2 2 1 1]<br />

[1 1 2 2 2 1 1]<br />

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

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

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

The result is that the object (marker = 2) is smaller because the second marker was processed earlier. This<br />

may not be the desired effect if the first marker was supposed to designate a background object. Therefore<br />

watershed_ift treats markers with a negative value explicitly as background markers and processes<br />

them after the normal markers. For instance, replacing the first marker by a negative marker gives a result<br />

similar to the first example:<br />

>>> markers = array([[0, 0, 0, 0, 0, 0, 0],<br />

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

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

... [0, 0, 0, 2, 0, 0, 0],<br />

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

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

... [0, 0, 0, 0, 0, 0, -1]], numarray.Int8)<br />

>>> print watershed_ift(input, markers)<br />

[[-1 -1 -1 -1 -1 -1 -1]<br />

[-1 -1 2 2 2 -1 -1]<br />

[-1 2 2 2 2 2 -1]<br />

[-1 2 2 2 2 2 -1]<br />

[-1 2 2 2 2 2 -1]<br />

[-1 -1 2 2 2 -1 -1]<br />

[-1 -1 -1 -1 -1 -1 -1]]<br />

The connectivity of the objects is defined by a structuring element. If no structuring element is provided,<br />

one is generated by calling generate_binary_structure (see Binary morphology) using a connectivity<br />

of one (which in 2D is a 4-connected structure.) For example, using an 8-connected structure<br />

with the last example yields a different object:<br />

>>> print watershed_ift(input, markers,<br />

... structure = [[1,1,1], [1,1,1], [1,1,1]])<br />

[[-1 -1 -1 -1 -1 -1 -1]<br />

[-1 2 2 2 2 2 -1]<br />

[-1 2 2 2 2 2 -1]<br />

[-1 2 2 2 2 2 -1]<br />

[-1 2 2 2 2 2 -1]<br />

[-1 2 2 2 2 2 -1]<br />

[-1 -1 -1 -1 -1 -1 -1]]<br />

Note: The implementation of watershed_ift limits the data types of the input to UInt8 and<br />

UInt16.<br />

1.10. Multi-dimensional image processing (ndimage) 75

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

Saved successfully!

Ooh no, something went wrong!