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 28th June 2014, 22:18   #1  |  Link
franketto
Registered User
 
Join Date: May 2014
Posts: 60
very bad chroma artefact on poor video

I have a very old clip that has a very bad chroma artefact (I don't know how to name it).

https://www.sendspace.com/file/7o757g

What can be done to make it better?
franketto is offline   Reply With Quote
Old 28th June 2014, 23:04   #2  |  Link
ChiDragon
Registered User
 
ChiDragon's Avatar
 
Join Date: Sep 2005
Location: Vancouver
Posts: 610
The chroma is flickering between two very different hues, back and forth, 25 times per second. Half of the frames are purple-tinted and the other half are green-tinted.

If the entire clip has this little motion, you can simply throw away half of the chroma frames and duplicate the others, such that chroma is now running at 12.5 fps. Like this:

Code:
AVISource("videoExample_BADChroma.avi")

Even = SelectEven()
Odd  = SelectOdd()

Even = MergeChroma(Even,Odd)

Interleave(Even,Odd)
Or you can try to actually correct the colors. I'm not very good at this so there is still some noticeable flicker:

Code:
AVISource("videoExample_BADChroma.avi")

Even = SelectEven().Tweak(hue=50,sat=0.7,coring=false)
Odd  = SelectOdd().Tweak(hue=-5,sat=0.9,coring=false)

Interleave(Even,Odd)
ChiDragon is offline   Reply With Quote
Old 29th June 2014, 01:37   #3  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,377
I like the first idea, it's nice and simple. But here's @LemMotlow's post with a more advanced solution if it's needed:
http://forum.doom9.org/showthread.ph...22#post1641322
raffriff42 is offline   Reply With Quote
Old 29th June 2014, 14:09   #4  |  Link
franketto
Registered User
 
Join Date: May 2014
Posts: 60
Ok, now I see some hope to restore it.

But the first approach doesn't work for all the clip, as from some frames on, it has this repeating pattern:
(Assuming r=reddish frame, y=yellowish frame)
ryrrryryyyryrrry

So the result of mergechroma at some point is 2r8y frames.

Also the second approach with colourlike has the same problem of 1y4r frames.

The ideal should be analyze each field and determine if hue is in range yellowish --> correct the hue, else is reddish --> so correct in other way, then interleave.

EDIT: maybe I must tweak a bit more the colourlike settings, but I'm no expert at all in this hue thing... is there some tut/guide to correct yellowish/reddish?
EDIT2: corrected pattern

Last edited by franketto; 29th June 2014 at 21:19.
franketto is offline   Reply With Quote
Old 29th June 2014, 19:14   #5  |  Link
ChiDragon
Registered User
 
ChiDragon's Avatar
 
Join Date: Sep 2005
Location: Vancouver
Posts: 610
If the pattern you described repeats for the rest of the clip, you can just use Trim at the point it starts and then SelectEvery in order to pick out and group them.
ChiDragon is offline   Reply With Quote
Old 29th June 2014, 21:48   #6  |  Link
franketto
Registered User
 
Join Date: May 2014
Posts: 60
As never said... I discovered the pattern changes...

So, I think the only way is to detect if frame is greenish or purplish and make different hue adjustments.

I'll have no time to test in the next 2 weeks, so I'll return to discuss later. Thank you.

Last edited by franketto; 29th June 2014 at 21:50.
franketto is offline   Reply With Quote
Old 29th June 2014, 22:04   #7  |  Link
franketto
Registered User
 
Join Date: May 2014
Posts: 60
I did it!

Code:
v0 = Avisource(...avi)
return ConditionalFilter(v0, v0.subtitle("purplish"), v0.subtitle("greenish"), "AverageChromaU()", ">", "115")
Now I will have to tweak the hue, but next weeks...
franketto is offline   Reply With Quote
Old 30th June 2014, 03:56   #8  |  Link
LemMotlow
Registered User
 
Join Date: Jul 2011
Location: Tennessee, USA
Posts: 235
Quote:
Originally Posted by franketto View Post
But the first approach doesn't work for all the clip, as from some frames on, it has this repeating pattern:
(Assuming r=reddish frame, y=yellowish frame)
ryrrryryyyryrrry
to me, that pattern looks like telecined video that has been improperly deinterlaced instead of inverse-telecined. I do not know why people insist on deinterlacing everything in sight -- especially film-source video that isn't interlaced to begin with.
LemMotlow is offline   Reply With Quote
Old 13th July 2014, 16:01   #9  |  Link
franketto
Registered User
 
Join Date: May 2014
Posts: 60
I'm here.

I tried this script:
Code:
ConditionalFilter(v0, purplish(v0,-25) , greenish(v0,35), "AverageChromaU()", ">", "116.5")

function purplish(clip c, int value){
# c = c.ScriptClip("""subtitle("purplish  " + String(AverageChromaU) )""").subtitle(string(value),200 )
c.Tweak(hue= value,sat=1.1,coring=false)
ColorYUV(Autowhite=true)
WriteHistogram("E:\test\p_hist.txt",1)
}

function greenish(clip c, int value){
# c = c.ScriptClip("""subtitle("greenish  " + String(AverageChromaU) )""").subtitle(string(value),200 )
c.Tweak(hue= value,sat=0.9,coring=false)
ColorYUV(Autowhite=true)
WriteHistogram("E:\test\g_hist.txt",1)
}

return colourlike("E:\test\p_hist.txt", "E:\test\g_hist.txt")

It's a lot better than original, but there are still some chroma issues like green "splashes" in the image (fixed at left+top and also around the pic):
https://www.mediafire.com/?nclxpb48tpfml8c

Could they be removed?

EDIT:
I added a clip with subtitles overimpressed to detect which was original purplish/greenish frames:
https://www.mediafire.com/?g3ydgcq7r30w7ug

Last edited by franketto; 13th July 2014 at 16:21.
franketto is offline   Reply With Quote
Old 13th July 2014, 16:05   #10  |  Link
franketto
Registered User
 
Join Date: May 2014
Posts: 60
Quote:
Originally Posted by LemMotlow View Post
to me, that pattern looks like telecined video that has been improperly deinterlaced instead of inverse-telecined.
I don't know, but it seems strange: that clip was recorded in a Pal country. So I think it shouldn't be telecined @29,97, but left at 25f.
franketto is offline   Reply With Quote
Old 13th July 2014, 16:42   #11  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 3,414
Another method is to smooth out the fluctuations using a temporal smoother on the u, v channels. Works ok on a static "talking heads" scene like your sample - but in a clip with lots of motion, you might get chroma ghosting artifacts

Code:
main=AVISource("videoExample_BADChroma.avi")
u=main.utoy().ttempsmooth(maxr=3, lthresh=200, strength=8)
v=main.vtoy().ttempsmooth(maxr=3, lthresh=200, strength=8)
ytouv(u,v)
mergeluma(main)

EDIT: oops, I missed that temporalsoften was suggested in that other thread

Last edited by poisondeathray; 13th July 2014 at 16:54.
poisondeathray is offline   Reply With Quote
Old 14th July 2014, 09:05   #12  |  Link
franketto
Registered User
 
Join Date: May 2014
Posts: 60
Quote:
Originally Posted by poisondeathray View Post
Another method is to smooth out the fluctuations using a temporal smoother on the u, v channels. Works ok on a static "talking heads" scene like your sample
There are no fast movements in this clip, so Temporalsmoother could be a solution.

Thank you: your code is better than mine in the clip I uploaded, but in other parts is worse.
Like i.e. this one:
https://www.mediafire.com/?afyrc2s1exu2i2a

Infact I get flashing purple on face like this:



But there is no green splashes like in mine...
franketto is offline   Reply With Quote
Old 14th July 2014, 14:36   #13  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 3,414
Quote:
Originally Posted by franketto View Post
There are no fast movements in this clip, so Temporalsmoother could be a solution.
If it's just a static interview scene, you can stack the filters, increase the strength. Add more instances or other temporal filters if you want

e.g
Code:
main=AVISource()

u=main.utoy().ttempsmooth(maxr=3, lthresh=256, strength=8).ttempsmooth(maxr=5, lthresh=256, strength=8)
v=main.vtoy().ttempsmooth(maxr=3, lthresh=256, strength=8).ttempsmooth(maxr=5, lthresh=256, strength=8)
ytouv(u,v)
mergeluma(main)
poisondeathray is offline   Reply With Quote
Old 14th July 2014, 16:16   #14  |  Link
franketto
Registered User
 
Join Date: May 2014
Posts: 60
Thank you poisondeathray, more instances solved the problem!
franketto is offline   Reply With Quote
Old 15th July 2014, 08:11   #15  |  Link
franketto
Registered User
 
Join Date: May 2014
Posts: 60
I have still some little green hue on the faces, especially on the edges of cheecks.
Is there a way to make a mask only of face (or man's silhouette) and then tweak the hue? (Leaving intact the background.)
franketto is offline   Reply With Quote
Old 16th July 2014, 04:19   #16  |  Link
LemMotlow
Registered User
 
Join Date: Jul 2011
Location: Tennessee, USA
Posts: 235
Quote:
Originally Posted by franketto View Post
I have still some little green hue on the faces, especially on the edges of cheecks.
Is there a way to make a mask only of face (or man's silhouette) and then tweak the hue? (Leaving intact the background.)
Nope. If you use your pixel reader you'll see that the background colors and most of the facial tones are in the same tonal range. Don't assume that the background doesn't change in that scene you posted. It changes, and so does the color of the man's hair and suit. Chances that the guy's face after masking will match the other frames are pretty low, even for people who know what they're doing.

I made color corrections two ways. First I used the ColourLike method referred to in raffriff42's earlier post. Next, I tweaked with image color controls in TVMW5's encoder, which work in YUV and RGB. If you're trying to clean up specific discolored skin tones, you'll need to work in RGB. You can try ColorMill, but gradation curves would be more precise. Seems like a lot of detail overkill for a video that was thoroughly wrecked by whoever made it.

I think the purple frame that's out of place might be frame 29 in your sample. I replaced it with ReplaceFramesMC.


Here's an mp4 with color corrections. Other than calming the flicker, there's no hope for anything else. Denoise attempts just make it worse: https://www.mediafire.com/?e6uor93h4rn3q6b . Its small, ~2MB. Sorry for the offsite link, but a 300kb limit for doom9 attachments is a pretty clear message that uploads aren't welcome. Rules are rules.
Attached Images
 

Last edited by LemMotlow; 16th July 2014 at 04:39.
LemMotlow is offline   Reply With Quote
Old 16th July 2014, 09:15   #17  |  Link
franketto
Registered User
 
Join Date: May 2014
Posts: 60
I quite got it.

It was ColorYUV(Autowhite=true) that changed hue too much.
So I made all tweak manual corrections and got some little yellow variations on faces' edges.
I corrected them with:

Code:
Tweak(StartHue=130, endHue=200, hue=20 ,sat=0.8)
So, now I have this: (your take at left, mine at right)


I used also Mdegrain1, a dehalo and nnedi3 to reach the 480x360 resolution that's little better on diagonal lines instead of the 320x240 (especially in other frames I haven't uploaded).

The drawback is a washing in the details of the jacket, regards your take and banding. Maybe it's ttsmooth. I used dither to compensate a bit.
In every case, now it's watchable, the original was so much terrible.

EDIT:
What should you use to deflicker?

Last edited by franketto; 16th July 2014 at 09:22.
franketto is offline   Reply With Quote
Old 16th July 2014, 13:50   #18  |  Link
LemMotlow
Registered User
 
Join Date: Jul 2011
Location: Tennessee, USA
Posts: 235
I confess, my script for the linked sample is a mess. I gave up on denoising, had a big project running on another PC and had to keep an eye on it. DeBlock() and GradFun3() was about all the denoising I did, and I tried that last.

Quote:
Originally Posted by franketto View Post
It was ColorYUV(Autowhite=true) that changed hue too much.
So I made all tweak manual corrections and got some little yellow variations on faces' edges.
I corrected them with:

Code:
Tweak(StartHue=130, endHue=200, hue=20 ,sat=0.8)
So, now I have this: (your take at left, mine at right)
It's anyone's guess what the correct colors are. In the image on the right, the man has purple hair and looks sunburned. But mine is far from perfect. The flicker is mostly due to different color balance between even and odd frames. And at that, jerky movement seems due to missing fields and improper deinterlacing. The original's bitrate is too low for comment, with bad macroblocks. Degraining and smoothing would make it worse and cause banding.

Overall the images are beyond the desired RGB 16-240 range. I started by working with Even fields, where bright red is off the charts but darker colors and most midtones look fairly correct. I named the resulting Even fields as "Reds".

Code:
source=last
source.SelectEven()
ColorYUV(off_y=-6,gain_v=-5,cont_v=-150,cont_u=-30,gain_u=3)
SmoothLevels(16,1.0,255,15,245,chroma=200,limiter=0,tvrange=true,dither=100,protect=6)
Reds=last
Next came Odd fields, with the opposite color problems between U and V. I used autowhite in this case, then tamed that down with more ColorYUV. I called the Odd fields "Grns". The idea was to make Odd fields look at least nominally similar to Even fields, even if they will never look "alike".
Code:
Source.SelectOdd()
ColorYUV(Autowhite=true)
ColorYUV(cont_y=-10,off_y=-8,cont_v=-20,off_v=5,cont_u=-180,gain_u=-10)
Grns=last
Next, I saved ColourLike histogram files for the Reds and Grns. I made user-created variables to define the file path names and save some duplicate coding.

Code:
RedsHist="E:\forum\franketto\B\RedsHist.txt"
GrnsHist="E:\forum\franketto\B\GrnsHist.txt"
Then write the histogram files and use ColourLike to make Grns look like Reds:

Code:
Reds.WriteHistogram(RedsHist)
Grns.WriteHistogram(GrnsHist)
Grns.ColourLike(GrnsHist,RedsHist)
Then weave together Reds and Grns. Maybe it was ffms2 that caused this, but frame 14 in that Grns group was an off-color purple copy of Grns frame 0. I used ReplaceFramesMC to replace the out of sequence and off-color frame, which is now frame 29 in the interleaved group.

Code:
Interleave(Reds,Grns)
ReplaceFramesMC(29,1)
new1=last
Now there was still some luma flicker and uneven chroma. I also did a bit of deblocking and anti-banding, but probably could have done more. There was a little more color and levels to fix as touch-up. MCTD on the chroma channels calmed uneven color a little, too.
Code:
new1
Crop(2,2,-6,-4).AddBorders(4,2,4,4)
MergeChroma(MCTemporalDenoise(settings="high"))
DeBlock()
MergeChroma(aWarpSharp2(depth=30))
GradFun3(thr=1.2)
LimitedSharpenFaster()
SMoothTweak(contrast=1.2,saturation=1.4)
SmoothLevels(16,0.95,255,14,240,chroma=200,limiter=0,tvrange=true,dither=100,protect=6)
Dither_convert_yuv_to_rgb(matrix="601",interlaced=false,tv_range=true,cplace="MPEG2",lsb_in=false,output="rgb32")
return last
I saved the final results as RGB and loaded VirtualDub's DeFlicker plugin as a last step. The VirtualDub results were saved as Lagarith YV12 for the encoder. The results were still a bit green and the guy's hair and suit color were weird. That was cleaned up with TempGenc Video Mastering Works YUV color filters before encoding.

There must be 50 other ways. At least.
LemMotlow 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:55.


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