Page 8 of 24

Re: HDR -> SDR tonemapping

Posted: Mon Mar 26, 2018 1:32 pm
by admin
Sweet! Thanks DJ. :salute:

Re: HDR -> SDR tonemapping

Posted: Mon Mar 26, 2018 1:33 pm
by DJATOM
Also checked without up-conversion to 16 bits, that works as intended.

Code: Select all

LwlibavVideoSource("D:\ACCEL_WORLD_INFINITE_BURST_UHD\BDMV\STREAM\00004.m2ts")
ConvertFromDoubleWidth(bits=10)
z_ConvertFormat(pixel_type="RGBPS",colorspace_op="2020ncl:st2084:2020:l=>rgb:linear:2020:l", dither_type="none")
DGReinhard(contrast=0.55, bright=2.35)
z_ConvertFormat(pixel_type="YV12",colorspace_op="rgb:linear:2020:l=>709:709:709:l",dither_type="ordered")

Re: HDR -> SDR tonemapping

Posted: Mon Mar 26, 2018 3:53 pm
by Guest
In approximately two hours I will be able to post some comparative images of both filters versus sdr sample

Re: HDR -> SDR tonemapping

Posted: Mon Mar 26, 2018 6:37 pm
by Guest
New comparisons
Note
DGHable and DGReinhard at default
HDR clip was not not resized to 1080p
sdr 1
sdr 1.jpg
DGHable 1
DGHable 1.jpg
DGReinhard 1
DGReinhard 1.jpg

Re: HDR -> SDR tonemapping

Posted: Mon Mar 26, 2018 6:38 pm
by Guest
sample 2
sdr
sdr 2.jpg
DGHable
DGHable 2.jpg
DGReinhard
DGReinhard 2.jpg

Re: HDR -> SDR tonemapping

Posted: Mon Mar 26, 2018 6:39 pm
by Guest
sample 3
sdr
sdr 3.jpg
DGHable
DGHable 3.jpg
DGReinhard
DGReinhard 3.jpg

Re: HDR -> SDR tonemapping

Posted: Mon Mar 26, 2018 6:41 pm
by Guest
sample 4
sdr
sdr 4.jpg
DGHable
DGHable 4.jpg
DGReinhard
DGReinhard 4.jpg

Re: HDR -> SDR tonemapping

Posted: Mon Mar 26, 2018 7:39 pm
by admin
Thank you, gonca. Great variety of scene types. :salute:

Maybe Hable needs to come down a notch in exposure to 2.0. Both operators work acceptably. I'm not sure which I prefer.

Re: HDR -> SDR tonemapping

Posted: Mon Mar 26, 2018 7:52 pm
by Guest
It might be a relevant point that those images are in jpg format, forum doesn't allow bmp

Re: HDR -> SDR tonemapping

Posted: Mon Mar 26, 2018 7:55 pm
by Narkyy
I think default settings really don't do it justice. SDR is first.
Settings I used (adjusted for other scenes too): exposure=1.6, b=0.40, c=0.11, d=0.30, e=0.019, w=20
I prefer Hable because it's more flexible, while Reinhard only has contrast/white adjustments.

01.png
02.png
03.png

Re: HDR -> SDR tonemapping

Posted: Mon Mar 26, 2018 8:02 pm
by admin
gonca wrote:
Mon Mar 26, 2018 7:52 pm
It might be a relevant point that those images are in jpg format, forum doesn't allow bmp
I added BMP to the allowed extensions.

Re: HDR -> SDR tonemapping

Posted: Mon Mar 26, 2018 8:03 pm
by admin
Narkyy wrote:
Mon Mar 26, 2018 7:55 pm
I think default settings really don't do it justice.
Thanks for the testing and yes, I agree Hable needs a smaller default exposure.

Re: HDR -> SDR tonemapping

Posted: Mon Mar 26, 2018 8:05 pm
by dmcs
I feel like without an HDR monitor as a reference, every setting would be a guess-timate. Trying to pick the right setting is quite a challenge. :D

Re: HDR -> SDR tonemapping

Posted: Mon Mar 26, 2018 8:25 pm
by Guest
I have a HDR TV being used as a monitor
The problem is that I can't capture a picture from the UHD source while retaining the HDR, metadata, of the original to post
I can compare by playing the clips but then no one else sees them

Re: HDR -> SDR tonemapping

Posted: Mon Mar 26, 2018 11:02 pm
by Dion
dmcs wrote:
Mon Mar 26, 2018 8:05 pm
I feel like without an HDR monitor as a reference, every setting would be a guess-timate. Trying to pick the right setting is quite a challenge. :D
HDR color mapping is set by the user.. and in the case of Monitor / TV's the manufacturer LG, Sony & Samsung etc..

So there is no correct way.. It's all your way.

Re: HDR -> SDR tonemapping

