7
7
Frontiers in Psychology, 4, 808.
8
8
9
9
Created on Sat Aug 3 11:34:57 2024
10
- Last edited on Sat Aug 3 14:09 :43 2024
10
+ Last edited on Fri Sep 13 16:30 :43 2024
11
11
12
12
@author: Giulio Gabrieli ([email protected] )
13
13
"""
@@ -69,11 +69,17 @@ def calculate_hog(image, orientations=16, pixels_per_cell=(16, 16), cells_per_bl
69
69
Calculate the Histogram of Oriented Gradients (HOG) for a given image.
70
70
71
71
:param image: Input image.
72
+ :type image: numpy.ndarray
72
73
:param orientations: Number of orientation bins.
74
+ :type orientation: int
73
75
:param pixels_per_cell: Size (in pixels) of a cell.
76
+ :type pixels_per_cell: tuple
74
77
:param cells_per_block: Number of cells in each block.
78
+ type cells_per_block: tuple
75
79
:param visualize: Whether to return an image of the HOG.
80
+ :type visualize: bool
76
81
:return: HOG feature vector and HOG image (if visualize is True).
82
+ :rtype: numpy.ndarray
77
83
"""
78
84
hog_features , hog_image = hog (image , orientations = orientations , pixels_per_cell = pixels_per_cell ,
79
85
cells_per_block = cells_per_block , visualize = visualize , block_norm = 'L2-Hys' )
@@ -84,8 +90,11 @@ def bin_hog_features(hog_features, n_bins):
84
90
Bin the HOG features into n bins.
85
91
86
92
:param hog_features: HOG feature vector.
93
+ :type hog_features: numpy.ndarray
87
94
:param n_bins: Number of bins.
95
+ :type n_bins: int
88
96
:return: Binned HOG feature vector.
97
+ :rtype: numpy.ndarray
89
98
"""
90
99
# Calculate the size of each bin
91
100
bin_size = len (hog_features ) // n_bins
@@ -103,7 +112,9 @@ def plot_hog_histogram(binned_hog_features, n_bins):
103
112
Plot the histogram of the binned HOG features.
104
113
105
114
:param binned_hog_features: Binned HOG feature vector.
115
+ :type hog_features: numpy.ndarray
106
116
:param n_bins: Number of bins.
117
+ :type n_bins: int
107
118
"""
108
119
plt .figure (figsize = (10 , 6 ))
109
120
plt .bar (range (n_bins ), binned_hog_features , align = 'center' , alpha = 0.7 )
@@ -112,13 +123,16 @@ def plot_hog_histogram(binned_hog_features, n_bins):
112
123
plt .title ('Histogram of Oriented Gradients (HOG) with 16 Bins' )
113
124
plt .show ()
114
125
115
- def get_self_similarity (image , methods = ['ground' , 'parent' , 'neighbors' , 'anisotropy' ]):
126
+ def get_self_similarity (image , methods = ['ground' , 'parent' , 'neighbors' , 'anisotropy' ], resize = True , newsize = ( 512 , 512 ) ):
116
127
"""
117
128
Calculate the self-similarity and anisotropy of an image using HOG features.
118
129
119
130
:param image: Input image.
131
+ :type image: numpy.ndarray
120
132
:param methods: List of methods to calculate self-similarity. Options are 'ground', 'parent', 'neighbors', 'anisotropy'.
133
+ :type methods: list
121
134
:return: Dictionary of self-similarity measures.
135
+ :rtype: dict
122
136
"""
123
137
results = {}
124
138
0 commit comments