Skip to content

Commit febe4a5

Browse files
authored
Repace _compute_frame_average with numpy.mean (#480)
repace _compute_frame_average with numpy.mean
1 parent 429434d commit febe4a5

File tree

1 file changed

+1
-27
lines changed

1 file changed

+1
-27
lines changed

scenedetect/detectors/threshold_detector.py

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,6 @@
2525

2626
logger = getLogger("pyscenedetect")
2727

28-
##
29-
## ThresholdDetector Helper Functions
30-
##
31-
32-
33-
def _compute_frame_average(frame: numpy.ndarray) -> float:
34-
"""Computes the average pixel value/intensity for all pixels in a frame.
35-
36-
The value is computed by adding up the 8-bit R, G, and B values for
37-
each pixel, and dividing by the number of pixels multiplied by 3.
38-
39-
Arguments:
40-
frame: Frame representing the RGB pixels to average.
41-
42-
Returns:
43-
Average pixel intensity across all 3 channels of `frame`
44-
"""
45-
num_pixel_values = float(frame.shape[0] * frame.shape[1] * frame.shape[2])
46-
avg_pixel_value = numpy.sum(frame[:, :, :]) / num_pixel_values
47-
return avg_pixel_value
48-
49-
50-
##
51-
## ThresholdDetector Class Implementation
52-
##
53-
5428

5529
class ThresholdDetector(SceneDetector):
5630
"""Detects fast cuts/slow fades in from and out to a given threshold level.
@@ -150,7 +124,7 @@ def process_frame(self, frame_num: int, frame_img: numpy.ndarray) -> ty.List[int
150124
):
151125
frame_avg = self.stats_manager.get_metrics(frame_num, self._metric_keys)[0]
152126
else:
153-
frame_avg = _compute_frame_average(frame_img)
127+
frame_avg = numpy.mean(frame_img)
154128
if self.stats_manager is not None:
155129
self.stats_manager.set_metrics(frame_num, {self._metric_keys[0]: frame_avg})
156130

0 commit comments

Comments
 (0)