A package for computer vision in Python.
Returns an RGB image
If any of the channels is None, that channel is set to zero.
| Parameters : | r,g,b : array-like, optional
|
|---|---|
| Returns : | rgb : ndarray
|
Calculate the bounding box of image img.
| Parameters : | img : ndarray
|
|---|---|
| Returns : | min1,max1,min2,max2 : int,int,int,int
|
Compute the border region between i and j regions.
A pixel is on the border if it has value i (or j) and a pixel in its neighbourhood (defined by Bc) has value j (or i).
| Parameters : | labeled : ndarray of integer type
i : integer j : integer Bc : structure element, optional output : ndarray of same shape as labeled, dtype=bool, optional
always_return : bool, optional
|
|---|---|
| Returns : | border_img : boolean ndarray
|
Compute border pixels
A pixel is on a border if it has value i and a pixel in its neighbourhood (defined by Bc) has value j, with i != j.
| Parameters : | labeled : ndarray of integer type
Bc : structure element, optional output : ndarray of same shape as labeled, dtype=bool, optional
|
|---|---|
| Returns : | border_img : boolean ndarray
|
Find the perimeter of objects in binary images.
A pixel is part of an object perimeter if its value is one and there is at least one zero-valued pixel in its neighborhood.
By default the neighborhood of a pixel is 4 nearest pixels, but if n is set to 8 the 8 nearest pixels will be considered.
| Parameters : | bw : ndarray
n : int, optional
|
|---|---|
| Returns : | perim : ndarray
|
See also
Returns the center of mass of img.
If labels is given, then it returns L centers of mass, one for each region identified by labels (including region 0).
| Parameters : | img : ndarray labels : ndarray
|
|---|---|
| Returns : | coords : ndarray
|
closed = close_holes(ref, Bc=None):
Close Holes
| Parameters : | ref : ndarray
Bc : structuring element, optional
|
|---|---|
| Returns : | closed : ndarray
|
Convolution of f and weights
Convolution is performed in doubles to avoid over/underflow, but the result is then cast to f.dtype.
| Parameters : | f : ndarray
weights : ndarray
mode : {‘reflect’ [default], ‘nearest’, ‘wrap’, ‘mirror’, ‘constant’}
cval : double, optional
output : ndarray, optional
|
|---|---|
| Returns : | convolved : ndarray of same dtype as f |
Convolution of f and weights along axis axis.
Convolution is performed in doubles to avoid over/underflow, but the result is then cast to f.dtype.
| Parameters : | f : ndarray
weights : 1-D ndarray
axis : int
mode : {‘reflect’ [default], ‘nearest’, ‘wrap’, ‘mirror’, ‘constant’}
cval : double, optional
output : ndarray, optional
|
|---|---|
| Returns : | convolved : ndarray of same dtype as f |
See also
Returns a version of img cropped to the image’s bounding box
| Parameters : | img : ndarray
border : int, optional
|
|---|---|
| Returns : | nimg : ndarray
|
Seeded Watershed
| Parameters : | surface : image markers : image
Bc : ndarray, optional
return_lines : boolean, optional
|
|---|---|
| Returns : | W : Regions image (i.e., W[i,j] == region for pixel (i,j)) WL : Lines image (if return_lines==True) |
Morphological dilation.
The type of operation depends on the dtype of A! If boolean, then the dilation is binary, else it is greyscale dilation. In the case of greyscale dilation, the smallest value in the domain of Bc is interpreted as +Inf.
| Parameters : | A : ndarray of bools
Bc : ndarray, optional
|
|---|---|
| Returns : | dilated : ndarray
|
See also
Computes the distance transform of image bw:
dmap[i,j] = min_{i', j'} { (i-i')**2 + (j-j')**2 | bw[i', j'] }
| Parameters : | bw : 2d-ndarray
metric : str, optional
|
|---|---|
| Returns : | dmap : ndarray
|
Morphological erosion.
The type of operation depends on the dtype of A! If boolean, then the erosion is binary, else it is greyscale erosion. In the case of greyscale erosion, the smallest value in the domain of Bc is interpreted as -Inf.
| Parameters : | A : ndarray of bools
Bc : ndarray, optional
|
|---|---|
| Returns : | erosion : ndarray
|
See also
Compute the Euler number of image f
The Euler number is also known as the Euler characteristic given that many other mathematical objects are also known as Euler numbers.
| Parameters : | f : ndarray
n : int, optional
|
|---|---|
| Returns : | euler_nr : int
|
Return a histogram with bins 0, 1, ..., ``img.max()``.
After calling this function, it will be true that hist[i] == (img == i).sum(), for all i.
| Parameters : | img : array-like of an unsigned type
|
|---|---|
| Returns : | hist : an dnarray of type np.uint32
|
Multi-dimensional Gaussian filter.
| Parameters : | array : ndarray
sigma : scalar or sequence of scalars
order : {0, 1, 2, 3} or sequence from same set, optional
mode : {‘reflect’ [default], ‘nearest’, ‘wrap’, ‘mirror’, ‘constant’}
cval : double, optional
output : ndarray, optional
|
|---|---|
| Returns : | filtered : ndarray
|
Notes
The multi-dimensional filter is implemented as a sequence of one-dimensional convolution filters. The intermediate arrays are stored in the same data type as the output. Therefore, for output types with a limited precision, the results may be imprecise because intermediate results may be stored with insufficient precision.
One-dimensional Gaussian filter.
| Parameters : | array : ndarray
sigma : float
axis : int, optional
order : {0, 1, 2, 3}, optional
mode : {‘reflect’ [default], ‘nearest’, ‘wrap’, ‘mirror’, ‘constant’}
cval : double, optional
output : ndarray, optional
|
|---|---|
| Returns : | filtered : ndarray
|
Retrieve appropriate structuring element
| Parameters : | A : ndarray
Bc : None, int, or array-like
|
||||||
|---|---|---|---|---|---|---|---|
| Returns : | Bc_out : ndarray
|
Hit & Miss transform
For a given pixel position, the hit&miss is True if, when Bc is overlaid on input, centered at that position, the 1 values line up with ``1``s, while the ``0``s line up with ``0``s (``2``s correspond to don’t care).
| Parameters : | input : input ndarray
Bc : ndarray
output : output array |
|---|---|
| Returns : | output : ndarray |
img’ = imresize(img, nsize)
Resizes img
| Parameters : | img : ndarray nsize : float or tuple(float) or tuple(integers)
order : integer, optional
|
|---|---|
| Returns : | img’ : ndarray |
See also
Label the array
| Parameters : | array : ndarray
Bc : ndarray, optional
output : ndarray, optional
|
|---|---|
| Returns : | labeled : ndarray
nr_objects : int
|
Labeled sum. sum will be an array of size labeled.max() + 1, where sum[i] is equal to np.sum(array[labeled == i]).
| Parameters : | array : ndarray of any type labeled : int ndarray
|
|---|---|
| Returns : | sums : 1-d ndarray of array.dtype |
Majority filter
filtered[y,x] is positive if the majority of pixels in the squared of size N centred on (y,x) are positive.
| Parameters : | img : ndarray
N : int, optional
output : ndarray, optional
|
|---|---|
| Returns : | filtered : ndarray
|
Median filter
| Parameters : | f : ndarray
Bc : ndarray or int, optional
mode : {‘reflect’ [default], ‘nearest’, ‘wrap’, ‘mirror’, ‘constant’}
cval : double, optional
output : ndarray, optional
|
|---|---|
| Returns : | median : ndarray of same type and shape as f
|
Returns the p0-p1 moment of image img
The formula computed is
sum_{ij} { img[i,j] (i - c0)**p0 (j - c1)**p1 }
where cm = (c0,c1). If cm is not given, then (0,0) is used.
If image is of an integer type, then it is internally converted to np.float64, unlesss convert_to_float is False. The reason is that, otherwise, overflow is likely except for small images. Since this conversion takes longer than the computation, you can turn it off in case you are sure that your images are small enough for overflow to be an issue. Note that no conversion is made if img is of any floating point type.
| Parameters : | img : 2-ndarray
p0 : float
p1 : float
cm : (int,int), optional
convert_to_float : boolean, optional
|
|---|---|
| Returns : | moment: float :
|
Calculate a threshold according to the Otsu method.
| Parameters : | img : an image as a numpy array.
ignore_zeros : Boolean
|
|---|---|
| Returns : | T : integer
|
Rank filter. The value at ranked[i,j] will be the rank``th largest in the neighbourhood defined by ``Bc.
| Parameters : | f : ndarray
Bc : ndarray
rank : integer mode : {‘reflect’ [default], ‘nearest’, ‘wrap’, ‘mirror’, ‘constant’}
cval : double, optional
output : ndarray, optional
|
|---|---|
| Returns : | ranked : ndarray of same type and shape as f
|
See also
Calculate a threshold according to the Riddler-Calvard method.
| Parameters : | img : ndarray
ignore_zeros : boolean, optional
|
|---|---|
| Returns : | T : float
|
Compute edges using Sobel’s algorithm
edges is a binary image of edges computed according to Sobel’s algorithm.
This implementation is tuned to match MATLAB’s implementation.
| Parameters : | img : Any 2D-ndarray just_filter : boolean, optional
|
|---|---|
| Returns : | edges : ndarray
|
img’ = stretch(img, [dtype=np.uint8]) img’ = stretch(img, max, [dtype=np.uint8]) img’ = stretch(img, min, max, [dtype=np.uint8])
| Parameters : | img : ndarray
min : integer, optional
max : integer, optional
dtype : dtype of output,optional
|
|---|---|
| Returns : | img’: ndarray :
|
Match template.
The value at match[i,j] will be the difference (in squared euclidean terms), between template and a same sized window on f centered on that point.
| Parameters : | f : ndarray
template : ndarray
mode : {‘reflect’ [default], ‘nearest’, ‘wrap’, ‘mirror’, ‘constant’}
cval : double, optional
output : ndarray, optional
|
|---|---|
| Returns : | match : ndarray of same type and shape as f
|
Skeletonisation by thinning
| Parameters : | binimg : Binary input image |
|---|---|
| Returns : | skel : Skeletonised version of binimg |
Read an image into a ndarray.
| Parameters : | filename : str
as_grey : boolean, optional
formatstr : str, optional
|
|---|---|
| Returns : | im : ndarray
|
Writes array into file filename
| Parameters : | filename : str
array : ndarray-like formatstr: str, optional :
|
|---|
Compute Haralick texture features
Computes the Haralick texture features for the four 2-D directions or thirteen 3-D directions (depending on the dimensions of f).
| Parameters : | f : ndarray of integer type
ignore_zeros : bool, optional
preserve_haralick_bug : bool, optional
compute_14th_feature : bool, optional
|
|---|---|
| Returns : | feats : ndarray of np.double
|
Notes
Haralick’s paper has a typo in one of the equations. This function implements the correct feature unless preserve_haralick_bug is True. The only reason why you’d want the buggy behaviour is if you want to match another implementation.
Compute Linear Binary Patterns
| Parameters : | image : ndarray
radius : number (integer or floating point)
points : integer
ignore_zeros : boolean, optional
|
|---|---|
| Returns : | features : 1-D numpy ndarray
|
Compute parameter free Threshold Adjacency Statistics
TAS were presented by Hamilton et al. in “Fast automated cell phenotype image classification” (http://www.biomedcentral.com/1471-2105/8/110)
The current version is an adapted version which is free of parameters. The thresholding is done by using Otsu’s algorithm (or can be pre-computed and passed in by setting T), the margin around the mean of pixels to be included is the standard deviation.
Also returns a version computed on the negative of the binarisation defined by Hamilton et al.
Use tas() to get the original version of the features.
| Parameters : | img : ndarray, 2D or 3D
T : integer, optional
|
|---|---|
| Returns : | values : ndarray
|
Compute Threshold Adjacency Statistics
TAS were presented by Hamilton et al. in “Fast automated cell phenotype image classification” (http://www.biomedcentral.com/1471-2105/8/110)
Also returns a version computed on the negative of the binarisation defined by Hamilton et al.
See also pftas() for a variation without any hardcoded parameters.
| Parameters : | img : ndarray, 2D or 3D
|
|---|---|
| Returns : | values : ndarray
|
See also
Zernike moments through degree
Returns a vector of absolute Zernike moments through degree for the image im.
| Parameters : | im : 2-ndarray
radius : integer
degree : integer, optional
cm : pair of floats, optional
|
|---|---|
| Returns : | zvalues : 1-ndarray of floats
|