|
| 1 | +""" |
| 2 | + glcm = glcm(img, distance, angle, mat_size=16) |
| 3 | + glcm = glcm(img, distances, angle, mat_size=16) |
| 4 | + glcm = glcm(img, distance, angles, mat_size=16) |
| 5 | + glcm = glcm(img, distances, angles, mat_size=16) |
| 6 | +
|
| 7 | +Calculates the GLCM (Gray Level Co-occurence Matrix) of an image. The `distances` and `angles` arguments may be |
| 8 | +a single integer or a vector of integers if multiple GLCMs need to be calculated. The `mat_size` argument is used |
| 9 | +to define the granularity of the GLCM. |
| 10 | +""" |
1 | 11 | function glcm(img::AbstractArray{T, 2}, distance::Integer, angle::Real, mat_size::Integer = 16) where T<:Real |
2 | 12 | max_img = maximum(img) |
3 | 13 | img_rescaled = map(i -> max(1, Int(ceil(i * mat_size / max_img))), img) |
@@ -45,31 +55,58 @@ function _glcm(img::AbstractArray{T, 2}, distance::Integer, angle::Number, mat_s |
45 | 55 | co_oc_matrix |
46 | 56 | end |
47 | 57 |
|
48 | | -function glcm_symmetric(img::AbstractArray, distance::Integer, angle::Real, mat_size) |
| 58 | +""" |
| 59 | + glcm = glcm_symmetric(img, distance, angle, mat_size=16) |
| 60 | + glcm = glcm_symmetric(img, distances, angle, mat_size=16) |
| 61 | + glcm = glcm_symmetric(img, distance, angles, mat_size=16) |
| 62 | + glcm = glcm_symmetric(img, distances, angles, mat_size=16) |
| 63 | +
|
| 64 | +Symmetric version of the [`glcm`](@ref) function. |
| 65 | +""" |
| 66 | +function glcm_symmetric(img::AbstractArray, distance::Integer, angle::Real, mat_size=16) |
49 | 67 | co_oc_matrix = glcm(img, distance, angle, mat_size) |
50 | 68 | co_oc_matrix_trans = co_oc_matrix' |
51 | 69 | co_oc_matrix_symm = co_oc_matrix + co_oc_matrix_trans |
52 | 70 | co_oc_matrix_symm |
53 | 71 | end |
54 | 72 |
|
55 | | -function glcm_symmetric(img::AbstractArray, distances, angles, mat_size) |
| 73 | +function glcm_symmetric(img::AbstractArray, distances, angles, mat_size=16) |
56 | 74 | co_oc_matrices = glcm(img, distances, angles, mat_size) |
57 | 75 | co_oc_matrices_sym = map(gmat -> gmat + gmat', co_oc_matrices) |
58 | 76 | co_oc_matrices_sym |
59 | 77 | end |
60 | 78 |
|
61 | | -function glcm_norm(img::AbstractArray, distance::Integer, angle::Real, mat_size) |
| 79 | +""" |
| 80 | + glcm = glcm_norm(img, distance, angle, mat_size) |
| 81 | + glcm = glcm_norm(img, distances, angle, mat_size) |
| 82 | + glcm = glcm_norm(img, distance, angles, mat_size) |
| 83 | + glcm = glcm_norm(img, distances, angles, mat_size) |
| 84 | +
|
| 85 | +Normalised version of the [`glcm`](@ref) function. |
| 86 | +""" |
| 87 | +function glcm_norm(img::AbstractArray, distance::Integer, angle::Real, mat_size=16) |
62 | 88 | co_oc_matrix = glcm(img, distance, angle, mat_size) |
63 | 89 | co_oc_matrix_norm = co_oc_matrix / Float64(sum(co_oc_matrix)) |
64 | 90 | co_oc_matrix_norm |
65 | 91 | end |
66 | 92 |
|
67 | | -function glcm_norm(img::AbstractArray, distances, angles, mat_size) |
| 93 | +function glcm_norm(img::AbstractArray, distances, angles, mat_size=16) |
68 | 94 | co_oc_matrices = glcm(img, distances, angles, mat_size) |
69 | 95 | co_oc_matrices_norm = map(gmat -> gmat /= Float64(sum(gmat)), co_oc_matrices) |
70 | 96 | co_oc_matrices_norm |
71 | 97 | end |
72 | 98 |
|
| 99 | +""" |
| 100 | +Multiple properties of the obtained GLCM can be calculated by using the `glcm_prop` function which calculates the |
| 101 | +property for the entire matrix. If grid dimensions are provided, the matrix is divided into a grid and the property |
| 102 | +is calculated for each cell resulting in a height x width property matrix. |
| 103 | +```julia |
| 104 | +prop = glcm_prop(glcm, property) |
| 105 | +prop = glcm_prop(glcm, height, width, property) |
| 106 | +``` |
| 107 | +Various properties can be calculated like `mean`, `variance`, `correlation`, `contrast`, `IDM` (Inverse Difference Moment), |
| 108 | + `ASM` (Angular Second Moment), `entropy`, `max_prob` (Max Probability), `energy` and `dissimilarity`. |
| 109 | +""" |
73 | 110 | function glcm_prop(gmat::Array{T, 2}, window_height::Integer, window_width::Integer, property::Function) where T<:Real |
74 | 111 | k_h = Int(floor(window_height / 2)) |
75 | 112 | k_w = Int(floor(window_width / 2)) |
|
0 commit comments