Skip to content

libhb: Initial implementation of Chroma Smooth filter. - #1957

Merged
bradleysepos merged 3 commits into
HandBrake:masterfrom
bradleysepos:chroma-smooth
Mar 28, 2019
Merged

bradleysepos merged 3 commits into
HandBrake:masterfrom
bradleysepos:chroma-smooth

Conversation

@bradleysepos

@bradleysepos bradleysepos commented Mar 7, 2019 •

Copy link
Copy Markdown
Contributor

Useful for resolving various color-related issues, especially with lower resolution content from analog sources, e.g. not great DVD and VHS sources.

The blurring/smoothing algorithm is the same as used by the unsharp filter.

Some under-the-hood aspects could be improved. Currently, the Y/Luma plane is copied in memory; it would be great if we had something like hb_buffer_copy() for only one plane. Also, thread init allocates the same data for all three planes, where most of it is only needed for the chroma planes.

Performance is stellar. In some cases the result may be preferable to what NLMeans does, and it's way faster.

Needs GUI implementation.

Test on:

  • Windows 10+ (via MinGW)
  • macOS 10.13+
  • Ubuntu Linux

Screenshots (If relevant):

Original, default CLI preset:

chroma-smooth-original

Chroma Smooth preset Very Strong, tune Very Wide:

chroma-smooth-verystrong-verywide

@bradleysepos

Copy link
Copy Markdown
Contributor Author

Some additional comparisons, full color and the a channel in Lab color, which is similar to the Cr channel in YCbCr. Enlarged 2x in both dimensions for comparison.

I realize there's not much going on in the scene and not much color variety; I chose the scene to highlight the chroma rainbow on the fence, which flickers horribly in motion, since it's a particularly common problem and a difficult one to overcome with HandBrake's current filters. Using appropriate settings (current preset Very Strong, tune Medium seems to work well), there is no perceptible chroma rainbow or flickering in motion after filtering.

This is a particularly bad source, so it's normal for stronger and wider settings to perform better. That said, I'll probably tweak the strength presets to be stronger. The weaker presets don't do much at all in the current iteration.

Presets comparison (smoothing strength)

Slideshow videos:

Images (open full size in tabs to compare):

  1. Original
  2. Preset Ultralight, tune Medium
  3. Preset Medium, tune Medium
  4. Preset Very Strong, tune Medium

chroma-smooth-original

chroma-smooth-ultralight-medium

chroma-smooth-medium-medium

chroma-smooth-verystrong-medium

chroma-smooth-original-a

chroma-smooth-ultralight-medium-a

chroma-smooth-medium-medium-a

chroma-smooth-verystrong-medium-a

Tunes comparison (smoothing width)

Slideshow videos:

Images (open full size in tabs to compare):

  1. Original
  2. Preset Very Strong, tune Tiny
  3. Preset Very Strong, tune Medium
  4. Preset Very Strong, tune Very Wide

chroma-smooth-original

chroma-smooth-verystrong-tiny

chroma-smooth-verystrong-medium

chroma-smooth-verystrong-verywide

chroma-smooth-original-a

chroma-smooth-verystrong-tiny-a

chroma-smooth-verystrong-medium-a

chroma-smooth-verystrong-verywide-a

@bradleysepos

Copy link
Copy Markdown
Contributor Author

No comments/concerns, or no time to review?

@jstebbins

Copy link
Copy Markdown
Contributor

Sorry, no time to review yet ☹️

@bradleysepos

Copy link
Copy Markdown
Contributor Author

I updated the strengths and reduced the width of the Very Wide tune from 13 px to 11 px.

Encoding times are for a single run, not an average. Suffice to say, there is essentially no speed impact on SD content with 6 cores / 12 threads. Unlike the previous examples, these are deinterlaced with EEDI2.

You can see that stronger settings appear to lead to artifacts (creating or enhancing existing ones) in the grayscale chroma plane(s); however, viewing the full color images proves this still continues to further reduce the appearance of chroma noise, rainbows, and other prominent visual artifacts.

Images (open full size in tabs to compare):

  1. Original (1m43.517s)
  2. Preset Ultralight, tune Medium (1m42.126s)
  3. Preset Light, tune Medium (1m39.838s)
  4. Preset Medium, tune Medium (1m39.923s)
  5. Preset Strong, tune Medium (1m42.462s)
  6. Preset Stronger, tune Medium (1m44.502s)
  7. Preset Very Strong, tune Medium (1m46.674s)

