-
Notifications
You must be signed in to change notification settings - Fork 409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Color Histogram Detector #295
Color Histogram Detector #295
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for taking this on, great work. Looking forward to experimenting to see what performance and accuracy improvements we can make for this.
Sorry for the long delay in getting back to you on this.
Moved to scenedetect/_cli/__init__.py
Sorry for the commit spam, I was trying to use the web editor to get this back up to date on the latest changes in develop. There's still a few failing tests, but this has been merged into develop to continue work on it. I'll fix the failing tests up as soon as possible and we can continue figuring out the remainder on #53 . Have added a TODO so this doesn't get lost: |
* Initial implementation of HistogramDetector. * Added check for color channels * Added tests for detect-hist. * Added documentation for detect-hist. * Add detect-hist to test_cli * Fix formatting * Fix test_histogram_detector * Move detect-hist to new location. * Delete scenedetect/cli/__init__.py Moved to scenedetect/_cli/__init__.py * Add config options for detect-hist * Update config.py * Update __init__.py * Update config.py --------- Co-authored-by: Brandon Castellano <[email protected]>
Would it be possible to have a mode that only detects hardcuts ignoring gradual transitions? It would be useful for video frame interpolation, where the goal is to stop interpolation over cuts but not overdetect continuous motion. |
@elexor See #100 for an open issue regarding fade detection. Right now PySceneDetect only has the ability to detect fast cuts (detectors can only output hard cuts). When using the threshold detector, a cut is placed between the fade in/fade out point. API support for non-hard cuts is planned in the future, which would allow for better handling of cases like this. |
As discussed in #53 by @r1b, I have taken inspiration from his notebook as well as this paper (pdf) and implemented a color histogram based detector. Command syntax is as follows:
For some detail on the detection algorithm, it works in a couple steps:
--bits
/-b
most significant bits of each pixel. The purpose of this step is to reduce the size of the histogram we will be generating in a future step to make it a bit more tractable.--bits 2
, the resulting array would have elements with bit values of0bRRGGBB
where RR are the two most significant bits from the red channel, GG from the green channel, and BB from the blue channel. With--bits 4
this becomes0bRRRRGGGGBBBB
and so on. This is done by performing bitwise shift operations on the different color channels before joining them using bitwise or operations.--bits 4
that would be 212 (12 comes from the 4 bits for each of the three color channels). Using--bits 2
would be 26 bins.hist_diff
.There are a couple things that I should mention with the current implementation. First and foremost is that the input frames need to be an 8-bit color image. This means that grayscale images that don't have the three color channels will not work. Also, inputs that have a bit-depth greater than 8 bits such as image sequences of 16-bit images will not work. I have included some checks to make sure the input is of the right shape and dtype.
The threshold is very sensitive to changes in the analysis parameters. Changing options like the downscale factor or the
--bits
value will have a large impact on what a good threshold would be. Just something to note as the other detectors are not as sensitive to these kind of changes. For defaults, I have chosen values that work well on the goldeneye clip with default downscaling.Computationally, this detector is not as efficient as others. I have done some testing on my machine and included below the average fps of the detection for different detection algorithms with both default downscaling and
-d 1
.-d
default-d 1
detect-hist
-b 4
detect-hist
-b 2
detect-content
detect-adaptive
detect-threshold
If this is something worth cleaning up/improving, I can work on tests and docs.