Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 25th April 2005, 22:11   #1  |  Link
paviko
Registered User
 
Join Date: Mar 2005
Location: Poland
Posts: 85
Hdr Agc 1.8.7 - 10.09.2006

HDR AGC version 1.8.7

More info and download at my homepage

-----
MODERATOR Note: This link is dead. Use this one:

https://web.archive.org/web/20131018...iko/hdragc.htm
-----

High Dynamic Range Automatic Gain Control - this plugin increase dynamic range of video clips (enhance shadows). It's "simply" gaining (brightening) dark areas of image without causing blow of highlights and is doing it by simulating the work of our eyes. Amount of gain is calculated automatically but you can also influence on it by parameters.

This plugin support YV12 and YUY2 color sprace.
Usage:
AVISource(...)
SeparateFields() # if content is interlaced
HDRAGC()
Weave() # if content is interlaced

MOST IMPORTANT PARAMETERS:
coef_gain (default 1.0) - increase parameter to get brighter image, decrease to limit auto brightening
coef_sat (1.0) - incerease to bring more saturation


TODO for 2.0 version
- MMX, SSE, SSE2 optimization


Tips:
1. I'd like to have brigther results.
Try increasing coef_gain and/or min_gain
2. Image lacks colours saturation after brightening
Try increasing coef_sat parameter
3. I would like to operate only in luma (without changing chrominance channels)
Set max_sat to 1.0
4. When I set coef_sat lower that 1.0, bright area of image are loosing saturation
Set min_sat to 1.0 (default value id 0.0)
5. Bright areas of image are too much gained
Try corrector parameter - recommended values are (0.8 - 1.0), the lower value then less gain is applied to brighter part of image
6. Gained parts have too much noise
Try increasing reducer parameter. Default value is 0.5, max is 2.0

Last edited by Guest; 23rd May 2014 at 15:38. Reason: New version
paviko is offline   Reply With Quote
Old 26th April 2005, 09:34   #2  |  Link
morsa
the dumbest
 
Join Date: Oct 2002
Location: Malvinas
Posts: 494
Wow. I always like this kind of things!!!!!
morsa is offline   Reply With Quote
Old 26th April 2005, 13:47   #3  |  Link
videoFred
Registered User
 
videoFred's Avatar
 
Join Date: Dec 2004
Location: Gent, Flanders, Belgium, Europe, Earth, Milky Way,Universe
Posts: 583
Congratulations!

This filter looks very, very promising.
Could this be a real auto-levels filter at last?
Is it possible to add an auto-gamma setting too?

Fred.
videoFred is offline   Reply With Quote
Old 26th April 2005, 16:53   #4  |  Link
Mug Funky
interlace this!
 
Mug Funky's Avatar
 
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,547
kickass! this could really help with the Zion scenes in the matrix trilogy (baaad lighting ratio right thurr).

not sure if it'll help on some grainy-as-hell and dark DV footage i have, but i don't expect anything to save that.

i think i'll wait for some optimization - i'm running a 5 year old machine, so every cycle is sacred.

[edit] i can see this becoming very useful for avisynth 3, if it ends up supporting 16bpc video - HDR is best suited to more-than-8-bits.

hehe. i'm a bit of an HDR fan - i've even got one of those mirror-ball light-probe things, though i hardly use it anymore (it's warped at the seam...).
__________________
sucking the life out of your videos since 2004

Last edited by Mug Funky; 26th April 2005 at 16:56.
Mug Funky is offline   Reply With Quote
Old 26th April 2005, 17:58   #5  |  Link
paviko
Registered User
 
Join Date: Mar 2005
Location: Poland
Posts: 85
@videoFred
Quote:
Is it possible to add an auto-gamma setting too?
Why would you like to auto control gamma?
Gamma is causing some contrast loss, that's why HDR technics were invented to overcome this.
But maybe it can be usefull. Could you describe in more detail how you imagine the gamma control? Of course the best would be image examples showing diffrent situations

@Mug Funky
Quote:
this could really help with the Zion scenes in the matrix trilogy (baaad lighting ratio right thurr)
This plugin works best with low compressed input like DV stream, where lots of details are preserved in dark areas. I don't know if MPEG2 isn't too lossly compression (depends on how the film was compressed). The more compressed input then less gain would be possible without artefacts.

Quote:
not sure if it'll help on some grainy-as-hell and dark DV footage i have
I've done this plugin for my home DV shoots (birthdays, etc.) Of course without good denoiser (fortunately we've got here the best ones: MVTools, FFT3D) we can't do much. But today mainstream camcorders (eg. Pana GS-120, Sony HC-85, Canon Optura) easily handle gain as much as 3.0 times.
Those examples posted by me are from Panasonic GS200, Sony PC350 and Sony PC85.

