Log in

View Full Version : reinterpolate420 - eliminate chroma jaggyness of PAL-DV


Pages : [1] 2

scharfis_brain
22nd September 2004, 22:44
function reinterpolate420(clip x)
{
u=x.utoy()
v=x.vtoy()

u=u.separatefields().separatefields().selectevery(4,1,2).tomsmocomp(1,-1,0).assumefieldbased().weave()
v=v.separatefields().separatefields().selectevery(4,1,2).tomsmocomp(1,-1,0).assumefieldbased().weave()

ytouv(u,v,x)
}

this function will only work properly, if your DV-Decoder upsamples the interplaced YUV420 (YV12) Chroma to yuy2 using point-sampling!

the results are IMO very good:

http://home.arcor.de/scharfis_brain/samples/reinterpolate420.png

It becomes quite useful, if you intend to deinterlace your PALDV for achieving some kind of Film-Look, for deshaking-pre-processing further filtering etc.

Wilbert
22nd September 2004, 23:30
Which DV codec did you use here?

scharfis_brain
23rd September 2004, 05:14
the VDub- File Info tells me, it is using the Mainconcept-DV-CoDec for decoding.

I'll test some other codecs after work.

dionisos
23rd September 2004, 16:19
the results were AMAZING!
i never thought that reinterpolate would do such a miracle!

Wilbert
23rd September 2004, 22:36
Could you try the following plugin

http://www.geocities.com/wilbertdijkhof/ReInterpolate420_v1.zip

and add a screenshot. Progressive only (for now). Syntax

AviSource(...)
ReInterpolate420()

ADLANCAS
24th September 2004, 03:06
In theory, should work also in NTSC DV ?

Video Dude
24th September 2004, 03:37
Originally posted by ADLANCAS
In theory, should work also in NTSC DV ?


NTSC DV is 4:1:1

PAL DV is 4:2:0

So the answer is no.


There is an AviSynth filter called ReInterpolate411 by trbarry that has been around for some time.

Wilbert
24th September 2004, 23:35
Added interlaced support

http://www.geocities.com/wilbertdijkhof/ReInterpolate420_v2.zip

syntax

AviSource(..)
ReInterpolate420(interlaced=true) # false by default

@scharfis_brain,

Could you compare it to your script?

scharfis_brain
25th September 2004, 10:12
jep, it works!
You're using simple lineare interpolation, aren't you?

my method using edge directed interpolation using tomsmocomp (tdeint(mode=1) should work, too) has a better chroma definition on diagonales.

smok3
25th September 2004, 10:43
scharfis_brain: cool, do you think this will work (as preproc) in favor of a 'better' chroma key?

scharfis_brain
25th September 2004, 10:58
of course!
my reinterpolate420 tries to find diagonal edge to enhance the chroma resolution. but currently something seems to be slight weird. the chroma is shifted by about 1 or two pixels upwards (wilberts plugin, too!)

but, try some comparisions of your chroma-keying with and without reinterpolate420, and report your results!

scharfis_brain
26th September 2004, 10:29
according to this: http://www.mir.com/DMG/chroma.html
(SMPTE PAL-DV)

Cb & Cr are spatially displaced by one line per field.

Do we need to include this weirdness in our reinterpolation?

I tend to say, that there is always a slight chroma-shift in PAL-DV depending on the color.

arggggghhhhhhhhhhhhh!
I hate this crappy YUV420. I will never step behind the thoughts of those engineers.
All they did was causing confusion........

Wilbert
26th September 2004, 13:34
You're using simple lineare interpolation, aren't you?
Yup.

my method using edge directed interpolation using tomsmocomp (tdeint(mode=1) should work, too) has a better chroma definition on diagonales.
If I would know how that works, I can try to implement it :)


Cb & Cr are spatially displaced by one line per field.

Do we need to include this weirdness in our reinterpolation?
I did. Let me tell you how I interpolate:

1) Assume clip is interlaced. The layout of the *frame* is as follows

YV1 ...
YV2 ...
YU3 ...
YU4 ...
YV5 ...
YV6 ...
YU7 ...
YU8 ...

