Skip to content

Commit

Permalink
Merge Balance modes, add new funcs, remove FixBrightness
Browse files Browse the repository at this point in the history
No point in keeping FixBrightness since SinglePlane is actually faster.
  • Loading branch information
noizuy authored Sep 19, 2024
1 parent 526e7b3 commit b24350f
Show file tree
Hide file tree
Showing 2 changed files with 872 additions and 420 deletions.
41 changes: 17 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,34 @@
# FixBrightness

This is a bbmod-style border deringer, which works by multiplying every pixel by the average of dividing each pixel in a line by its nearest pixel in the next line. Unlike bbmod, this doesn't attempt to localize the result and just assumes the same adjustment to be made for the entire row. It's effectively an automated FixBrightness/rektlvls, hence the name.

## Usage

```
core.bore.FixBrightness(clip clip, int top=0, int bottom=0, int left=0, int right=0, clip ignore_mask=None, float thrlo=0.1, float thrhi=8.0, int step=1, int plane=0)
```

* `clip`: 32-bit float clip.
* `top = 0`, `bottom = 0`, `left = 0`, `right = 0`: number of lines from each border to adjust.
* `ignore_mask = None`: Ignore mask, needs to be 8-bit. Anything below 128 will be ignored during adjustment calculation.
* `thrlo = 0.1`: Lower limit of adjustment. Any quotient below this will be ignored.
* `thrhi = 8.0`: Upper limit of adjustment. Any quotient above this will be ignored.
* `step = 1`: Speed up processing ever so slightly by lowering the number of pixels used to find the adjustment. Might be an unnecessary parameter.
* `plane = 0`: Plane to process.
This approach to border deringing uses [linear least squares](https://www.gnu.org/software/gsl/doc/html/lls.html) to find a proper adjustment.

# Balance
SinglePlane does simple linear regression between each line and the first clean line. MultiPlane does the same with multiple linear regression using all three planes. SinglePlaneLimited does this for each pixel individually using only the nearest pixels defined by ref_line_size. SinglePlaneWeighted is SinglePlaneLimited with bilateral filter style weighting for distance and difference. SinglePlaneDebug is the same as SinglePlane, but saves adjustment values to frame props instead of applying them.

This approach to border deringing uses [linear least squares](https://www.gnu.org/software/gsl/doc/html/lls.html) to find a proper adjustment.
SinglePlaneLimited and SinglePlaneWeighted are more experimental and should be used with care.

In simple (0) `mode`, it functions similarly to `FixBrightness`, using simple linear regression instead of a simple mean. This is more robust than `FixBrightness`, although a bit slower.
In multiple (1) `mode`, it uses multiple linear regression with all three planes as input parameters, which may help with ringing that was added in a different color space. This should be considered a last resort effort.
The frame props generated by SinglePlanedebug are:
* `BoreAdjustment`
* `BoreCovariance`
* `BoreSumSquares`
These are in order of operation, i.e. top, bottom, left, right, each from innermost to outermost line.

## Requirements
* [GSL](https://www.gnu.org/software/gsl/)

## Usage

```
core.bore.Balance(clip clip, int top=0, int bottom=0, int left=0, int right=0, int plane=0, int mode=0)
core.bore.SinglePlane(clip clip, int left=0, int right=0, int top=0, int bottom=0, clip ignore_mask=None, int plane=0)
core.bore.MultiPlane(clip clip, int left=0, int right=0, int top=0, int bottom=0, clip ignore_mask=None, int plane=0)
core.bore.SinglePlaneLimited(clip clip, int left=0, int right=0, int top=0, int bottom=0, clip ignore_mask=None, int ref_line_size=100, int plane=0)
core.bore.SinglePlaneWeighted(clip clip, int left=0, int right=0, int top=0, int bottom=0, clip ignore_mask=None, float sigmaS=50.0, float sigmaR=0.5, float sigmaD=1.5, int ref_line_size=100, int plane=0)
core.bore.SinglePlaneDebug(clip clip, int left=0, int right=0, int top=0, int bottom=0, clip ignore_mask=None, int plane=0)
```

* `clip`: 32-bit float clip.
* `top = 0`, `bottom = 0`, `left = 0`, `right = 0`: number of lines from each border to adjust.
* `left = 0`, `right = 0`, `top = 0`, `bottom = 0`: number of lines from each border to adjust.
* `ignore_mask = None`: 8-bit gray mask with pixels to avoid when calculating the adjustment. If more than one plane exists, only the first one is used, so it needs to match the to-be-adjusted plane's resolution.
* `plane = 0`: Plane to adjust.
* `mode = 0`: Linear regression mode, 0 for simple and 1 for multiple linear regression using all three planes as parameters (requires no subsampling). Mode 2 is a debugging mode for simple linear regression that attaches the following frame properties: BalanceAdjustment, BalanceCovariance, BalanceSumSquares. Note that the values are in order of operation, i.e. top -> bottom -> left -> right with values for the innermost lines first.
* `sigmaS = 50, sigmaR = 0.5, sigmaD = 1.5`: SinglePlaneWeighted's smoothing parameters, same as a bilateral filter's, sigmaR is difference between pixels in same line, sigmaD is difference between adjustments compared to current pixel and its neighbor.
* `ref_line_size = 100`: Reference line size for SinglePlaneLimited/Weighted. The actual size is `2 * ref_line_size + 1`.

# Compilation

Expand Down
Loading

0 comments on commit b24350f

Please sign in to comment.