[PR #932] [IMPROVEMENT] Modify -quant 0 option #1763

Open
opened 2026-01-29 17:18:26 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/CCExtractor/ccextractor/pull/932

State: closed
Merged: Yes


Please prefix your pull request with one of the following: [FEATURE] [FIX] [IMPROVEMENT].

In raising this pull request, I confirm the following (please check boxes):

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • I have considered, and confirmed that this submission will be valuable to others.
  • I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  • I give this submission freely, and claim no ownership to its content.

My familiarity with the project is as follows (check one):

  • I have never used CCExtractor.
  • I have used CCExtractor just a couple of times.
  • I absolutely love CCExtractor, but have not contributed previously.
  • I am an active contributor to CCExtractor.

This pull request aims at simplifying and making the -quant 0 parameter faster. It does so by reducing the number of distinct color shades available in the palette of the PNG image under processing.

An example would be, say a palette color is (248, 187, 027). The new algorithm reduces this image to (224, 160, 0). This is one quantised value amongst the (888) which can be formed under this algorithm. Since the color palette is reduced and our rect bitmap structures point to palette for their pixel color value; in a way this algorithm decreases the color value to the nearest multiple of 32 for R,G,B; effectively quantising it without much reduction in the actual image visibility.

As can be seen in the below screenshot, this method improves the time taken (92 seconds vs 100 seconds) and also gives a better result than no quantisation.

With 8-bit color reduction

As is marked in the below screenshot (with no quant algorithm at all), a dialogue is read as "Are you off the deck". This is a mistake which does not happen and is read as "Are you off the clock" with the improved algorithm. The video is provided along with the timestamp to check for authenticity.

without color reduction

video screenshot

At last below is a diff between the two files to see the other error corrections that the method provides, (for example it correctly reads "I" (capital "i") which were read as "|")

difference between the two extracted subtitles

For video file, refer issue #929

Minor Addition: Added below line which can be uncommented to output debug.png from ocr_bitmap() function
save_spupng("debug.png", indata, w, h, palette, alpha, 16);

**Original Pull Request:** https://github.com/CCExtractor/ccextractor/pull/932 **State:** closed **Merged:** Yes --- Please prefix your pull request with one of the following: **[FEATURE]** **[FIX]** **[IMPROVEMENT]**. **In raising this pull request, I confirm the following (please check boxes):** - [X] I have read and understood the [contributors guide](https://github.com/CCExtractor/ccextractor/blob/master/.github/CONTRIBUTING.md). - [X] I have checked that another pull request for this purpose does not exist. - [X] I have considered, and confirmed that this submission will be valuable to others. - [X] I accept that this submission may not be used, and the pull request closed at the will of the maintainer. - [X] I give this submission freely, and claim no ownership to its content. **My familiarity with the project is as follows (check one):** - [ ] I have never used CCExtractor. - [ ] I have used CCExtractor just a couple of times. - [ ] I absolutely love CCExtractor, but have not contributed previously. - [X] I am an active contributor to CCExtractor. --- This pull request aims at simplifying and making the -quant 0 parameter faster. It does so by reducing the number of distinct color shades available in the palette of the PNG image under processing. An example would be, say a palette color is (248, 187, 027). The new algorithm reduces this image to (224, 160, 0). This is one quantised value amongst the (8*8*8) which can be formed under this algorithm. Since the color palette is reduced and our rect bitmap structures point to palette for their pixel color value; in a way this algorithm decreases the color value to the nearest multiple of 32 for R,G,B; effectively quantising it without much reduction in the actual image visibility. As can be seen in the below screenshot, this method improves the time taken (92 seconds vs 100 seconds) and also gives a better result than no quantisation. ![With 8-bit color reduction](https://user-images.githubusercontent.com/32812320/36497081-47a274d6-1760-11e8-8a6e-f1ff883af9d6.png) As is marked in the below screenshot (with no quant algorithm at all), a dialogue is read as "Are you off the deck". This is a mistake which does not happen and is read as "Are you off the clock" with the improved algorithm. The video is provided along with the timestamp to check for authenticity. ![without color reduction](https://user-images.githubusercontent.com/32812320/36497173-835fbc2c-1760-11e8-9044-f0a1d4527320.png) ![video screenshot](https://user-images.githubusercontent.com/32812320/36497188-8ecdec28-1760-11e8-9955-e68e72ed51c0.png) At last below is a diff between the two files to see the other error corrections that the method provides, (for example it correctly reads "I" (capital "i") which were read as "|") ![difference between the two extracted subtitles](https://user-images.githubusercontent.com/32812320/36497260-cd5e6eae-1760-11e8-8c30-f26ffd1f6222.png) For video file, refer issue #929 Minor Addition: Added below line which can be uncommented to output debug.png from ocr_bitmap() function `save_spupng("debug.png", indata, w, h, palette, alpha, 16);`
claunia added the pull-request label 2026-01-29 17:18:26 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/ccextractor#1763