when converting to YUY2 by the codec, the existing chroma is untouched. The missing chroma is either duplicated or point sampled (not sure which one it is).

ReInterpolate creates the missing chroma (the existing chroma is left untouched) as follows:

YV1 ... U1 = as done by codec
YV2 ... U2 = as done by codec
YU3 ... V3 = 0.5*( V1 + V5 )
YU4 ... V4 = 0.5*( V2 + V6 )
YV5 ... U5 = 0.5*( U3 + U7 )
YV6 ... U6 = 0.5*( U4 + U8 )
YU7 ...
YU8 ...

2) Assume clip is progressive. I assume that the conversion is always field-based (so codec always upsamples assuming interlaced). Perhaps this is false?

The layout of the *frame* is as follows

ReInterpolate creates the missing chroma (the existing chroma is left untouched) as follows:

YV1 ... U1 = as done by codec
YV2 ... U2 = as done by codec
YU3 ... V3 = 0.666*V2 + 0.333*V5
YU4 ... V4 = 0.333*V2 + 0.666*V5
YV5 ... U5 = 0.666*U4 + 0.333*U7
YV6 ... U6 = 0.333*U4 + 0.666*U7
YU7 ...
YU8 ...

Should I do it differently? Btw, I assume your made your YV12 test clip correctly (feeding the codec with interlaced/progressive YUY2).

Last question :)
my reinterpolate420 tries to find diagonal edge to enhance the chroma resolution. but currently something seems to be slight weird. the chroma is shifted by about 1 or two pixels upwards (wilberts plugin, too!)
Could you post some screenshots of this?

scharfis_brain
26th September 2004, 13:48
thanks for your explantation!

Could you post some screenshots of this?

the screenshot above has this issue!

but, I am not sure, whether the Codec places the chroma correctly, or reinterpolate420 does ?!?

MGRip
26th September 2004, 18:31
Where to add this code in the avisynth script? (I'm newbie with avisynth)

scharfis_brain
27th September 2004, 14:10
to use this function, you need to place it at the top of your script:

[code]
function reinterpolate420(clip x)
{
u=x.utoy()
v=x.vtoy()

u=u.separatefields().separatefields().selectevery(4,1,2).tomsmocomp(1,-1,0).assumefieldbased().weave()
v=v.separatefields().separatefields().selectevery(4,1,2).tomsmocomp(1,-1,0).assumefieldbased().weave()

ytouv(u,v,x)
}

loadplugin("drive:\path\tomsmocomp.dll")

avisource("dv-video-pal.avi")
reinterpolate420()

MGRip
27th September 2004, 18:27
Thanks,
I've just added ConvertToYUY2() before the reinterpolate420() (because there was an error without this)

scharfis_brain
27th September 2004, 18:30
if your source is RGB, this should be okay, but if the source is YV12
(check with avisource("ccc").info())
then, you should not use reinterpolate420 jet.

MGRip
27th September 2004, 19:01
Somehow it says that even my captured footage is RGB24, how can it be? I captured it with adobe premiere.

communist
27th September 2004, 19:31
Are you using the PanasonicDV codec? It accepts and outputs only RGB ;)
Try ffdshows DV decoder and set it to output YV12. Also you cant have a DV file with RGB color space - DV is stored in YV12 and I dont know of any encoder (codec) that employs RGB colorspace in DV streams - but than again these wouldn be DV streams anymore ;)

MGRip
27th September 2004, 19:57
Thanks,
I have really used Panasonic's codec. Where can I find the lastest ffdshow? Do I need to uninstall the panasonic codec?

scharfis_brain
27th September 2004, 20:05
reinterpolate420() only works with the rgb or yuy2 output of commonly used DV-Codecs.

for YV12, I'll try to make another YUY2-upsampling function
(motion adaptive & edge directed)

MGRip
28th September 2004, 15:08
So how can it be that I had chroma jaggies (in text that was done in Adobe AE - full saturated) with the pana's codec (RGB24 only)?

