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 1st July 2013, 16:29   #1  |  Link
HappyLee
Registered User
 
Join Date: Mar 2013
Posts: 27
Correcting a video with huge contrast?

Hi. I'm dealing with a terrible source again, and this time it's the Bad Tour Wembley DVD of Michael Jackson (released in 2012). There are lots of problems with the "enhancing" job of the VHS tape, like over-sharpened, but the biggest problem is the contrast of the video was adjusted way large. It's too black on places that aren't supposed to be that black, especially with his eyes. Same problem with white areas but lighter compared to the black problem.

Here's a comparison. On the left is the video source I'm trying to improve, and on the right is the normal color.


Levels and Tweak won't make it look much better, because there are some places like the background that's truly supposed to be black, and they only makes the picture looks more grey.

My idea is to make gradual change of luma. Use Levels to make black parts not so black at first, detect dark areas and gradually make the middle part darker. For small black areas like his eyes, the gradual change won't make much different, but for large black areas like the background, it could make it's middle part darker like it's supposed to be. This, I think, could make the picture looks better in some degree.

But unfortunately I haven't found any filters doing that, and I'm not able to make my idea into script so far. So, could anyone here help me find a way to solve that problem? Thanks in advance!
HappyLee is offline   Reply With Quote
Old 1st July 2013, 19:17   #2  |  Link
Guest
Guest
 
Join Date: Jan 2002
Posts: 21,922
What is the source on the right that you call normal, and why don't you use that one?
Guest is offline   Reply With Quote
Old 1st July 2013, 19:22   #3  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,374
Looks like a job for SGradation (discussed here)
Code:
#    output luma with gamma < 1.0
#               ^
#            255+                           +
#               |                           +
#               |                          +
#               |                         +
#               |                       +
#               |                     +
#               |                  +
#            128+            +++
#               |        +
#               |     +
#               |   +
#               | +
#               |+
#               |+
#              0+-------------+-------------+> input luma
#               0            128           255

Last edited by raffriff42; 24th August 2013 at 22:37. Reason: link to updated SGradation entry
raffriff42 is offline   Reply With Quote
Old 1st July 2013, 22:09   #4  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 2,348
AVISynth and its plugins are a marvelous tool for many jobs, but if I were facing this problem, AVISynth would be the last thing I would think of using. In my video editing program (Vegas), I have a number of "plugins" that the program provides, including a histogram correction feature, similar to what "raffriff42" shows above. I'd use that, along with color correction, in order to match different scenes.
johnmeyer is offline   Reply With Quote
Old 1st July 2013, 22:21   #5  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 2,348
I did a screen grab of the "bad" still shot you posted, and then put that in my video editing program (Vegas). It took three plugins, adjusting the controls interactively using the real-time GUI feedback that any full-fledged editing program provides, but in the end I think I came up with something that is pretty close to matching the "good" still shot you posted above:



So, once again, try the controls in your video editing program and I think you'll get better results than anything you are likely to be able to do with AVISynth.
johnmeyer is offline   Reply With Quote
Old 1st July 2013, 23:00   #6  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,374
Meh, not great, but better than before. EDIT - agreed, a GUI would have been helpful.


Code:
#avisynth

C1=ImageSource("sgrad-test-1.jpg")
C1=C1.Crop(0, 0, 512, 384).ConvertToYV12()

## original image
#return C1

#@func SGradation2(clip clp, val "gammalite", val "gammadark")

## less midrange contrast
C2=C1.SGradation2(0.3, 0.3)

## more overall contrast
C2=C2.Levels(42, 1.0, 192, 16, 235)  

## stage one complete
#return C2

### optional ###

LoadModule("avslib", "filters", "channels") 

## clamp red, hackishly (EDIT: should have used Limiter)
V=C2.ShowV
V=V.Levels(0, 1.0, 160, 0, 255, coring=true) 
V=V.Levels(0, 1.0, 255, 0, 160) 

C3=MergeYUV(C2.ShowY, C2.ShowU, V)

## stage two complete
#return C3

### compare all ###

return StackVertical(
\              C1.Histogram(mode="levels").Subtitle("before"), 
\              C2.Histogram(mode="levels").Subtitle("SGrad+Levels"), 
\              C3.Histogram(mode="levels").Subtitle("clamp red"))

Last edited by raffriff42; 16th March 2017 at 14:41. Reason: (fixed image link)
raffriff42 is offline   Reply With Quote
Old 2nd July 2013, 03:22   #7  |  Link
HappyLee
Registered User
 
Join Date: Mar 2013
Posts: 27
Quote:
Originally Posted by neuron2 View Post
What is the source on the right that you call normal, and why don't you use that one?
It's not the same tape, not even the same show, just a comparison.

Quote:
Originally Posted by raffriff42 View Post
Looks like a job for SGradation (discussed here)
Yeah, you're right. SGradation really seems to be the answer.

Quote:
Originally Posted by raffriff42 View Post
Meh, not great, but better than before. EDIT - agreed, a GUI would have been helpful.
That looks much better. Thank you so much for it, and I'll try adjusting it with that method right away.
HappyLee is offline   Reply With Quote
Old 2nd July 2013, 15:02   #8  |  Link
HappyLee
Registered User
 
Join Date: Mar 2013
Posts: 27
SGradation works great, but this happens sometimes (on the right, where you can see the luma blocks):


