skshape.image package
Subpackages
Submodules
skshape.image.enhancement module
Image enhancement module for image preprocessing and enhancement.
The enhancement module contains image preprocessing funtionality to improve the quality of the image, for example, to smooth an image selectively by preserving features like edges or corners.
-
skshape.image.enhancement.
weighted_smoothing
(image, diffusion_weight=0.0001, data_weight=1.0, weight_function_parameters={})[source] Weighted smoothing of images: smooth regions, preserve sharp edges.
- Parameters
image (NumPy array) –
diffusion_weight (float or NumPy array, optional) – The weight of the diffusion for smoothing. It can be provided as an array the same shape as the image, or as a scalar that will multiply the default weight matrix obtained from the edge indicator function.
data_weight (float or NumPy array, optional) – The weight of the image data to preserve fidelity to the image. It can be provided as an array the same shape as the image, or as a scalar that will multiply the default weight matrix obtained by subtracting the edge indicator function from 1.0.
weight_function_parameters (dict, optional) – The parameters sigma and rho for the edge indicator function. Sigma is the standard deviation for the gaussian gradient applied to the image: dI = N * gaussian_gradient_magnitude(image), where N = min(image.shape) - 1, and rho is the scaling weight in the definition of the edge indicator function: 1/(1 + (dI/rho)**2) The default values are: {‘sigma’: 3.0, ‘rho’: None}. If rho is None, it is calculated by rho = 0.23 * dI.max().
- Returns
smoothed_image
- Return type
NumPy array
- Raises
ValueError – If diffusion_weight or data_weight have the wrong type.
skshape.image.statistics module
Functionality for statistical computations needed by other functions.
This module contains functions for statistical computations. These are mostly auxiliary functions used by other image and shape analysis functions.
-
skshape.image.statistics.
estimate_integration_errors
(I, resolution=None)[source] Estimates the integration errors for elements of about pixel size.
The given image is sampled by domain elements (e.g. triangles), and surface elements (e.g. curve edges), with each element being roughly the pixel size. Quadrature error is evaluated on each element and used to estimate the average error for a unit square or a curve of length one on the image. The purpose is to see what the average error would be if the unit square or the curve is meshed fine enough to resolve the image pixels with small elements.
- Parameters
I (ImageFunction) – An image function that returns the image values for a given 2xN or 3xN array of point coordinates. It can also have the method, resolution(), which returns a tuple consisting of the number of pixels along each axes. This is used if resolution is not given as a separate argument.
resolution (tuple, optional) – A pair or triple of integers defining the grid size to infer the minimum size of mesh elements to be used in integration.
- Returns
domain_int_error (float) – The average integration error on a unit area of the image when the integration is performed on triangles, each roughly the size of a pixel.
surface_int_error (float) – The average integration error on a unit length curve on the image when the curve consists of elements of roughly the size of a pixel.
sample_values (NumPy array) – A one-dimensional NumPy array containing all of the random image values used for the computations.
-
skshape.image.statistics.
two_clusters
(I)[source] Computes two clusters from given vector with k-means algorithm.
Given a one-dimensional array of real numbers, this function computes and returns two clusters using the k-means algorithm. For the method to work well, the data should have a clear bimodal distribution.
- Parameters
I (NumPy array) – A one-dimensional Numpy array of real numbers, which is assumed to have two clusters.
- Returns
clusters (tuple) – A pair of tuples characterizing the two clusters computed. The tuples have the following form:
(center, deviation, share, mask),
where the center is the center (or average) of the cluster computed, deviation is the median of the distances of the points in that cluster to the center, share is the ratio of the points in that cluster to the total number of points, mask is a boolean array of the same size as I and is True for points belonging to the clusters, is False otherwise.
d (NumPy array) – Array of distances for each point in I to its cluster center.
skshape.image.synthetic_image module
Smooth functions used to define continuous synthetic images in 2d, 3d.
This module contains smooth functions with well-defined continuous derivatives, which can be used to define synthetic continuous images.
Examples
For example, we can create a continuous 3d image defined on the unit cube [0,1]^3. This example image includes a sphere/ball and a cube with smooth edges that are not jump discontinuities.
>>> import numpy as np
>>> from skshape.image.synthetic_image import BallFunction, BoxFunction, SyntheticImage
>>> sphere = BallFunction( (0.25,0.25,0.25), 0.2, edge_width=0.03 )
>>> cube = BoxFunction( (0.6,0.6,0.6), (0.85,0.85,0.85), edge_width=0.05 )
>>> img = SyntheticImage( [sphere, cube] )
>>> x = y = z = t = np.linspace(0.0,1.0,1000)
>>> line_coords = np.array((x,y,z))
>>> img_values = img( line_coords )
>>> img_grad_values = img.gradient( line_coords )
-
class
skshape.image.synthetic_image.
BallFunction
(center, radius, edge_width=0.1, edge_func_type='polynomial')[source] Bases:
object
-
gradient
(x)[source]
-
hessian
(x)[source]
-
third_deriv
(x)[source]
-
transition_width
()[source]
-