Skip to content

Instantly share code, notes, and snippets.

View noizuy's full-sized avatar

noizuy

View GitHub Profile
@noizuy
noizuy / lee_banding_mask.py
Created February 19, 2024 14:01
The very simple false contour mask from Ji Won Lee, Bo Ra Lim, Rae-Hong Park, Jae-Seung Kim and Wonseok Ahn, "Two-stage false contour detection using directional contrast and its application to adaptive false contour reduction," in IEEE Transactions on Consumer Electronics, vol. 52, no. 1, pp. 179-188, Feb. 2006, doi: 10.1109/TCE.2006.1605045.
from collections.abc import Callable
import vapoursynth as vs
core = vs.core
from vstools import depth, get_peak_value, get_lowest_value, get_y
def lee_banding_mask(clip: vs.VideoNode, bits: int = 2, threshold: int | None = None, edge_detection: Callable = core.std.Sobel):
"""
False contour detection via bit depth reduction. The idea is (overly) simple: Re-quantize and find difference to input, calculate the gradient, and mark gradients under a threshold as false contours.
Naturally, this only works on content that isn't naturally flat.
# False contour detection is described in http://dx.doi.org/10.1109/ICCE.2006.1598468
# Smoothing is described in http://dx.doi.org/10.1109/TCE.2010.5506014
# Direction estimation is described in http://dx.doi.org/10.1109/TCE.2006.1706513
#
# These papers seem to all be a part of the same project.
# Their end result uses the original false contour detection and uses a NN along with the directional smoothing used here to choose which pixels to smooth and how.
# Keep in mind it works in your given image's bit depth.
#
# Usage in REPL:
# include("/path/to/script.jl")
@noizuy
noizuy / banding.md
Last active February 8, 2024 14:57

keywords are usually debanding, bit depth expansion, false contour removal, decontouring

CCL-based stuff only works on banding that stems from heavy compression (i.e. completely flat bands) and falls apart with flat content

Debanders

Knowledge-based

@noizuy
noizuy / BEF-BDE.ipynb
Created March 13, 2023 13:07
C. Peng, M. Xia, Z. Fu, J. Xu and X. Li, "Bilateral False Contour Elimination Filter-Based Image Bit-Depth Enhancement," in IEEE Signal Processing Letters, vol. 28, pp. 1585-1589, 2021, doi: 10.1109/LSP.2021.3099962. without false contour map - they removed it in a later paper anyway. meme
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@noizuy
noizuy / autolvls.py
Last active November 2, 2023 08:06
automated dirty line fix - basically just bbmod without the limiting
import vapoursynth as vs
core = vs. core
from vstools import join, plane, depth
# b-spline like in bbmod
def bblur(c, w=1, h=None):
if h is None:
h = w
return c.resize.Bicubic(width=w, height=h, filter_param_a=1, filter_param_b=0).resize.Bicubic(width=c.width, height=c.height, filter_param_a=1, filter_param_b=0)
@noizuy
noizuy / NABF.jl
Created February 27, 2023 12:41
quick and dirty bilateral and noise aware bilateral (supposedly you should gen a LUT): Jang, Sung-Joon & Hwang, Youngbae. (2020). Noise-Aware and Light-Weight VLSI Design of Bilateral Filter for Robust and Fast Image Denoising in Mobile Systems. Sensors. 20. 4722. 10.3390/s20174722.
# https://www.researchgate.net/publication/343806997_Noise-Aware_and_Light-Weight_VLSI_Design_of_Bilateral_Filter_for_Robust_and_Fast_Image_Denoising_in_Mobile_Systems
using LinearAlgebra, Images, SpecialFunctions
function fs(xi, x, σ_s)
exp((norm(xi - x) ^ 2) / (-2 * σ_s ^ 2))
end
function fr(xi, x, σ_r)
exp((norm(xi - x) ^ 2) / (-2 * σ_r ^ 2))
end
@noizuy
noizuy / x264-aq-bias-strength-tmod.patch
Created October 23, 2022 08:51
x264 patch to add the aq-bias-strength parameter. For x264-tmod.
From 9d7c2b58022b0cee8eae1c1308576fb876b067df Mon Sep 17 00:00:00 2001
From: noizuy <85082087+noizuy@users.noreply.github.com>
Date: Sun, 23 Oct 2022 10:42:52 +0200
Subject: [PATCH] add aq-bias-strength parameter New parameter that controls
the dark bias strength via multiplication of AQ strength in AQ mode 3.
---
common/base.c | 5 +++++
encoder/ratecontrol.c | 2 +-
x264.c | 2 ++
@noizuy
noizuy / x264-aq-bias-strength.patch
Last active October 21, 2022 14:28
x264-aMod patch to add the aq-bias-strength parameter. For x264-aMod. Should be easily ported to tmod.
diff --git a/common/base.c b/common/base.c
index c249b141..6e2f3bf4 100644
--- a/common/base.c
+++ b/common/base.c
@@ -416,6 +416,7 @@ REALIGN_STACK void x264_param_default( x264_param_t *param )
param->rc.f_pb_factor = 1.3;
param->rc.i_aq_mode = X264_AQ_VARIANCE;
param->rc.f_aq_strength = 1.0;
+ param->rc.f_aq_bias_strength = 1.0;
param->rc.i_lookahead = 40;
@noizuy
noizuy / mad_neo_f3kdb.patch
Last active October 19, 2022 16:55
Idk if this still works, but this was a patch to add one of the madVR debander checks to neo_f3kdb, which this renames to mad_neo_f3kdb for testing. Make sure to disable CPU optimizations, since it's only added to the C++ code.
diff --git a/src/flash3kyuu_deband_impl_c.cpp b/src/flash3kyuu_deband_impl_c.cpp
index f1e800b..31cd792 100644
--- a/src/flash3kyuu_deband_impl_c.cpp
+++ b/src/flash3kyuu_deband_impl_c.cpp
@@ -167,6 +167,14 @@ static __forceinline void __cdecl process_plane_plainc_mode12_high(const process
int diff4 = ref_4_up - src_px_up;
use_org_px_as_base = is_above_threshold(threshold, diff1, diff2, diff3, diff4);
}
+
+ int ref_pixel_sum = abs(ref_1_up - src_px_up);
@noizuy
noizuy / aq-fast-edge.patch
Last active October 21, 2022 15:05
At high resolutions, AQ modes 4 & 5 show a significant speed reduction. This option (--aq-fast-edge) allows the user to omit the 5x5 Gaussian blur applied before edge detection is performed, slightly improving encode speed. Goes on top of the AQ mode 5 patch.
From 534154762b267f7a8e16620b530de2b18026c5e3 Mon Sep 17 00:00:00 2001
From: noizuy <85082087+noizuy@users.noreply.github.com>
Date: Mon, 26 Sep 2022 12:46:29 +0200
Subject: [PATCH] add AQ fast edge option At high resolutions, AQ modes 4 & 5
show a significant speed reduction. This option allows the user to omit the
5x5 Gaussian blur applied before edge detection is performed, slightly
improving encode speed.
---
doc/reST/cli.rst | 4 +++