mirror of
https://github.com/wassname/scikit-image.git
synced 2026-09-11 12:43:04 +08:00
DOC: Added latex formulas to docstring
This commit is contained in:
@@ -122,24 +122,25 @@ def compute_glcm(image, distances, angles, levels=256, symmetric=False,
|
|||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
def compute_glcm_prop(glcm, prop='contrast'):
|
def compute_glcm_prop(P, prop='contrast'):
|
||||||
"""Calculate texture properties of a GLCM.
|
"""Calculate texture properties of a GLCM.
|
||||||
|
|
||||||
Compute a feature of a grey level co-occurance matrix to serve as
|
Compute a feature of a grey level co-occurance matrix to serve as
|
||||||
a compact summary of the matrix. The properties are computed as
|
a compact summary of the matrix. The properties are computed as
|
||||||
follows:
|
follows:
|
||||||
|
|
||||||
- 'contrast': :math:`X`
|
- 'contrast': :math:`\\sum_{i,j=0}^{levels-1} P_{i,j}(i-j)^2`
|
||||||
- 'dissimilarity': :math:`X`
|
- 'dissimilarity': :math:`\\sum_{i,j=0}^{levels-1} P_{i,j}\\left|i-j\\right|`
|
||||||
- 'homogeneity': :math:`X`
|
- 'homogeneity': :math:`\\sum_{i,j=0}^{levels-1}\\frac{P_{i,j}}{1+(i-j)^2}`
|
||||||
- 'energy': :math:`X`
|
- 'ASM': :math:`\\sum_{i,j=0}^{levels-1} P_{i,j}^2`
|
||||||
- 'correlation': :math:`X`
|
- 'energy': :math:`\\sqrt{ASM}`
|
||||||
- 'ASM': :math:`X`
|
- 'correlation': :math:`\\sum_{i,j=0}^{levels-1} P_{i,j}\\left[\\frac{(i-\\mu_i)(j-\\mu_j)}{\\sqrt{(\\sigma_i^2)(\\sigma_j^2)}}\\right]`
|
||||||
|
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
glcm : ndarray
|
P : ndarray
|
||||||
Input array. `glcm` is the grey-level co-occurrence histogram
|
Input array. `P` is the grey-level co-occurrence histogram
|
||||||
for which to compute the specified property. The value
|
for which to compute the specified property. The value
|
||||||
`P[i,j,d,theta]` is the number of times that grey-level j
|
`P[i,j,d,theta]` is the number of times that grey-level j
|
||||||
occurs at a distance d and at an angle theta from
|
occurs at a distance d and at an angle theta from
|
||||||
@@ -176,8 +177,8 @@ def compute_glcm_prop(glcm, prop='contrast'):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
assert glcm.ndim == 4
|
assert P.ndim == 4
|
||||||
(num_level, num_level2, num_dist, num_angle) = glcm.shape
|
(num_level, num_level2, num_dist, num_angle) = P.shape
|
||||||
assert num_level == num_level2
|
assert num_level == num_level2
|
||||||
assert num_dist > 0
|
assert num_dist > 0
|
||||||
assert num_angle > 0
|
assert num_angle > 0
|
||||||
@@ -201,12 +202,12 @@ def compute_glcm_prop(glcm, prop='contrast'):
|
|||||||
for d in range(num_dist):
|
for d in range(num_dist):
|
||||||
for a in range(num_angle):
|
for a in range(num_angle):
|
||||||
if prop == 'energy':
|
if prop == 'energy':
|
||||||
asm = (glcm[:, :, d, a] ** 2).sum()
|
asm = (P[:, :, d, a] ** 2).sum()
|
||||||
results[d, a] = np.sqrt(asm)
|
results[d, a] = np.sqrt(asm)
|
||||||
elif prop == 'ASM':
|
elif prop == 'ASM':
|
||||||
results[d, a] = (glcm[:, :, d, a] ** 2).sum()
|
results[d, a] = (P[:, :, d, a] ** 2).sum()
|
||||||
elif prop == 'correlation':
|
elif prop == 'correlation':
|
||||||
g = glcm[:, :, d, a]
|
g = P[:, :, d, a]
|
||||||
mean_i = (I * g).sum()
|
mean_i = (I * g).sum()
|
||||||
mean_j = (J * g).sum()
|
mean_j = (J * g).sum()
|
||||||
diff_i = I - mean_i
|
diff_i = I - mean_i
|
||||||
@@ -221,6 +222,6 @@ def compute_glcm_prop(glcm, prop='contrast'):
|
|||||||
|
|
||||||
results[d, a] = corr
|
results[d, a] = corr
|
||||||
else:
|
else:
|
||||||
results[d, a] = (glcm[:, :, d, a] * weights).sum()
|
results[d, a] = (P[:, :, d, a] * weights).sum()
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|||||||
Reference in New Issue
Block a user