Posted: Sun Apr 01, 2018 6:41 am
by Selur
Small note about nvhsp: It only patches the first header and is only meant for the output of nvencc, but is not really needed nowadays since nvencc itself supports hdr related signaling.

@admin: Are you planning to port DGTonemap to Vapoursynth? (I'd like a gpu based alternative to tonemap)

Cu Selur

Re: HDR -> SDR tonemapping

Posted: Sun Apr 01, 2018 6:48 am
by Guest
NVEncC does accept the HDR signalling through the command line since a few versions ago.
Both work, so they are both good, depending on workflow

Re: HDR -> SDR tonemapping

Posted: Sun Apr 01, 2018 7:40 am
by admin
Thanks for the useful info, guys.
Selur wrote:
Sun Apr 01, 2018 6:41 am
Are you planning to port DGTonemap to Vapoursynth? (I'd like a gpu based alternative to tonemap)
Yes, I will. And I'm depackaging filters so they can be open-sourced. Only DGSource() will remain closed.

Re: HDR -> SDR tonemapping

Posted: Sun Apr 01, 2018 10:21 pm
by Nginx
admin wrote:
Sun Apr 01, 2018 7:40 am
Thanks for the useful info, guys.
Selur wrote:
Sun Apr 01, 2018 6:41 am
Are you planning to port DGTonemap to Vapoursynth? (I'd like a gpu based alternative to tonemap)
Yes, I will. And I'm depackaging filters so they can be open-sourced. Only DGSource() will remain closed.
Sounds real great. :hat:

Re: HDR -> SDR tonemapping

Posted: Mon Apr 02, 2018 11:00 am
by admin
Ready for a splash of ice water in the face, guys? I already took one. :(

Here's the deal. A CUDA version of DGTonemap is currently useless, for two reasons: a) the overhead of transferring three (R, G, B) float images to/from the GPU makes the CUDA version perform worse than simply doing things in SW with a decent prefetch, and b) the overall time is heavily dominated by the SW conversions, so that even if the tonemapping part performed better with CUDA, it would have little overall effect.

So, what is the morale of this story? Everything has to be done on the GPU, i.e, ship up one 16-bit frame, convert to 709 and tonemap, and ship back the frame. Then we could expect a large speedup. Got my work cut out for me. :scratch:

Re: HDR -> SDR tonemapping

Posted: Mon Apr 02, 2018 11:20 am
by Guest
Ready for a splash of ice water in the face, guys? I already took one. :(
Don't go swimming in Lake Erie yet ;)
As for the rest, if anyone can do it you can
Don't forget your paper reviews, or to relax every so often.
The software version already gives us a good solution

Re: HDR -> SDR tonemapping

Posted: Mon Apr 02, 2018 11:52 am
by admin
Reviews are done, but I'm going to take your advice to relax. :lol:

Re: HDR -> SDR tonemapping

Posted: Wed Apr 04, 2018 4:54 am
by hydra3333
8-)

Re: HDR -> SDR tonemapping

Posted: Fri Apr 13, 2018 4:08 pm
by dmcs
I have a question. In the DGTonemap's manual, the formula for Hable is

Code: Select all

hable(x) = ((x*(a*x+c*b)+d*e) / (x*(a*x+b)+d*f)) - e/f
Can you tell me what the "x" variable means? Thank you.

Re: HDR -> SDR tonemapping

Posted: Fri Apr 13, 2018 4:19 pm
by admin
It's easiest just to give you the code.

Code: Select all

#include "windows.h"
#include "avisynth.h"
#include "stdio.h"

class DGReinhard : public GenericVideoFilter
{
	float contrast;
	float bright;

public:
	DGReinhard(PClip _child, float _contrast, float _bright, IScriptEnvironment* env) : GenericVideoFilter(_child)
	{
		if (vi.pixel_type != VideoInfo::CS_RGBPS)
		{
			env->ThrowError("DGReinhard: input must be CS_RGBPS");
		}
		contrast = _contrast;
		bright = _bright;
	}
    PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);
};

PVideoFrame __stdcall DGReinhard::GetFrame(int n, IScriptEnvironment* env)
{
    PVideoFrame src = child->GetFrame(n, env);
	PVideoFrame dst = env->NewVideoFrame(vi);

	float *srcpR, *srcpG, *srcpB;
	float *dstpR, *dstpG, *dstpB;

	const int src_pitch = src->GetPitch(PLANAR_R) / 4;
	const int dst_pitch = dst->GetPitch(PLANAR_R) / 4;
	const int row_size = dst->GetRowSize(PLANAR_R);
	const int width = vi.width;
	const int height = dst->GetHeight(PLANAR_R);

	const float offset = (1.0f - contrast) / contrast;
	const float factor = (bright + offset) / bright;

	srcpR = (float *)src->GetReadPtr(PLANAR_R);
	dstpR = (float *)dst->GetWritePtr(PLANAR_R);
	srcpG = (float *)src->GetReadPtr(PLANAR_G);
	dstpG = (float *)dst->GetWritePtr(PLANAR_G);
	srcpB = (float *)src->GetReadPtr(PLANAR_B);
	dstpB = (float *)dst->GetWritePtr(PLANAR_B);
	for (int y = 0; y < height; y++)
	{
		for (int x = 0; x < width; x++)
		{
			dstpR[x] = srcpR[x] / (srcpR[x] + offset) * factor;
			dstpG[x] = srcpG[x] / (srcpG[x] + offset) * factor;
			dstpB[x] = srcpB[x] / (srcpB[x] + offset) * factor;
		}
		srcpR += src_pitch;
		srcpG += src_pitch;
		srcpB += src_pitch;
		dstpR += dst_pitch;
		dstpG += dst_pitch;
		dstpB += dst_pitch;
	}

	return dst;
}

class DGHable : public GenericVideoFilter
{
	float exposure, a, b, c, d, e, f, w;

public:
	DGHable(PClip _child, float _exposure,
		float _a,
		float _b,
		float _c,
		float _d,
		float _e,
		float _f,
		float _w,
		IScriptEnvironment* env) : GenericVideoFilter(_child)
	{
		if (vi.pixel_type != VideoInfo::CS_RGBPS)
		{
			env->ThrowError("DGHable: input must be CS_RGBPS");
		}
		exposure = _exposure;
		a = _a;
		b = _b;
		c = _c;
		d = _d;
		e = _e;
		f = _f;
		w = _w;
	}

	float hable(float in)
	{
		return (in * (in * a + b * c) + d * e) / (in * (in * a + b) + d * f) - e / f;
	}

	PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);
};

PVideoFrame __stdcall DGHable::GetFrame(int n, IScriptEnvironment* env)
{
	PVideoFrame src = child->GetFrame(n, env);
	PVideoFrame dst = env->NewVideoFrame(vi);

	float *srcpR, *srcpG, *srcpB;
	float *dstpR, *dstpG, *dstpB;

	const int src_pitch = src->GetPitch(PLANAR_R) / 4;
	const int dst_pitch = dst->GetPitch(PLANAR_R) / 4;
	const int row_size = dst->GetRowSize(PLANAR_R);
	const int width = vi.width;
	const int height = dst->GetHeight(PLANAR_R);

	srcpR = (float *)src->GetReadPtr(PLANAR_R);
	dstpR = (float *)dst->GetWritePtr(PLANAR_R);
	srcpG = (float *)src->GetReadPtr(PLANAR_G);
	dstpG = (float *)dst->GetWritePtr(PLANAR_G);
	srcpB = (float *)src->GetReadPtr(PLANAR_B);
	dstpB = (float *)dst->GetWritePtr(PLANAR_B);

	float whitescale = 1.0f / hable(w);

	for (int y = 0; y < height; y++)
	{
		for (int x = 0; x < width; x++)
		{
			dstpR[x] = hable(exposure * srcpR[x]) * whitescale;
			dstpG[x] = hable(exposure * srcpG[x]) * whitescale;
			dstpB[x] = hable(exposure * srcpB[x]) * whitescale;
		}
		srcpR += src_pitch;
		srcpG += src_pitch;
		srcpB += src_pitch;
		dstpR += dst_pitch;
		dstpG += dst_pitch;
		dstpB += dst_pitch;
	}

	return dst;
}

AVSValue __cdecl Create_DGReinhard(AVSValue args, void* user_data, IScriptEnvironment* env)
{
	return new DGReinhard(args[0].AsClip(),
		(float)args[1].AsFloat(0.3f),
		(float)args[2].AsFloat(5.0f),
		env);
}

AVSValue __cdecl Create_DGHable(AVSValue args, void* user_data, IScriptEnvironment* env)
{
	return new DGHable(args[0].AsClip(),
		(float)args[1].AsFloat(2.0f),
		(float)args[2].AsFloat(0.15f),
		(float)args[3].AsFloat(0.50f),
		(float)args[4].AsFloat(0.10f),
		(float)args[5].AsFloat(0.20f),
		(float)args[6].AsFloat(0.02f),
		(float)args[7].AsFloat(0.30f),
		(float)args[8].AsFloat(11.20f),
		env);
}

const AVS_Linkage *AVS_linkage = 0;
extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit3(IScriptEnvironment* env, AVS_Linkage* vectors)
{
	AVS_linkage = vectors;
	env->AddFunction("DGReinhard", "c[contrast]f[bright]f", Create_DGReinhard, 0);
	env->AddFunction("DGHable", "c[exposure]f[a]f[b]f[c]f[d]f[e]f[f]f[w]f", Create_DGHable, 0);
	return 0;
}