communist
28th September 2004, 16:41
Because its DV = YV12 - no matter what your codec accepts as input and whatever it outputs after upsampling the chroma from YV12 :rolleyes:

MGRip
28th September 2004, 17:41
So why I can't reduce chroma jaggies when its the Panasonic codec?
Or maybe if I will write ConvertToYUY2() will it be the same effect as YV12?

scharfis_brain
28th September 2004, 17:49
1) DV is stored as YV12. period.

2) the codec can output the video in those ways:
2a) leave it as it is: -> YV12 -> use converttoyuy2(interlaced=true) for a first aid to remove chroma-jaggyness.
YV12 output is one of the rare cases. ffdshow can do so.

2b) the codec upsamples to YUY2. (canopus)
but this is done in a very stupid way: pixel doubling.
this causes to the mentioned jaggyness, reinterpolate420() tries to eliminate

2c) the codec delivers YV12 upsampled to RGB24 (panasonic).
this upsampling is as stupid as the YUY2 one.
here you might use converttoyuy2() to get back to yuy2 and then apply reinterpolate420().

3) conclusion:
start with:
avisource("dv.avi").info()
if it is yv12, use converttoyuy2(interlaced=true), but do NOT use reinterpolate420()

if it is yuy2, just use reinterpooate420()

if it is rgb, then use

converttoyuy2().reinterpolate420()


got it now? :devil:

MGRip
28th September 2004, 19:04
Thanks for spending the time on me, I highly appreciate your help :)
This script very helped me :D

Wilbert
29th September 2004, 10:53
@scharfis,

if it is yv12, use converttoyuy2(interlaced=true), but do NOT use reinterpolate420()
You can do that, but it might be better to use 1/2-1/2 upsampling instead of the 3/4-1/4. I will change my plugin so that you can compare it.

About PAL DV YV12:

PAL always merges two chroma lines together within the PAL-Decoder for better chroma stability -> similar to interlaced YV12
The advantage is that PAL DV doesn't have this weird chroma placement. It occured to me that this implies that the conversion YV12->YUY2->YV12 (interlaced stuff) is lossless (which is not the case for mpeg1/mpeg2 4:2:0 as we all know).

smok3
29th September 2004, 12:48
i wonder what kind of colormagic stuff does the new experimental vdub (1.6.0) - with internal dv decoder?:
http://somestuff.org/images/galleries/site/dv_compare.png
(note:this is not exactly the same frame, maybe it is not visible on this snapshot, but the internal vdub decoder produces much nicer pic)

edit2: another comparision:
http://somestuff.org/images/galleries/site/dv_compare_vdub_vs_le.png

edit3: i just noticed, the vdub pixels in this 2nd example are 1:1 while liquid uses pal ar, but that does not affect chroma jaggies.
edit1: this is pal.
--------------------------------

scharfis_brain: actually i dont do chroma key very often, so i dont have any cool material to try at hand right now.

KF
12th October 2004, 13:23
I've a DV500 analog and DV firewire card. I've noticed the same artefacts and avisource(...).info() reports rgb32 and Pinnacle DV...
for the codec information. My source is PAL interlaced. I tend to edit in Premiere with a final target being a DVD.
What's the final conclusion from your thread? Should I use Wilbert's plugin or scharfis_brain's function? Which is faster and which one keeps all of the original data intact? Is ffdshow a better approach to decompressing? How good is it in terms of quality? I'm sorry if you think I should have gathered all this info from the thread, but I just need some kind of finalising statement to say what the best final method should be.:confused:

TIA

Wilbert
12th October 2004, 13:51
Should I use Wilbert's plugin or scharfis_brain's function?
I principle you can use both. But, scharfis said his one gives more pleasing results:


my method using edge directed interpolation using tomsmocomp (tdeint(mode=1) should work, too) has a better chroma definition on diagonales.

Which is faster?
Why don't you test this for us?

which one keeps all of the original data intact?
Both.

