Histogram now works with all 3 colours
This commit is contained in:
parent
2e47ff349f
commit
c157549fe4
1 changed files with 11 additions and 4 deletions
|
@ -21,17 +21,23 @@ def extract_edge_features(frame):
|
||||||
|
|
||||||
def extract_histogram_features(frame, bins=64):
|
def extract_histogram_features(frame, bins=64):
|
||||||
"""
|
"""
|
||||||
Extract histogram features from a frame.
|
Extract histogram features from a frame with 3 channels.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
- frame (ndarray): Image frame.
|
- frame (ndarray): Image frame with shape (height, width, 3).
|
||||||
- bins (int): Number of bins for the histogram.
|
- bins (int): Number of bins for the histogram.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
- ndarray: Normalized histogram feature vector.
|
- ndarray: Normalized histogram feature vector.
|
||||||
"""
|
"""
|
||||||
histogram, _ = np.histogram(frame.flatten(), bins=bins, range=[0, 255])
|
feature_vector = []
|
||||||
return histogram.astype(np.float32) / frame.size
|
for channel in range(3):
|
||||||
|
histogram, _ = np.histogram(frame[:,:,channel].flatten(), bins=bins, range=[0, 255])
|
||||||
|
normalized_histogram = histogram.astype(np.float32) / frame[:,:,channel].size
|
||||||
|
feature_vector.extend(normalized_histogram)
|
||||||
|
|
||||||
|
return np.array(feature_vector)
|
||||||
|
|
||||||
|
|
||||||
def preprocess_frame(frame):
|
def preprocess_frame(frame):
|
||||||
# Check frame dimensions and resize if necessary
|
# Check frame dimensions and resize if necessary
|
||||||
|
@ -41,6 +47,7 @@ def preprocess_frame(frame):
|
||||||
# Extract features
|
# Extract features
|
||||||
edge_feature = extract_edge_features(frame)
|
edge_feature = extract_edge_features(frame)
|
||||||
histogram_feature = extract_histogram_features(frame)
|
histogram_feature = extract_histogram_features(frame)
|
||||||
|
|
||||||
histogram_feature_image = np.full((HEIGHT, WIDTH), histogram_feature.mean()) # Convert histogram feature to image-like shape
|
histogram_feature_image = np.full((HEIGHT, WIDTH), histogram_feature.mean()) # Convert histogram feature to image-like shape
|
||||||
combined_feature = np.stack([edge_feature, histogram_feature_image], axis=-1)
|
combined_feature = np.stack([edge_feature, histogram_feature_image], axis=-1)
|
||||||
|
|
||||||
|
|
Reference in a new issue