chroma-smooth-original

chroma-smooth-ultralight-medium

chroma-smooth-light-medium

chroma-smooth-medium-medium

chroma-smooth-strong-medium

chroma-smooth-stronger-medium

chroma-smooth-verystrong-medium

chroma-smooth-original-a

chroma-smooth-ultralight-medium-a

chroma-smooth-light-medium-a

chroma-smooth-medium-medium-a

chroma-smooth-strong-medium-a

chroma-smooth-stronger-medium-a

chroma-smooth-verystrong-medium-a

@bradleysepos

Copy link
Copy Markdown
Contributor Author

Another very difficult analog tape source. Comparison in full color and the b channel in Lab color, which is similar to the Cb channel in YCbCr.

Images (open full size in tabs to compare):

  1. Original
  2. NLMeans preset Strong, tune Tape
  3. Chroma Smooth preset Strong, tune Very Wide
  4. Both NLMeans and Chroma Smooth (running in that order)

As you can see, Chroma Smooth significantly reduces banding that NLMeans does not. Together, the chroma is smooth and clean, relatively speaking.

chroma-smooth-jungle-original

chroma-smooth-jungle-nlmeans-only

chroma-smooth-jungle-strong-verywide

chroma-smooth-jungle-both

chroma-smooth-jungle-original-b

chroma-smooth-jungle-nlmeans-only-b

chroma-smooth-jungle-strong-verywide-b

chroma-smooth-jungle-both-b

@bradleysepos

Copy link
Copy Markdown
Contributor Author

One more, a relatively clean animation source that suffers from chroma rainbows that flicker madly. NLMeans can't do anything about it, and with luma filtering enabled harms detail slightly. Chroma Smooth removes most of the rainbow and reduces the flicker to a tolerable minimum. The side effect to removing the worst annoyances is a small loss of saturation.

Images (open full size in tabs to compare):

  1. Original
  2. NLMeans preset Medium, tune Animation
  3. Chroma Smooth preset Strong, tune Medium

chroma-smooth-animation-original

chroma-smooth-animation-nlmeans

chroma-smooth-animation-strong-medium

@Nomis101

Copy link
Copy Markdown
Contributor

This are impressive results. I like your Chroma Smooth filter. I have some older movie sources, that would benefit from such a filter.

Comment thread libhb/chroma_smooth.c Resolved

@jstebbins jstebbins left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tried to understand how it works. But code looks good. Just the 2 nits.

Comment thread libhb/chroma_smooth.c Resolved
@jstebbins

Copy link
Copy Markdown
Contributor

Have you run it through valgrind yet? I always do a valgrind run on a few seconds of video when messing with buffers or pretty much any large change. Caught a double free of an hb_dict_t in my avfilter PR that way 😉

@jstebbins

Copy link
Copy Markdown
Contributor

Hmm, regarding luma_copy and chroma_smooth, why not just pass in the hb_buffer_t in and out instead of digging into the buffer details at the function call. Have the function split out the components it needs.

@bradleysepos

Copy link
Copy Markdown
Contributor Author

I have not valgrinded this, yet. I believe I suggested it regarding the avfilter PR. Guess I should take my own advice. 😸

@bradleysepos

Copy link
Copy Markdown
Contributor Author

Pushed some changes. I backed out the passing buffers idea because it's a bit involved to pass around the thread data properly, ends up being uglier. Would like to merge if all are satisfied.

@jstebbins

Copy link
Copy Markdown
Contributor

fine with me.

@bradleysepos
bradleysepos merged commit ed4a2a3 into HandBrake:master Mar 28, 2019
@bradleysepos
bradleysepos deleted the chroma-smooth branch March 28, 2019 17:55
@Nomis101

Nomis101 commented May 2, 2019

Copy link
Copy Markdown
Contributor

Will the Chroma Smooth filter get an UI in HandBrake or is this for command line use only?

@bradleysepos

Copy link
Copy Markdown
Contributor Author

Eventually.

@mkikoen

mkikoen commented Dec 31, 2019

Copy link
Copy Markdown

@bradleysepos Nice Job Man! Looks pretty good so far.

Once you have time, you should keep on tweaking the filter to see if it's possible to get around the reduced saturation side effect since this is a very important post processing filter to me. Also, I recommend that you should assign the GUI implementation of the Chroma Smooth Filter to Version 1.4.0 milestone once that happens.

I'll be looking forward to having this implemented in the next update ASAP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

6 participants