Is ffdshow a better approach to decompressing? How good is it in terms of quality?
Nope. The idea with ffdshow was that you could let it deliver YV12. You shouldn't do that in case of NTSC (cause DV 4:1:1 is not supported in AviSynth). For PAL, we should change ConvertToYUY2, because DV-YV12 is different as MPEG2-YV12 (the one AviSynth uses). I guess I can add that in my plugin.

So, no benefits if you use ffdshow.

KF
12th October 2004, 20:01
Wilbert, this was just a quick test

scripts used:

Wilbert's
=========
loadplugin("C:\Program Files\AviSynth 2.5\plugins\ReInterpolate420.dll")
avisource("myfile.avi").info()
ConvertToYUY2()
ReInterpolate420(interlaced=true)

Scharfis_Brain's
================
function reinterpolate420(clip x)
{
u=x.utoy()
v=x.vtoy()

u=u.separatefields().separatefields().selectevery(4,1,2).tomsmocomp(1,-1,0).assumefieldbased().weave()
v=v.separatefields().separatefields().selectevery(4,1,2).tomsmocomp(1,-1,0).assumefieldbased().weave()

ytouv(u,v,x)
}

loadplugin("C:\Program Files\AviSynth 2.5\plugins\tomsmocomp.dll")

avisource("myfile.avi").info()
ConvertToYUY2()
reinterpolate420()

************************************************
time take by cce 2.67

time taken: 1:59:36 scharfis_brain

time taken: 1:53:43 wilbert

Original File size 96,503,820 bytes

Attached zipfile contains snapshots of the same frame.
Strange observations if you examine the yellow text.
Scharfis_Brain's method causes the colour of the text to be less by one pixel whilst Wilbert's method causes the colour to extend out of the text boundaries by one pixel.
I've had to crop the images in order to meet the upload file size restrictions.
But the portion shows what I mean.

scharfis_brain
12th October 2004, 20:07
the att. does not work

KF
12th October 2004, 20:16
Having problems uploading zip file. When I edit the post it shows the attached file but I can't see any link:confused:

Wilbert
12th October 2004, 20:19
Attachments work again. But bb has to approve them.

KF
13th October 2004, 18:43
As I can't see my attachment yet, I've managed to upload the full snapshots here.
http://www.raikmo.demon.co.uk/scharfis_brain.bmp
http://www.raikmo.demon.co.uk/wilbert.bmp

If you zoom 300% in photoshop and examine the yellow text you'll know what I meant in my earlier post.
Scharfis method produces chroma that doesn't fill the full text characters, i.e. less by 1 pixel. Whilst Wilbert's method produces bleeding by 1 pixel.

scharfis_brain
13th October 2004, 19:09
Do NOT use the overlaid text as reference!

it is created using common chroma sampling, but DV uses another kind of chroma sampling!

wilberts method seems to has the correct chroma - placing, while my method seems to introduce a chroma upshift.

I'll try to correct this.

KF
14th October 2004, 09:21
Thanks Scharfis!:)

KF
14th October 2004, 13:48
Since the Pinnacle DV codec produces only RGB output is there any mileage in installing one of the other codecs, such as MainConcept's DV codec? Bearing in mind that I need to edit the avi files in Premiere prior to encoding in MPEG2.

KF
18th October 2004, 15:13
Are the Mainconcept's codec or Canopus's codec better in terms of quality and speed of rendering, compared to Pinnacle's DV codec?