What should I do? Is there a better way than MaskTools + MedianBlur, without ruining useful details? Or is there a smart luma smoother that can handle it (I tried SmoothHiQ but it doesn't work)?
HappyLee is offline   Reply With Quote
Old 2nd July 2013, 16:45   #9  |  Link
creaothceann
Registered User
 
Join Date: Jul 2010
Location: Germany
Posts: 360
Well, you could try the Dither functions.
creaothceann is offline   Reply With Quote
Old 3rd July 2013, 13:02   #10  |  Link
HappyLee
Registered User
 
Join Date: Mar 2013
Posts: 27
Quote:
Originally Posted by creaothceann View Post
Well, you could try the Dither functions.
I used GradFun3() but nothing I see is changed. I'm not doing it right am I?
Edit: Oh, sorry, should have increased the thr value.

Last edited by HappyLee; 3rd July 2013 at 13:49.
HappyLee is offline   Reply With Quote
Old 3rd July 2013, 23:14   #11  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,374
There is only so much that can be done. See the HDR AGC thread for a good discussion of the issues involved.

This call to HDRAGC
Code:
HDRAGC(max_gain=2.0, max_sat=1.0, black_clip=10.0)
looks pretty similar to
Code:
SGradation2(0.3, 0.55)
but one or the other may look better in the actual video.

Last edited by raffriff42; 3rd July 2013 at 23:32. Reason: sample code
raffriff42 is offline   Reply With Quote
Old 4th July 2013, 21:39   #12  |  Link
TheSkiller
Registered User
 
Join Date: Dec 2007
Location: Germany
Posts: 634
Quote:
Originally Posted by HappyLee View Post
I used GradFun3() but nothing I see is changed. I'm not doing it right am I?
You should try SmoothCurve() (part of SmoothAdjust) instead of trying to smooth out SGradation2() afterwards using GradFun3().

SmoothCurve() will give you plenty control. Make use of it's debug view show=true.
TheSkiller is offline   Reply With Quote
Old 5th July 2013, 00:45   #13  |  Link
Mug Funky
interlace this!
 
Mug Funky's Avatar
 
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,555
i'm going to post in defence of colourists everywhere and say perhaps the producers wanted it that way?

it's a bit heavy-handed i'll agree.

also, having graded live shows before, you can't be sure those two pics are even slightly comparable (his pose is identical, but he's perhaps the best dancer in the last century so that makes sense). if the flare abates for a few frames you'll find the black-level crashes through the floor...

with crushed blacks, there's no recovering them... best just let them go. personally i would never have smashed them that hard unless johnny-big-nuts-producer insisted and i wanted to placate him or shut him up...
__________________
sucking the life out of your videos since 2004
Mug Funky is offline   Reply With Quote
Old 5th July 2013, 03:32   #14  |  Link
HappyLee
Registered User
 
Join Date: Mar 2013
Posts: 27
Quote:
Originally Posted by TheSkiller View Post
You should try SmoothCurve() (part of SmoothAdjust) instead of trying to smooth out SGradation2() afterwards using GradFun3().

SmoothCurve() will give you plenty control. Make use of it's debug view show=true.
I tried to use SmoothLevels() instead of Levels() in the SGradation function, but I guess they can't replace each other. I don't really understand what SmoothLevels() and SmoothCurve() do. I tried SmoothCurve() after SGradation just now and I didn't see any difference. Could you teach me how to use it further? Thanks.
HappyLee is offline   Reply With Quote
Old 5th July 2013, 05:27   #15  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,374
SmoothAdjust is pretty neat. I found I could stretch the blacks to an extreme degree without banding or blotchiness.
Code:
#avisynth

C1=ImageSource("sgrad-test-2.jpg")
C1=C1.Crop(0, 128, 512, 256).ConvertToYV12()

## SGrad
C2=C1.SGradation2(0.6, 0.6)

## Smooth - moderate
#C3=C1.SmoothCurve(Ycurve="0-0;4-0;8-12;36-66;245-235;255-255", smooth=200, dither=100, show=false)
#C3=C3.SmoothLevels(23, 1.1, 255, 0, 255) 

## Smooth - extreme
C4=C1.SmoothCurve(Ycurve="0-0;4-0;8-26;36-66;245-235;255-255", smooth=200, dither=100, show=false)
C4=C4.SmoothLevels(30, 1.35, 255, 0, 255) 

S=StackVertical(
\         C4.Subtitle("Smooth"), 
\         C2.Subtitle("SGrad"))

## exaggerate the artifacts
return S.Levels(0, 1.9, 255, 0, 255)
Note the "exaggerate " line is just to show off the smoothing.

Agree w/ Mug Funky on the futility of trying to rescue this particular video, especially if the stage lights are constantly changing.


Last edited by raffriff42; 18th March 2017 at 01:40. Reason: (fixed image link)
raffriff42 is offline   Reply With Quote
Old 21st July 2013, 17:21   #16  |  Link
HappyLee
Registered User
 
Join Date: Mar 2013
Posts: 27
I improved SGradation with SmoothAdjust. Finally the color banding problem is solved. Here's my code for SGradation2S (S for smooth):
Code:
function SGradation2S(clip clp, val "gammaW", val "gammaB") {
	gW=float(default(gammaW,1.0))
	gB=float(default(gammaB,1.0))
	gc=clp.GreyScale()
 	dk=gc.SmoothLevels(16,1.0/gB,127,16,127,smooth=200,limiter=1)
	lt=gc.SmoothLevels(235,1.0/gW,128,107,0,smooth=200)
	r=Overlay(dk,lt,mode="add")
	r.MergeChroma(clp)
}

Last edited by HappyLee; 22nd July 2013 at 05:10.
HappyLee 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 04:41.


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