Quote:
i can see this becoming very useful for avisynth 3, if it ends up supporting 16bpc video - HDR is best suited to more-than-8-bits.
Yes but when we will be able to touch devices recording in 16-bit format

Regards
paviko is offline   Reply With Quote
Old 27th April 2005, 04:05   #6  |  Link
Backwoods
ReMember
 
Backwoods's Avatar
 
Join Date: Nov 2003
Posts: 416


HDRAGC(max_gain=1.5)

Awesome filter.
Backwoods is offline   Reply With Quote
Old 27th April 2005, 06:18   #7  |  Link
AVIL
Registered User
 
Join Date: Nov 2004
Location: Spain
Posts: 400
Felicitations. This is an superb filter.

I've done a benchmark with virtualdub's filter "MSU Smart Brightness & Contrast" and the result is favourable to your filter. Your image has no halos, better contrast and less pixelation in dark areas.

Only one doubt. I've tried with different values (from 16 to 255) for avg_lum but with no visual changes at all. ¿Do this parameter depend on others?

I often process VHS captures (YUY2 colorspace). I can accept promote to RGB. The return to YUY2 is almost lossless. The return from YV12 isn`t lossless. Despite the evolution to YV12 ¿It will be possible to preserve RGB processing in future releases?.

Thanks.
AVIL is offline   Reply With Quote
Old 27th April 2005, 07:24   #8  |  Link
videoFred
Registered User
 
videoFred's Avatar
 
Join Date: Dec 2004
Location: Gent, Flanders, Belgium, Europe, Earth, Milky Way,Universe
Posts: 583
Quote:
Originally posted by paviko
@videoFred

Why would you like to auto control gamma?
Gamma is causing some contrast loss, that's why HDR technics were invented to overcome this.
But maybe it can be usefull. Could you describe in more detail how you imagine the gamma control? Of course the best would be image examples showing diffrent situations

I did a very first test on some very dark files and the result was even better if I increased the gamma with VDub. But this was a very first and promising test on some divX files. At home, I have tons of huge 1024x768 Huffyuv files, and a fast computer. I do some more testing, and report the results here, but I need at least a week for this.

Fred.
videoFred is offline   Reply With Quote
Old 27th April 2005, 14:14   #9  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,390
paviko, this is very nice work. A little sluggish , but results are really impressing!

It reminded me of the fact that in one of my postponed scripting projects, there is some code gathering dust for half a year now, that tries to do something rather similar. (Namely: the "contrast booster" feature of "LimitedSharpen-EX".)

The principle of operation is less sophisticated and precise (general limitations of AviSynth scripting). In exchange, it runs somewhat faster than HDRAGC() ... 10 times, or more.

Result when feeding the "lowlight" JPEG from above as input, via imagereader:



If someone is interested in the (unfinished) AVS code, drop a line here. Basically, an ultra-wide gaussian blur is done, then the difference to the original is square-rooted, and fed into a modified multiplication/hardlight routine.

(Should I think about writing PDF whitepapers ...)
__________________
- We´re at the beginning of the end of mankind´s childhood -

My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!)
Didée is offline   Reply With Quote
Old 27th April 2005, 14:48   #10  |  Link
joshbm
Registered User
 
joshbm's Avatar
 
Join Date: Jun 2003
Location: Land of the Noobs & the Home of the Brave
Posts: 349
Didee I am interested. I am also interested in LimitedSharpen-EX ;-).
__________________
Tired of waiting for video encodes? Get a totally new P4 Desktop Computer for FREE.
joshbm is offline   Reply With Quote
Old 27th April 2005, 18:12   #11  |  Link
paviko
Registered User
 
Join Date: Mar 2005
Location: Poland
Posts: 85
Thank you all for your replies.

@AVIL
Quote:
Only one doubt. I've tried with different values (from 16 to 255) for avg_lum but with no visual changes at all. ¿Do this parameter depend on others?
Thank you for reporting this. It's a bug, avg_lum parameter is partially reversed in code now, so it's definitaly not working as it's supossed to work.
Quote:
¿It will be possible to preserve RGB processing in future releases?.
RGB32 will be always supported in this plug-in. Gaining in RGB space is not causing loss of saturation. I haven't tried yet solving equation for YUV colour format, so I don't know if the plug-in will work the same in YUV, but it will be faster. It's also possible that YUY2 version will be added too.

@videoFred
Thanks, waiting for your reports

@Didée
Quote:
it runs somewhat faster than HDRAGC() ... 10 times, or more
I'm planning to optimize these filter, don't know exactly how much faster it will run. Probably the ultra-wide gaussian you are using is highly optimized by avisynth developer team. In my plug-in the most computational task is calculating average brigthness with inclusion of simulating human eye reaction (should I believe what is written in this article ? ) - it's like reading one frame of video 150 times.
Quote:
If someone is interested in the (unfinished) AVS code, drop a line here. Basically, an ultra-wide gaussian blur is done, then the difference to the original is square-rooted, and fed into a modified multiplication/hardlight routine.
Yes please post it Didée, I'm especially interested in your "modified multiplication/hardlight routine"
Quote:
Should I think about writing PDF whitepapers ...
Definately yes

Regards
paviko is offline   Reply With Quote
Old 28th April 2005, 00:15   #12  |  Link
tsp
Registered User
 
tsp's Avatar
 
Join Date: Aug 2004
Location: Denmark
Posts: 807
paviko: I took a look at you code and did a little profiling on it. it seems if it's this loop that's taking about 75% of the time:
Code:
for (h=0; h < src_height;h++) {       // Loop from bottom line to top line.
			for (w = 0; w < src_width/4; w++) {	// and from leftmost pixel to rightmost one. 
				int miny = h - circle;
				if (miny < 0)
					miny = 0;
				int maxy = h + circle;
				if (maxy > src_height - 1)
					maxy = src_height - 1;
				int minx = w - circle;
				if (minx < 0)
					minx = 0;
				int maxx = w + circle;
				if (maxx > src_width / 4 - 1)
					maxx = src_width / 4 - 1;
				y_local[h][w] = 0.0f;
				float w_sum = 0.0f;
				for (int y = miny; y <= maxy; y++)
					for (int x = minx; x <= maxx; x++){
						if (circleMat[w - x + circle][h - y + circle]){
							float weight = weights[y_lum[y][x]][y_lum[h][w]];
							w_sum += weight;
							y_local[h][w] += weight * y_lum[y][x];
						}
					}
				y_local[h][w] /= w_sum;
			}
		}
I changed it to this and gained about 25% speed increase:
Code:
		for (h=0; h < src_height;h++) {       // Loop from bottom line to top line.
			int miny = h - circle;
			if (miny < 0)
				miny = 0;
			int maxy = h + circle;
			if (maxy > src_height - 1)
				maxy = src_height - 1;

			for (w = 0; w < src_width/4; w++) {	// and from leftmost pixel to rightmost one. 

				int minx = w - circle;
				if (minx < 0)
					minx = 0;
				int maxx = w + circle;
				if (maxx > src_width / 4 - 1)
					maxx = src_width / 4 - 1;
				//y_local[h][w] = 0.0f;
				float y_local_h_w=0.0f;
				float w_sum = 0.0f;
				int y_lum_hw=y_lum[h][w];
				for (int y = miny; y <= maxy; y++)
					for (int x = minx; x <= maxx; x++){
						if (circleMat[w - x + circle][h - y + circle]){
							int y_lum_xy=y_lum[y][x];
							float weight = weights[y_lum_xy][y_lum_hw];
							
							w_sum += weight;
							y_local_h_w += weight * y_lum_xy;
							
						}
					}
				y_local[h][w] = y_local_h_w/w_sum;
			}
		}
Else a very nice filter.

Last edited by tsp; 28th April 2005 at 15:41.
tsp is offline   Reply With Quote
Old 28th April 2005, 04:43   #13  |  Link
Yuri
Registered User
 
Join Date: Aug 2003
Posts: 55
Unfortunately, I only get a green screen when I load this filter through VDub. Why so? What am I doing wrong?
Yuri is offline   Reply With Quote
Old 28th April 2005, 05:23   #14  |  Link
Backwoods
ReMember
 
Backwoods's Avatar
 
Join Date: Nov 2003
Posts: 416
Do you have "ConvertToRGB32()" before the filter's functions?
Backwoods is offline   Reply With Quote
Old 28th April 2005, 14:51   #15  |  Link
Yuri
Registered User
 
Join Date: Aug 2003
Posts: 55
Now it works!
Thank you, Backwoods.
Yuri is offline   Reply With Quote
Old 28th April 2005, 18:33   #16  |  Link
Bordo32
Registered User
 
Join Date: Jan 2003
Posts: 31
@paviko, very nice and promising filter

Just a thought, if by using AVISource(...) DV codec opens avi file in YUY2 space, the next line ConvertToRGB32() will expand luma from 16-235 range to 0-255. All details below 16 and above 235 will be lost. We know that most of miniDV cams have overshoots in luma up to 255.
Would it be better use:
ConvertToRGB(matrix="PC.601") and have a full luma range?

It might be stupid question, but I am just curious, is this filter is interlaced aware, does not require those SeparateFields() Weave() type of things?

Last edited by Bordo32; 28th April 2005 at 18:44.
Bordo32 is offline   Reply With Quote
Old 28th April 2005, 19:34   #17  |  Link
Wilbert
Moderator
 
Join Date: Nov 2001
Location: Netherlands
Posts: 6,294
Quote:
Would it be better use:
ConvertToRGB(matrix="PC.601") and have a full luma range?
Yes, you can try that. Best is to compare both and see what you like best.

Quote:
It might be stupid question, but I am just curious, is this filter is interlaced aware, does not require those SeparateFields() Weave() type of things?
Nope, because the avi is opened as YUY2 (you only need it if source or target is YV12).
Wilbert is offline   Reply With Quote
Old 28th April 2005, 22:19   #18  |  Link
paviko
Registered User
 
Join Date: Mar 2005
Location: Poland
Posts: 85
@backwoods
I've looked closer to your frame grab and I'd like to have you camcorder It's perfectly keeping colour information in dark areas. Is it a professional camcorder? The best result with such a good devices can be obtained when max_sat parameter is set to 1.0. Otherwise colours can be boosted too much.

@tsp
Thank you very much for your help, it definately should be like you posted.

@Bordo32
Quote:
the next line ConvertToRGB32() will expand luma from 16-235 range to 0-255
I've never thought about this, because I've instaled DV codec that is using 0-255 range. I think that ConvertToRBG will leave 16-235 range unchanged but not sure and for now can't check it. Of course you should listen to Wilbert
Thanks for pointing it, I'll addres the issue with the range 16-235 when YUY2 support will be added.
Quote:
It might be stupid question, but I am just curious, is this filter is interlaced aware, does not require those SeparateFields() Weave() type of things?
It's your second perfect question. It's best to do separatefields() and then weave() for interlaced. But also without it only in special cases some artefact can appear. Maybe it's good to add interlaced mode to filter, or do you prefer doing it yourself with separatefields() and weave() ?

Regards
paviko is offline   Reply With Quote
Old 29th April 2005, 00:22   #19  |  Link
Backwoods
ReMember
 
Backwoods's Avatar
 
Join Date: Nov 2003
Posts: 416
Quote:
Originally posted by paviko
@backwoods
I've looked closer to your frame grab and I'd like to have you camcorder It's perfectly keeping colour information in dark areas. Is it a professional camcorder? The best result with such a good devices can be obtained when max_sat parameter is set to 1.0. Otherwise colours can be boosted too much.
Ah yes, I didn't notice that max_sat was 2.0 by default. Putting it around 1.5/6 gives a nice result. And the camera I was using is a Sony HDR-FX1, nice camera.


Quote:
It's your second perfect question. It's best to do separatefields() and then weave() for interlaced. But also without it only in special cases some artefact can appear. Maybe it's good to add interlaced mode to filter, or do you prefer doing it yourself with separatefields() and weave() ?
I would just put a note in saying to use SeparateFields() and Weave() for interlaced people. Considering those people are going to be doing other effects also, which should be done inbetween S() and W(). Unless it's easy enough to code interlaced material handling.
Backwoods is offline   Reply With Quote
Old 29th April 2005, 09:24   #20  |  Link
Wilbert
Moderator
 
Join Date: Nov 2001
Location: Netherlands
Posts: 6,294
Quote:
Quote:
It might be stupid question, but I am just curious, is this filter is interlaced aware, does not require those SeparateFields() Weave() type of things?
Nope, because the avi is opened as YUY2 (you only need it if source or target is YV12).
Oops I completely misunderstood your question.
Wilbert is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:10.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2017, vBulletin Solutions Inc.