abraxxa
25th November 2004, 00:38
I tried your plugin Wilbert but it doesn't really help.
The video looks like pixel-doubled after inserting 'ConvertToYUY2(interlaced=true)' (what is needed because DirectShowSource gives me YV12).
The source is PAL DV interlaced BUT edited with Adobe Premiere by a friend (who isn't very experienced with video codecs...).

This is my avisynth script:

loadplugin("C:\Programme\AviSynth 2.5\plugins\kerneldeint140.dll")
DirectShowSource("E:\DVDRIP\TSC_DVD_#1\gtech3-raw-big.avi")
ConvertToYUY2(interlaced=true)
#ReInterpolate420(interlaced=true)
KernelDeint(order=0,threshold=6,sharp=true,map=false


Any suggestions?
I search the whole doom9 forum and tried out different things for hours but I just don't get the quality of your screenshots :(

Wilbert
25th November 2004, 21:50
You shouldn't load it via ffdshow. The problem is that DV-YV12 and MPEG2-YV12 is sampled differently. This implies that the conversions DV-YV12 -> YUY2 and MPEG2-YV12 -> YUY2 (the latter is what avs does) should be done differently.

I will add 'DV-YV12 -> YUY2' one day to my filter, but don't have time now.

Bottom line, load your dv with avisource :)

abraxxa
25th November 2004, 23:47
THANKS!
I knew that there is a difference but not which and i thought that 'eliminate chroma jaggyness of PAL-DV' is related to PAL-DV cam footage.
I used DirectShowSource() cause i have no vfw codec for AviSource() and DirectShowSource().info() shows me that its YV12 so I thought its ok.
I installed Sony DV codec 2.23 which outputs RGB24.
Quality is still bad :(
Now I found out that I have Canopus DV codec installed. (i don't know the version, it's the one shipped with Procoder 2.0).
But quality is still bad :(
Mainly the edges have a 'rainbow' effect :confused:

loadplugin("E:\Install\Video\AviSynth\ReInterpolate420\Release\ReInterpolate420.dll")
loadplugin("E:\Install\Video\AviSynth\KernelDeint_1.5.2\kerneldeint.dll")
AviSource("E:\DVDRIP\TSC_DVD_#1\gtech3-raw-big.avi", true, "YUY2", fourCC="CDVC").info()
#ConvertToYUY2(interlaced=true)
ReInterpolate420(interlaced=true)
#KernelDeint(order=0,threshold=6,sharp=true,map=false)

It also seems that ReInterpolate420 doesn't do/change anything...

What are I'm missing? :confused:

Wilbert
26th November 2004, 13:00
Could you upload a small clip (of about 25 frames)?

abraxxa
26th November 2004, 15:35
No problem!

25 frames snip (http://abraxxa.zorro.at/temp/gtech3_snip.avi)

You can see the effect on the edge of the roof of the halls in the background.
Is this a deinterlacing problem OR a choma problem?

Try it with this avisynth script:

loadplugin("c:\Install\Video\AviSynth\KernelDeint_1.5.2\kerneldeint.dll")
AviSource("c:\temp\gtech3_snip.avi", false, "YUY2", fourCC="CDVC")
KernelDeint(order=0,threshold=5,sharp=true,map=false)

I tried also with order=1 but that doesn't help either...

abraxxa
8th December 2004, 21:12
*bump*

Had you time to look into my problem Wilbert?

Wilbert
8th December 2004, 23:52
Sorry, I forgot about it :) I will look at it tomorrow.

abraxxa
9th December 2004, 00:44
Thanks! ;)

henryho_hk
11th December 2004, 14:12
I have a Sony DSR-PD150P (PAL edition) and the Canopus playback-only codec installed. I want to rip the DV on the tape using WinDV, mark the avi as cdvc and then convert it to XviD.

I suppose I should do the following, right?

avisource("input.avi",pixel_type="YUY2",audio=true)
FixBrokenChromaUpsampling()
ReInterpolate420(interlaced=true)
ConvertToYV12(interlaced=true)
kerneldeint(order=0,sharp=true)
removegrain(mode=2)

Or should I remove "ReInterpolate420()" for the reason that I will convert it to YV12 later?

scharfis_brain
11th December 2004, 14:22
@abraxxa: I found nothing special with your clip.
The stairstepping is a very normal thing with interlacing.
Either use tdeint(mode=1, tryweave=false) instead of kernelbob() or start experimenting with mvbob()...

@henryho_hk: what do you intend to gain by the usage of:

ReInterpolate420(interlaced=true)
ConvertToYV12(interlaced=true)


your YV12 chroma will only be blurred unnesesary.

if you need YV12 out of an DV-AVI, open it via directshowsource() and enable ffdshow as DV-Decoder.
it will give you much better chroma...