View Full Version : AviSynth DV cleanup script
FredThompson
6th July 2003, 08:38
If you haven't been following the thread I've got about cleanup in the capture area, go take a look. Regardless of what you're doing with DV, you'll probably be quite stunned how much noise is there. The script is NOT refined yet. I know that. There are some sample grabs on my page at http://www.geocities.com/fredthompson6
If you shoot DV, you really should see what's happening. The results are getting VERY good.
The thread is here (http://forum.doom9.org/showthread.php?s=&threadid=55607).
FredThompson
8th July 2003, 10:22
Oh, guess I should included that, huh?
The page is outdated. The unwanted artifacts shown in 2 of the screen grabs do NOT exist with the current script. GeoCities has been acting up so I haven't been able to edit the page. If you use the current script and frame server from NTSC DV source the image quality can be higher than if you write a DV file from the script because of the lossy nature of DV.
There IS one thing I'm still working on that's quite important for cleanup. The current script fuzzes up the last frame before a scene change. That should be fixed fairly soon.
zeus163
10th July 2003, 00:24
I can't wait to try this when I get home. I played around with it right before we left on vacation and my wife wasn't too pleased. I'm sure I'll have some questions about this when I get back as the end result on your web page looked fantastic and you are doing what I want to do. While the original capture isn't terrible, I'd like to be able to clean it up a bit.
Thanks and I'm sure I'll get back to you in a few weeks!
FredThompson
10th July 2003, 01:45
Right now I'm working on fine-tuning and making the scripts more easily used by other people. Also, I'm working on some laserdisc capture issues. Can't get into too may details but anyone with laserdisc might be interested in the attacks on moire if we're successful.
Hope to have that page updated by the weekend then I'll start on a complete how-to set of instructions. I'll submit them to doom9 first because of the dl cap at GeoCities.
Xesdeeni
10th July 2003, 16:14
Fred, one of your images compares 4:1:1 to something else. But the problem you show is specific to your DV codec, not 4:1:1. I'm guessing the "something else" you compare it to is probably 4:2:2, but the same type of problem would show up there if the codec didn't interpolate the chroma. For some reason the DV codecs don't all do this for 4:1:1.
Just basic linear interpolation helps a lot, done after the DV codec. I think you can do this with AVISynth's separation of luminance and chrominance, although I couldn't figure out how to last year, so I wrote a plugin to play with. But I wasn't satisfied with that. I had a video where a red ball was on a blue rug, and the red and blue colors bled into one-another using linear interpolation.
Anyway, I got the idea to do a "luma follower" interpolation. The idea was that there might be enough information in the luminance for the interpolation of the chromanance to follow and do a better job. For example:
Contrived original 4:4:4 (C is representative of U and V):
Y 100 101 150 149 150
C 50 51 80 79 80
4:1:1
Y 100 101 150 149 150
C 50 80
Replicated (like in your example) 4:1:1 to 4:4:4
Y 100 101 150 149 150
C 50 50 50 50 80
Linear interpolated 4:1:1 back to 4:4:4
Y 100 101 150 149 150
C 50 58 65 73 80
Luma follow (linear) 4:1:1 back to 4:4:4
Y 100 101 150 149 150
C 50 50 80 80 80
Unfortunately, in reality the noise and sharpening of the camera and/or DV codec caused me to have to add a floor and ceiling, slowing down the already unoptimized code. And the results weren't as good as I thought they should be.
I don't have this plugin with me, but if you want to see the results, I'll try to remember to grab it. But in any case, you should try interpolating the chroma, or using a DV codec that does so.
Xesdeeni
FredThompson
10th July 2003, 16:42
Yes, please, I'll be very interested to see what you've got. The comparison screenshot was with FlyVideo doing 4:2:0. At least, that's my understanding. I don't have that hardware.
The source is IanD who has recently been posting in the DV forum.
I've got a 2-frame clip from him with the second frame having the saturated red streak. What you are seeing is the result of the MainConcept codec. It's also visible with the Canopus and Panasonic codecs, Cnaopus having the worst performance.
If there's a way to filter, sure, I'd love help.
FWIW, I'm also now working on some laserdisc-specific denoising. Apparently, they can have a problem with moving moire.
FredThompson
10th July 2003, 19:27
ok, site should be properly updated now. I've added the 2-frame sample of IanD's FlyVideo3000 capture from the Star Wars laserdisc. Frame 2 is the one that's causing problems with DV. All I did to create the screengrab problem was load his file into VirtualDub then save as MainConcept DV. The problem seems common to DV encoders but the amount of unwanted color varies.
Cleanup script has also been slightly modified.
Xesdeeni
11th July 2003, 14:25
I'm sorry, I forgot to grab my Luma Follow filter. But as penance, I've created an AVISynth script you can try:AVISource("FlyVideoStarWars-MCDV.avi")
#chroma = BilinearResize(180,480).BilinearResize(720,480)
#chroma = BicubicResize(180,480).BicubicResize(720,480)
chroma = LanczosResize(180,480).LanczosResize(720,480)
MergeChroma(chroma)See what you think.
Xesdeeni
FredThompson
11th July 2003, 16:51
I'll give it a shot.
This is resizing the chroma to 1/4 res then enlarging it to fit the full frame hoping rounding will get rid of some of the junk, right?
I forgot to mention that I've come to believe the only efficient way to work with filtered video is frame serving given the size of lossless storage or artifacts from lossy compression. Given those thoughts, it's not important to force the chroma into the 4:1:1 configuration.
Right now I'm not so concerned about absolute "perfect" chroma consistency from source to destination, I'm more interested in image quality. Have come to recognize that, just like physical pigment, removing "dirt" lightens the image. It's similar to cleaning a stained glass window or the effect when the Sistene Chapel was properly cleaned.
My filtering is using a mix of YUY2, YV12 and RGB colormodels out of necessity. Maybe AviSynth 3.0 will give an internal 4:4:4 mode and properly emulate other modes for interfacing with filters while properly handling oversampling. Uh...I mean the internal version stays 4:4:4 but will appear to any of the other 3 to suite the filter. Sort of like applying a 16-bit audio filter to a 96 kHz audio sample. That would be real cool.
Xesdeeni
11th July 2003, 19:24
This is resizing the chroma to 1/4 res then enlarging it to fit the full frame hoping rounding will get rid of some of the junk, right?Yes, kind of. The output of the DV codecs replicates the chrominance over four adjacent pixels. Instead, it would be better to interpolate. But without my filter (which I think was actually written for VirtualDub) you can't fix those samples. The next best thing is to do the above.
Umm...actually. Now that I look at it, the 180x480 downscale should really be just decimation. Hmmm. Can you do that in AVISynth?
Xesdeeni
FredThompson
11th July 2003, 19:40
Dunno. I'll look into it tonight.
But....howsabout pointing me to your plugin. Can always load the VirtualDub and run it that way. Like I said, I'm not a stickler for absolute color match 'cause we're removing dirt so what's the "true" color?
Xesdeeni
11th July 2003, 21:23
I'm sorry, I forgot the filter at home. I'll try to remember to upload it from there.
Xesdeeni
Xesdeeni
14th July 2003, 05:03
If you can get it, it's at http://www.geocities.com/xesdeeni2001/411Helper.zip. If not, I'll try to update the main page to point at it tomorrow.
Xesdeeni
FredThompson
14th July 2003, 05:13
Thanks. I'm working on the script right now, matter of fact. Looking to release it tomorrow.
That's when the fun starts, huh? Public release, I mean.
FredThompson
14th July 2003, 06:03
Nuts, GeoCities is being a stickler. I noticed that with my page. They won't let you download directly, must have a link on a page hosted by them.
Xesdeeni
14th July 2003, 15:46
Try http://www.geocities.com/xesdeeni2001/index.html now.
Xesdeeni
FredThompson
15th July 2003, 01:01
Hey, that's pretty cool.
Interpolation is the better of the 2 options for saturated red on black. The junk isn't removed, it's turned into more of a somewhat dampened blob. That's a huge improvement from the grid-like original.
I've not finished testing it inside my AviSynth scripting and am wondering how it will perform at the beginning of the filter chain. Maybe if it's first, followed by CNR2 and other noise filters, the red smear will be reduced even more. Can't test that wiht VirtualDub because VirtualDub filters come after the AviSynth processing.
Is this filter something you're open to actively working on?
I'm wondering how performance could change with an agressive weighting for very low luminence regions. The idea being this distortion is far more evident when the background should be black.
So...how about a way to dramatically decrease the chroma if the luma is very low a la DarkSmoother?
Xesdeeni
15th July 2003, 14:44
Hey, that's pretty cool.
Interpolation is the better of the 2 options for saturated red on black. The junk isn't removed, it's turned into more of a somewhat dampened blob. That's a huge improvement from the grid-like original.Well, I was hoping the luma follow would be better :|I've not finished testing it inside my AviSynth scripting and am wondering how it will perform at the beginning of the filter chain. Maybe if it's first, followed by CNR2 and other noise filters, the red smear will be reduced even more. Can't test that wiht VirtualDub because VirtualDub filters come after the AviSynth processing.I'm pretty sure VirtualDub filters can be used just like AVISynth filters (except that they require RGB). All you do is use VirtualDubPlugin(). There shouldn't be any type of order issue.Is this filter something you're open to actively working on?I kind of gave up when it looked like basic interpolation looked as good or better than the "luma follow." I don't have too much time nowadays, but I included the source if you want to have a try.I'm wondering how performance could change with an agressive weighting for very low luminence regions. The idea being this distortion is far more evident when the background should be black.I don't know. It's difficult to reclaim lost information, especially when it is completely thrown out. Any assumption you make to reclaim it may be right for some images, but completely wrong for others. And remember, this is lossy compression, meaning you can never get out what was originally put in. In most cases, it's just a matter of getting something that looks good, not necessarily a duplicate of the original. In the case of your sample, the stair-step blockiness was obviously wrong. But the reconstructed version, even using the AVISynth script above, looks quite nice. It's not a duplicate of the original, but unless you put them side-by-side, will you really notice?So...how about a way to dramatically decrease the chroma if the luma is very low a la DarkSmoother?That's probably easy enough, but then dark things will have less saturation. Theoretically, the original had the amount of saturation included in the chroma sample. And if the sub-sampled chroma happened to come from something lighter up against something darker, the "luma follow" should have allowed a sharper edge in the color. Perhaps I just didn't find the right algorithm.
There was another thing that always annoyed me about sub-sampled YUV space I have never actually experimented with. Say you have two pixels (assuming 4:2:2), one that is bright and one color, and right next is a dark and another color.Y 192 10
C red blueWhen the sub-sample is generated (sometimes the colors are averaged, sometimes they are dropped, but for this example, assume they are averaged), you get an equal weighting from both colors.Y 192 10
C yellowBut depending on how dark the second pixel is, the color may have been completely invisible. But it is weighted into the color as if it were brighter. I've always wondered if the conversion from 4:4:4 to 4:2:2 (or I guess 4:1:1, although I think the standard is to drop three colors instead of averaging), a darker pixel should be weighted less.Y 192 10
C redThis means when you convert back, your bright pixel will be closer to the right color. The darker one may be further away, but I think that is probably preferable to the brighter one being further away.Y 192 10
C red redAnyway, the closest I've come to playing with this is the "luma follow." Since I'm pretty sure 4:1:1 drops three pixels, you'd get something likeY 192 193 9 10 9 ...
C red red blue blue blue ...
Y 192 193 9 10 9 ...
C red blue ...As I mentioned above, the "luma follow" should help when converting backY 192 193 9 10 9 ...
C red red blue blue blue ...But if the original colors were averaged, "luma follow" wouldn't really help:Y 192 193 9 10 9 ...
C yellow blue ...
Y 192 193 9 10 9 ...
C yel yel blue blue blue ...Xesdeeni
FredThompson
15th July 2003, 19:44
Yes, you are correct on many points ;)
Maybe I didn't fully elaborate on the weighting idea. If you look at the comparision of FlyVideo and NTSC DV capture on this page: http://www.geocities.com/fredthompson6 you'll see the 4:1:1 distortion in all its glory.
That's where the color bleed looks worst, saturated colors on a black background. There's another example near the bottom of the page.
Well, I'm wondering about an area-based method to look at the surrounding luma and mess with the chroma as needed. If you've got:
red black black black black black black...
It should be easy enough to determine where to chop off the chroma.
Uh....black means near-black...
So it's really a horizontal-only analysis and the trigger is a string of near-black pixels.
Then again, maybe it won't work. I notice this much more when there's a lot of black so I'm assuming other people would also. Short gaps are a little different and that's where your example comes in.
Think of how DarkSmoother and ShadowSmoother work on only the very low luminence pixels. That's what I'm wondering about.
Xesdeeni
15th July 2003, 23:17
OK, I put up a comparison using your image (http://www.geocities.com/xesdeeni2001).
The top image is the original from your AVI file, labelled "Original."
I then saved the file using the MainConcept DV codec, and re-loaded it using the same MainConcept codec. This image is labelled "MainConcept."
I then used the following ver. 2.0.8 AVISynth script to attempt to interpolate just the chroma:AVISource("FlyVideoStarWars-MCDV.avi")
chroma = LanczosResize(180,480).LanczosResize(720,480)
MergeChroma(chroma)The result is labelled "AVS Lanczos." You'll note that while the four-pixel banding is gone, it is replaced by two-pixel banding. This is because AVISynth was operating in 4:2:2 mode. Interestingly, using BicubicResize() or BilinearResize() made no visible difference. Even when I did a subtractive compare in Photoshop, there was so little difference that I had to crank the contrast up just to be sure there was actually a difference.
Due to the 4:2:2 issue, I tried to see if I could work around this by playing in part RGB and part YUV. This certainly isn't optimal, but the quality seems to get much better in the image labelled "AVS Bilinear (RGB)." I used this script:AVISource("FlyVideoStarWars-MCDV.avi")
chroma = ConvertToRGB.BilinearResize(180,480).BilinearResize(1440,480).ConvertToYUY2()
BilinearResize(1440,480).MergeChroma(chroma).ConvertToRGB().BilinearResize(720,480)
The image labelled "411 Helper (Int)" shows the use of my 4:1:1 Helper plugin for VirtualDub in "Interpolation" mode. This is a basic linear interpolation in 4:4:4 (actually 4:4:4:4, which I read was supposed to be faster to work in when you were just doing an intermediate between RGB and RGB).
The "411 Helper (LF)" image uses the "luma follow" technique I outline above. I'm still disappointed in this one. It just should be better.
Xesdeeni
FredThompson
16th July 2003, 00:51
OMG, that's stunning.
Wonder if this will help with VHS smearing.
cweb
30th November 2003, 19:05
Perhaps this is not too useful, but I was experimenting today with some DV AVI files decoded by the MainConcept codec, and tried the following in my avisynth script to reduce some of the excessive red colour evident in the video:
video=coloryuv(video,gain_v=-16,opt="coring",Autogain=true, Autowhite=false)
(Before this I do deinterlacing with kerneldeint and I call undot)
Basically I was trying to just reduce red by 15% without having to go back into RGB space...
The classical solution would be to do:
video=RGBAdjust(video,0.85,1,1,0).ConvertToYV12() # reduce red by 15%
where video is an RGB clip (or converted to RGB32) but I think it's wasteful to convert so much.
cweb
30th November 2003, 20:27
It's strange, but I was loading your 411 Helper (LF) virtualdub plugin just to see if it made any difference to my DV script.. well at least visually I couldn't see any difference at all.
There is supposed to be a visual improvement, isn't there? I cannot really see it, even when I zoom with my graphics program (I even tried loading the avi in Vdubmod and just using the 411 helper filter. I didn't see improvements). Of course I'm not saying 411 helper isn't any good, I just would like to see a visual improvement (and then I might use it).
I'm using Avisynth 2.54 (latest beta 261103) and the latest virtualdubmod.
Edit: I'm using PAL, so perhaps that's the reason. I asked someone else to compare the images, and they told me they saw some more gleam in the 411 processed version. I couldn't really see it....
FredThompson
1st December 2003, 02:06
411Helper and Reinterpolate411 are to correct NTSC DV which is 4:1:1, PAL is 4:2:0.
vBulletin® v3.8.4, Copyright ©2000-2010, Jelsoft Enterprises Ltd.