https://en.wikipedia.org/wiki/Image_texture https://en.wikipedia.org/wiki/Co-occurrence_matrix#Application_to_image_analysis
|
Binarizes a grayscale image based on a given threshold value, |
|
Apply binary mask, or thresholding based |
|
Opening filter, defined as the sequence of |
|
Simple method for calculating the euclidean distance between two points, |
|
Calculate all Haralick descriptors for a sequence of |
|
Calculate all Euclidean distances between a selected base descriptor |
|
Uses luminance weights to transform RGB channel to greyscale, by |
|
Calculates all 8 Haralick descriptors based on co-occurrence input matrix. |
|
Calculate sample co-occurrence matrix based on input image |
|
Normalizes a 1D array, between ranges 0-cap. |
|
Normalizes image in Numpy 2D array format, between ranges 0-cap, |
|
Opening filter, defined as the sequence of |
|
Simple implementation of Root Mean Squared Error |
|
Simple image transformation using one of two available filter functions: |
Binarizes a grayscale image based on a given threshold value, setting values to 1 or 0 accordingly.
>>> binarize(np.array([[128, 255], [101, 156]]))
array([[1, 1],
[0, 1]])
>>> binarize(np.array([[0.07, 1], [0.51, 0.3]]), threshold=0.5)
array([[0, 1],
[1, 0]])
Apply binary mask, or thresholding based on bit mask value (mapping mask is binary).
Returns the mapped true value mask and its complementary false value mask.
>>> img = np.array([[[108, 201, 72], [255, 11, 127]],
... [[56, 56, 56], [128, 255, 107]]])
>>> gray = grayscale(img)
>>> binary = binarize(gray)
>>> morphological = opening_filter(binary)
>>> binary_mask(gray, morphological)
(array([[1, 1],
[1, 1]], dtype=uint8), array([[158, 97],
[ 56, 200]], dtype=uint8))
Opening filter, defined as the sequence of dilation and then erosion filter on the same image.
>>> img = np.array([[1, 0.5], [0.2, 0.7]])
>>> img = binarize(img, threshold=0.5)
>>> closing_filter(img)
array([[0, 0],
[0, 0]], dtype=uint8)
Simple method for calculating the euclidean distance between two points, with type np.ndarray.
>>> a = np.array([1, 0, -2])
>>> b = np.array([2, -1, 1])
>>> euclidean(a, b)
3.3166247903554
Calculate all Haralick descriptors for a sequence of different co-occurrence matrices, given input masks and coordinates.
>>> img = np.array([[[108, 201, 72], [255, 11, 127]],
... [[56, 56, 56], [128, 255, 107]]])
>>> gray = grayscale(img)
>>> binary = binarize(gray)
>>> morphological = opening_filter(binary)
>>> get_descriptors(binary_mask(gray, morphological), (0, 1))
array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])
Calculate all Euclidean distances between a selected base descriptor and all other Haralick descriptors The resulting comparison is return in decreasing order, showing which descriptor is the most similar to the selected base.
descriptors: Haralick descriptors to compare with base index base: Haralick descriptor index to use as base when calculating respective euclidean distance to other descriptors.
Ordered distances between descriptors
>>> index = 1
>>> img = np.array([[[108, 201, 72], [255, 11, 127]],
... [[56, 56, 56], [128, 255, 107]]])
>>> gray = grayscale(img)
>>> binary = binarize(gray)
>>> morphological = opening_filter(binary)
>>> get_distances(get_descriptors(
... binary_mask(gray, morphological), (0, 1)),
... index)
[(0, 0.0), (1, 0.0), (2, 0.0), (3, 0.0), (4, 0.0), (5, 0.0), (6, 0.0), (7, 0.0), (8, 0.0), (9, 0.0), (10, 0.0), (11, 0.0), (12, 0.0), (13, 0.0), (14, 0.0), (15, 0.0)]
Uses luminance weights to transform RGB channel to greyscale, by taking the dot product between the channel and the weights.
>>> grayscale(np.array([[[108, 201, 72], [255, 11, 127]],
... [[56, 56, 56], [128, 255, 107]]]))
array([[158, 97],
[ 56, 200]], dtype=uint8)
Calculates all 8 Haralick descriptors based on co-occurrence input matrix. All descriptors are as follows: Maximum probability, Inverse Difference, Homogeneity, Entropy, Energy, Dissimilarity, Contrast and Correlation
matrix: Co-occurrence matrix to use as base for calculating descriptors.
Reverse ordered list of resulting descriptors
>>> img = np.array([[[108, 201, 72], [255, 11, 127]],
... [[56, 56, 56], [128, 255, 107]]])
>>> gray = grayscale(img)
>>> binary = binarize(gray)
>>> morphological = opening_filter(binary)
>>> mask_1 = binary_mask(gray, morphological)[0]
>>> concurrency = matrix_concurrency(mask_1, (0, 1))
>>> [float(f) for f in haralick_descriptors(concurrency)]
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
Calculate sample co-occurrence matrix based on input image as well as selected coordinates on image.
Implementation is made using basic iteration, as function to be performed (np.max) is non-linear and therefore not callable on the frequency domain.
>>> img = np.array([[[108, 201, 72], [255, 11, 127]],
... [[56, 56, 56], [128, 255, 107]]])
>>> gray = grayscale(img)
>>> binary = binarize(gray)
>>> morphological = opening_filter(binary)
>>> mask_1 = binary_mask(gray, morphological)[0]
>>> matrix_concurrency(mask_1, (0, 1))
array([[0., 0.],
[0., 0.]])
Normalizes a 1D array, between ranges 0-cap.
array: List containing values to be normalized between cap range. cap: Maximum cap amount for normalization.
return 1D numpy array, corresponding to limited range array
>>> normalize_array(np.array([2, 3, 5, 7]))
array([0. , 0.2, 0.6, 1. ])
>>> normalize_array(np.array([[5], [7], [11], [13]]))
array([[0. ],
[0.25],
[0.75],
[1. ]])
Normalizes image in Numpy 2D array format, between ranges 0-cap, as to fit uint8 type.
image: 2D numpy array representing image as matrix, with values in any range cap: Maximum cap amount for normalization data_type: numpy data type to set output variable to
return 2D numpy array of type uint8, corresponding to limited range matrix
>>> normalize_image(np.array([[1, 2, 3], [4, 5, 10]]),
... cap=1.0, data_type=np.float64)
array([[0. , 0.11111111, 0.22222222],
[0.33333333, 0.44444444, 1. ]])
>>> normalize_image(np.array([[4, 4, 3], [1, 7, 2]]))
array([[127, 127, 85],
[ 0, 255, 42]], dtype=uint8)
Opening filter, defined as the sequence of erosion and then a dilation filter on the same image.
>>> img = np.array([[1, 0.5], [0.2, 0.7]])
>>> img = binarize(img, threshold=0.5)
>>> opening_filter(img)
array([[1, 1],
[1, 1]], dtype=uint8)
Simple implementation of Root Mean Squared Error for two N dimensional numpy arrays.
>>> root_mean_square_error(np.array([1, 2, 3]), np.array([1, 2, 3]))
0.0
>>> root_mean_square_error(np.array([1, 2, 3]), np.array([2, 2, 2]))
0.816496580927726
>>> root_mean_square_error(np.array([1, 2, 3]), np.array([6, 4, 2]))
3.1622776601683795
Simple image transformation using one of two available filter functions: Erosion and Dilation.
image: binarized input image, onto which to apply transformation kind: Can be either ‘erosion’, in which case the :func:np.max
function is called, or ‘dilation’, when :func:np.min is used instead.
to be used when applying convolution to original image
returns a numpy array with same shape as input image, corresponding to applied binary transformation.
>>> img = np.array([[1, 0.5], [0.2, 0.7]])
>>> img = binarize(img, threshold=0.5)
>>> transform(img, 'erosion')
array([[1, 1],
[1, 1]], dtype=uint8)
>>> transform(img, 'dilation')
array([[0, 0],
[0, 0]], dtype=uint8)