- L -
28th August 2016, 15:24
Fast Edge-Preserving Smoothing for Local Contrast Enhancement - MPC-HC Shaders
- This is a fast, edge & gradient preserving, blur shaders.
- It's based on Bilateral Filter, but with omitted Spatial/Gaussian Weight and modified Range/Intensity weight
- Gradient preservation using the measure of Maximum luminance difference between origin(o), sample(a), and the inverse of sample(a'), this idea based on a post by tritical. (http://forum.doom9.org/showthread.php?p=510605#post510605)
- It use a multiple pass/stacked filter and 5 texture fetch per pass, you could use as few as 3 pass to perform Local Contrast Enhancement.
- It use CIELab color space.
- Only tested on madVR.
sampler s0; float2 c1 : register(c1);
#define bsigma 0.050 // sigma for blurring, higher value means more blur thus higher contrast enhancement
//
#define dsigma 0.003 // sigma for denoising, set to 0(off) for a clean source
// value between 0.003-0.005 do a mild denoise while retaining most of the detail
#define offset 10.000 // sampling offset, adjust accordingly : 1st pass offset: n, 2nd pass offset n/2, 3rd pass offset n/4 ...
// e.g. :
// 21x21 kernel : 1st pass 10.0, 2nd pass 5.0, 3rd pass 2.5 , 4th pass 1.25(last pass might be unnecessary/not noticable)
// 81x81 kernel : 1st pass 40.0, 2nd pass 20.0, ............ , 6th pass 1.25(last pass might be unnecessary/not noticable)
/*
#define dlt(o,a,b) o-a // standard delta, luminance difference of: origin(o) and sample(a)
// does not preserve gradient
*/
#define dlt(o,a,b) max(o,max(a,b))-min(o,min(a,b)) // modified delta, maximum luminance difference of: origin(o), sample(a), inverse sample(b)
// preserve gradient
#define wi(d,s) exp( -(d*d) / (2*s*s))
#define Tx(x,y) tex2D(s0, tex + c1*float2(x,y))
#define Tx0 Tx(0,0)
#define pxo Tx(0,0).xw
static const float2 sigma = { bsigma, dsigma};
float4 main(float2 tex : TEXCOORD0) : COLOR {
float2 px[5+1],delta,coef,blur; int n; coef=blur=n=0;
px[1] = Tx(-offset, 0).xw;
px[2] = Tx( 0, offset).xw;
px[3] = Tx( 0.0, 0.0 ).xw;
px[4] = Tx( 0,-offset).xw;
px[5] = Tx( offset, 0).xw;
for (int i = 1; i <= 5; ++i) { n++;
delta = dlt(pxo,px[n],px[5+1-n]);
coef += wi(delta,sigma);
blur += px[n]*wi(delta,sigma); }
blur /= coef;
if (dsigma > 0.0)
return float4(blur.x,Tx0.yz,blur.y);
else
return float4(blur.x,Tx0.yzw);
}
Blur Comparison : Input (https://s10.postimg.io/mqm1qih49/S_00_input.png) | Exact Bilateral Filter (https://s3.postimg.io/5jlzk70mb/S_01_exact_CIE_Lab.png) | Shaders 3 pass (offset 10,5,2.5) sigma 0.03 (https://s14.postimg.io/bhzjq9mqp/S_02_Shaders_3_pass_sigma_0_030.png)
LCE Comparison : Input (https://s10.postimg.io/mqm1qih49/S_00_input.png) | Result (Shaders 3 pass (offset 10,5,2.5) sigma 0.03) (https://s16.postimg.io/6z584l9tx/S_03_Shaders_3_pass_sigma_0_030_Sharp.png)
LCE Comparison : samsung_opera_DWEU.mkv (https://s21.postimg.io/qmqu0b5ev/opera_in.png) | Result (Shaders 6 pass (offset 40,20,10,5,2.5,1.25) sigma 0.05, strength 1.2) (https://s3.postimg.io/l6d8xkeeb/opera_out.png)
Download (https://drive.google.com/file/d/0B0C7XTDhJ4MMWGNYQ3VGbFJfU1E/view)
- Installation -
Set as post-resize shader, in the following order:
FastLCE - RGB2Lab
FastLCE - Blur - Offset 10.00 (Larger offset first)
FastLCE - Blur - Offset 05.00
FastLCE - Blur - Offset 02.50
FastLCE - Contrast Enhancement
FastLCE - Lab2RGB
Disclaimer:I'm not a programmer by any means, so the above code may or may not work on your setup.
Use it only on HD and clean source cause it may increase noise/banding.
- This is a fast, edge & gradient preserving, blur shaders.
- It's based on Bilateral Filter, but with omitted Spatial/Gaussian Weight and modified Range/Intensity weight
- Gradient preservation using the measure of Maximum luminance difference between origin(o), sample(a), and the inverse of sample(a'), this idea based on a post by tritical. (http://forum.doom9.org/showthread.php?p=510605#post510605)
- It use a multiple pass/stacked filter and 5 texture fetch per pass, you could use as few as 3 pass to perform Local Contrast Enhancement.
- It use CIELab color space.
- Only tested on madVR.
sampler s0; float2 c1 : register(c1);
#define bsigma 0.050 // sigma for blurring, higher value means more blur thus higher contrast enhancement
//
#define dsigma 0.003 // sigma for denoising, set to 0(off) for a clean source
// value between 0.003-0.005 do a mild denoise while retaining most of the detail
#define offset 10.000 // sampling offset, adjust accordingly : 1st pass offset: n, 2nd pass offset n/2, 3rd pass offset n/4 ...
// e.g. :
// 21x21 kernel : 1st pass 10.0, 2nd pass 5.0, 3rd pass 2.5 , 4th pass 1.25(last pass might be unnecessary/not noticable)
// 81x81 kernel : 1st pass 40.0, 2nd pass 20.0, ............ , 6th pass 1.25(last pass might be unnecessary/not noticable)
/*
#define dlt(o,a,b) o-a // standard delta, luminance difference of: origin(o) and sample(a)
// does not preserve gradient
*/
#define dlt(o,a,b) max(o,max(a,b))-min(o,min(a,b)) // modified delta, maximum luminance difference of: origin(o), sample(a), inverse sample(b)
// preserve gradient
#define wi(d,s) exp( -(d*d) / (2*s*s))
#define Tx(x,y) tex2D(s0, tex + c1*float2(x,y))
#define Tx0 Tx(0,0)
#define pxo Tx(0,0).xw
static const float2 sigma = { bsigma, dsigma};
float4 main(float2 tex : TEXCOORD0) : COLOR {
float2 px[5+1],delta,coef,blur; int n; coef=blur=n=0;
px[1] = Tx(-offset, 0).xw;
px[2] = Tx( 0, offset).xw;
px[3] = Tx( 0.0, 0.0 ).xw;
px[4] = Tx( 0,-offset).xw;
px[5] = Tx( offset, 0).xw;
for (int i = 1; i <= 5; ++i) { n++;
delta = dlt(pxo,px[n],px[5+1-n]);
coef += wi(delta,sigma);
blur += px[n]*wi(delta,sigma); }
blur /= coef;
if (dsigma > 0.0)
return float4(blur.x,Tx0.yz,blur.y);
else
return float4(blur.x,Tx0.yzw);
}
Blur Comparison : Input (https://s10.postimg.io/mqm1qih49/S_00_input.png) | Exact Bilateral Filter (https://s3.postimg.io/5jlzk70mb/S_01_exact_CIE_Lab.png) | Shaders 3 pass (offset 10,5,2.5) sigma 0.03 (https://s14.postimg.io/bhzjq9mqp/S_02_Shaders_3_pass_sigma_0_030.png)
LCE Comparison : Input (https://s10.postimg.io/mqm1qih49/S_00_input.png) | Result (Shaders 3 pass (offset 10,5,2.5) sigma 0.03) (https://s16.postimg.io/6z584l9tx/S_03_Shaders_3_pass_sigma_0_030_Sharp.png)
LCE Comparison : samsung_opera_DWEU.mkv (https://s21.postimg.io/qmqu0b5ev/opera_in.png) | Result (Shaders 6 pass (offset 40,20,10,5,2.5,1.25) sigma 0.05, strength 1.2) (https://s3.postimg.io/l6d8xkeeb/opera_out.png)
Download (https://drive.google.com/file/d/0B0C7XTDhJ4MMWGNYQ3VGbFJfU1E/view)
- Installation -
Set as post-resize shader, in the following order:
FastLCE - RGB2Lab
FastLCE - Blur - Offset 10.00 (Larger offset first)
FastLCE - Blur - Offset 05.00
FastLCE - Blur - Offset 02.50
FastLCE - Contrast Enhancement
FastLCE - Lab2RGB
Disclaimer:I'm not a programmer by any means, so the above code may or may not work on your setup.
Use it only on HD and clean source cause it may increase noise/banding.