make_contiguous#
- make_contiguous(im, mode='keep_zeros')[source]#
Take an image with arbitrary greyscale values and adjust them to ensure all values fall in a contiguous range starting at 0.
- Parameters:
im (array_like) – An ND array containing greyscale values
mode (string) –
Controls how the ranking is applied in the presence of numbers less than or equal to 0.
- ’keep_zeros’
(default) Voxels equal to 0 remain 0, and all other numbers are ranked starting at 1, include negative numbers, so [-1, 0, 4] becomes [1, 0, 2]
- ’symmetric’
Negative and positive voxels are ranked based on their respective distances to 0, so [-4, -1, 0, 5] becomes [-2, -1, 0, 1]
- ’clipped’
Voxels less than or equal to 0 are set to 0, while all other numbers are ranked starting at 1, so [-3, 0, 2] becomes [0, 0, 1].
- ’none’
Voxels are ranked such that the smallest or most negative number becomes 1, so [-4, 2, 0] becomes [1, 3, 2]. This is equivalent to calling
scipy.stats.rankdata
directly, and reshaping the result to matchim
.
- Returns:
image – An ndarray the same size as
im
but with all values in contiguous order.- Return type:
ndarray
Examples
>>> import porespy as ps >>> import numpy as np >>> im = np.array([[0, 2, 9], [6, 8, 3]]) >>> im = ps.tools.make_contiguous(im) >>> print(im) [[0 1 5] [3 4 2]]
Click here to view online example.