Log in

View Full Version : Deinterlacing PAL gives wave artifacts


Pages : [1] 2

Atlantis
18th April 2021, 11:32
https://i.postimg.cc/90BnNRqN/clip1.jpg

I have an interlaced PAL DVD video. Don't know how to deinterlace it properly.

QTGMC
TFM
EEDI3
nnedi3
TDeint
YadifMod2

Everything gives a strange wave effect as you see on the left image

Only FieldDeinterlace gives a better result. The image on the right.

QTGMC progressive mode gives a nice image but the motion is jerky. Understandable I suppose.

What's happening here? Can you do a better job? Maybe with QTGMC? Here is the original file:
https://ufile.io/g4iifg8u

2 minutes bright clip:
https://www.mediafire.com/file/nk1gfnek2orz5nd/clip.mkv/file

1 minute dark clip:
https://www.mediafire.com/file/hat1gxxndxppgmw/clip2.mkv/file

Sharc
18th April 2021, 12:01
The moire is already in the source, in both fields.
Deinterlacing won't fix it.

Atlantis
18th April 2021, 12:09
So what to do?

Sharc
18th April 2021, 12:35
You could try DeFreq.
http://avisynth.org.ru/defreq/defreq.html

Good luck.

StainlessS
18th April 2021, 15:18
I think JohnMeyer said he used Spotless to fix some moire, but DeFreq should probably work.

johnmeyer
18th April 2021, 16:54
The original post is very confusing because it implies that the moiré pattern only showed up once deinterlacing was performed. If this clip truly is the original, then it is obvious that the pattern is baked into the original, and all the various tools listed (e.g., TFM, QTGMC, etc.) won't touch it.

If the problem showed up when deinterlacing, then you should most definitely read this recent thread:

Moire Effect & TFM(pp=0) Solution (forum.doom9.org/showthread.php?t=182154)

I got quite an education about deinterlacing when I found out that you can indeed create moiré patterns by deinterlacing (because of motion estimation) and that tuning TFM can make a big improvement (i.e., very little moiré).

To get rid of moiré that is "baked in," Defreq is the usual thing to try.

StainlessS mentioned that I had used Spotless to remove moiré, but he may be thinking of how I used it to remove rainbows, in this post:

https://forum.videohelp.com/threads/398864-Need-help-on-Avisynth?highlight=spotless#post2595644

Atlantis
18th April 2021, 17:56
There is nothing confusing in the original post. The original video is provided and you can inspect it as it was said.

TFM(pp=0) doesn't help much. I have come to the conclusion that the best script for the moment is:

FieldDeinterlace()
QTGMC(InputType=2, TR2=2)

StainlessS
18th April 2021, 18:11
thinking of how I used it to remove rainbows
Yep, that was my mistake John.

johnmeyer
18th April 2021, 19:33
There is nothing confusing in the original post. The original video is provided and you can inspect it as it was said.Not to be argumentative, but just to clarify things so people don't go chasing the wrong thing, in that original post you said:

QTGMC
TFM
EEDI3
nnedi3
TDeint
YadifMod2

Everything gives a strange wave effect as you see on the left image

"Everything gives" means, to me, that you applied one or more of the AVISynth DLLs you listed and that they then produced the wave effect, which was not present in the original. You also showed a side-by-side image with what purports to be the original, on the right, showing no lines.

So, I am actually still confused because what you posted is supposed to be the original, but it has lines, whereas the still you posted does not.

Again, Defreq should be able to reduce the lines quite a bit, and I suggest you try it. You may need to get some help with the settings, because the documentation is not great, and the settings for the spacing between the lines, and the angle of the lines interact.

The waviness of the lines may require that you apply Defreq more than once as I did in this recent post I made about very stron horizontal lines. As you will see in my final post in that thread, with the help of jagabo over at Videohelp.com (to get good settings), I did a pretty good job eliminating the lines.

Horizontal noise bars - what are they called, and how to remove? (http://forum.doom9.org/showthread.php?t=182712)

Like your video, I had to first perform IVTC.

wonkey_monkey
18th April 2021, 19:41
The original post is very confusing because it implies that the moiré pattern only showed up once deinterlacing was performed. If this clip truly is the original, then it is obvious that the pattern is baked into the original, and all the various tools listed (e.g., TFM, QTGMC, etc.) won't touch it.


While the moiré pattern is baked into the original, it's also true that it only "shows up" in a still frame after deinterlacing because the moiré patterns in each field visually cancel each other out. Here's the original final frame:

https://i.imgur.com/pLYG8ca.png

All that can be seen is a slight diagonal pattern, most easily visible on the door just to the right of the crown.

It's only when the fields are truly separated that the moiré really becomes visible in a still image:

https://i.imgur.com/V6D98Wl.png

Richard1485
18th April 2021, 22:57
All that can be seen is a slight diagonal pattern, most easily visible on the door just to the right of the crown.

Exactly, which makes me wonder whether this is worth deinterlacing. The series was shot on video and correctly transferred to DVD as interlaced PAL. Deinterlacing it makes the artifacts look worse. Why not leave it as it is?

Atlantis
18th April 2021, 23:01
Again, the post is clear. The image on the left is QTGMC applied, the right image is FieldDeinterlace applied.

FieldDeinterlace is the only filter that gives an acceptable result.

Atlantis
18th April 2021, 23:04
I combine it with QTGMC progressive and that is the best, easiest and fastest result I get.

FieldDeinterlace()
QTGMC(InputType=2, TR2=2)

Richard1485
18th April 2021, 23:15
FieldDeinterlace is the only filter that gives an acceptable result.

I combine it with QTGMC progressive and that is the best, easiest and fastest result I get.


Great, so from your point of view, the problem is solved as far as it can be, yes?

johnmeyer
18th April 2021, 23:25
If you do want to do more work, I suggest that you do read the first link I gave in post #6 above. It appears to me that you may have a very similar problem. One of the "solutions" posted in that thread, which worked better than others, is pretty close to your simple deinterlace. So, as Richard1485 says, that may be the best you can do. However, there were some other interesting ideas posted in that long thread and the OP got far more advice that you've gotten so far here. I've got a sneaking hunch that you can still get a better result.

wonkey_monkey
19th April 2021, 00:17
Exactly, which makes me wonder whether this is worth deinterlacing. The series was shot on video and correctly transferred to DVD as interlaced PAL. Deinterlacing it makes the artifacts look worse. Why not leave it as it is?

For the same reasons that you'd ever deinterlace anything, which are mostly to avoid deinterlacing headaches/incompatabilities on playback later on, or because your target codec doesn't support interlacing.

Deinterlacing only really makes the artefacts look worse in still images. As video playing back, it'll look largely the same.


FieldDeinterlace is the only filter that gives an acceptable result.

I could be wrong, but it seems to me that if FieldDeinterlace is capable of filtering out that much unwanted "detail", it must also be filtering out quite a bit of actual detail (or leaving in some residual interlacing)

Richard1485
19th April 2021, 00:42
For the same reasons that you'd ever deinterlace anything, which are mostly to avoid deinterlacing headaches/incompatabilities on playback later on, or because your target codec doesn't support interlacing.

Deinterlacing only really makes the artefacts look worse in still images. As video playing back, it'll look largely the same.

The artifacts are visibly worse to me on playback after deinterlacing. And I wouldn't deinterlace interlaced PAL content that was shot on video. If the video has to be recompressed, it's better to pick a codec that supports interlacing.

wonkey_monkey
19th April 2021, 00:56
The artifacts are visibly worse to me on playback after deinterlacing.

Well the video has to be deinterlaced at some point if you're going to play it back properly. So, "worse on playback after deinterlacing" compared to what?

If the video has to be recompressed, it's better to pick a codec that supports interlacing.

Yes, if that's an option. Sometimes it isn't, and even if a codec supports it there's no guarantee a player will treat the codec's output properly.

Richard1485
19th April 2021, 01:16
Well the video has to be deinterlaced at some point if you're going to play it back properly. So, "worse on playback after deinterlacing" compared to what?

The original video played back on the same equipment.

Yes, if that's an option. Sometimes it isn't, and even if a codec supports it there's no guarantee a player will treat the codec's output properly.

That's true, of course. But back in post #11, I was wondering whether it's really worth the OP's while to deinterlace this content, and I'm still wondering that. Maybe there's some factor that prohibits re-encoding as interlaced, but it's nothing that we've heard about so far.

Atlantis
19th April 2021, 02:06
Bad news. After closer inspection of the full video encode (Not possible with the sample video) FieldDeinterlace() seems doesn't detect scene change:

https://i.postimg.cc/XNQDLkgw/bad-scene-change.jpg

As you see the two frames are combined. So I'm still stuck. Not good enough for me. Everything looks good except the scene change.
Don't know what else to do. I'm really trying not to make it too complicated. I have a hunch that DeFreq shouldn't work great. The DeFreq example image on the site given doesn't look that great to me.

Only if I could have FieldDeinterlace() with scene change detection I would be happy. Or something instead of FieldDeinterlace that doesn't show the waves.

Richard1485
19th April 2021, 02:26
I have a hunch that DeFreq shouldn't work great. The DeFreq example image on the site given doesn't look that great to me.

It's probably wise not to judge it based on an example image, especially as you might be able to get guidance with settings. The results that jagabo's advice recently produced were impressive.

StainlessS
19th April 2021, 04:38
Only if I could have FieldDeinterlace() with scene change detection I would be happy.
Maybe/probably changes scene on 2nd field of the same frame, we can fix that I think.
[just replace last frame before scene change with frame before or after it].
Check out the posted frame, is it changing scene mid frame ?

Time for bed now [well 04:45 so a bit past bedtime], if not fixed before I return then post a dozen frames before
and after problem frame [untouched].

Boulder
19th April 2021, 05:31
Only if I could have FieldDeinterlace() with scene change detection I would be happy. Or something instead of FieldDeinterlace that doesn't show the waves.

Do you mean that it should leave that frame interlaced? The scene change occurs "inside" the frame, i.e. the first field belongs to scene A and the next field to B.

Sharc
19th April 2021, 07:49
FieldDeinterlace helps in this particular case because it blends by default, i.e.
FieldDeinterlace(blend=true)

The price is some blurriness and the blended frames at scene changes.
Also, you may want to adjust the threshold
FieldDeinterlace(threshold=30,blend=true)

For comparison:
v1=QTGMC().selecteven()
v2=FieldDeinterlace(threshold=30,blend=true)
stackhorizontal(v1,v2)

wonkey_monkey
19th April 2021, 10:08
The original video played back on the same equipment.

...which must do some kind of deinterlacing if it's to play it back properly. If not, then you're watching it with combing, which is wrong.

Maybe/probably changes scene on 2nd field of the same frame, we can fix that I think.

That's unusual for a BBC production.

Boulder
19th April 2021, 11:35
The question is, is the blend actually noticable when watching the result at 25 fps?

Atlantis
19th April 2021, 11:38
Before testing the solutions, I'm going to post the original file with scene change:

https://ufile.io/u0kysgxv

Atlantis
19th April 2021, 11:47
Reporting before testing the other solutions.
Last night I discovered that TFM(pp=5) works. It gives no wave pattern and the scene change detection works. I got excited and encoded the whole video. Later I found out that the movements are choppy and not as smooth as FieldDeinterlace.
So, still not good. Now I'm going to test the other solutions said here.

Atlantis
19th April 2021, 11:54
Do you mean that it should leave that frame interlaced? The scene change occurs "inside" the frame, i.e. the first field belongs to scene A and the next field to B.
Of course not. I am deinterlacing. I don't want to see two blended frames like that. It should be a clean change from one scene to the next scene. Not blended.

Richard1485
19th April 2021, 12:32
...which must do some kind of deinterlacing if it's to play it back properly. If not, then you're watching it with combing, which is wrong.

Obviously. What I was implying is that deinterlacing with AviSynth doesn't make the video look appreciably better than just playing the original video and handling the deinterlacing on playback, which made me wonder if the former is achieving much here. But the OP seems set on it, so...

Of course not. I am deinterlacing. I don't want to see two blended frames like that. It should be a clean change from one scene to the next scene. Not blended.

I suppose that there might be a field-order transition at some point. Perhaps you could try calling TFM() before FieldDeinterlace().

Frank62
19th April 2021, 12:43
FieldDeinterlace helps in this particular case because it blends by default, i.e.
FieldDeinterlace(blend=true)

The price is some blurriness and the blended frames at scene changes.

That's the whole point of it all.

-You have moire patterns in both fields
-The only way to remove those (apart from defreq, for which, I fear, you have to turn the picture for 45 degrees first and handle fields separately) seems to be to blend both fields, which, by accident, makes the moire invisible,
-but:
1. will of course cause ghosting if there is more horizontal movement in a scene, AND
2. causes blending of scenechanges, too.

There might be ways to handle the blend-deinterlacing so that it respects scenechanges (never perfectly, because scenechange detection is always thesholded and never works absolutely perfect), but because of point 1., ghosting, it's not the best idea anyway.
The only solution to make it look better will be Defreq.

Atlantis
19th April 2021, 15:02
FieldDeinterlace(threshold=30,blend=true)

does not work. I went from 10 to 70 and you still get blended frames at scene change. I'm basically at point zero again.

Boulder
19th April 2021, 15:06
FieldDeinterlace(threshold=30,blend=true)

does not work. I went from 10 to 70 and you still get blended frames at scene change. I'm basically at point zero again.

The threshold is not for scene changes but detecting combing. If you use blend=true which is the default, you will get blend deinterlacing no matter what :)

Atlantis
19th April 2021, 15:20
Ok. This is so frustrating. I did not believe for one second that it is going to be this hard and problematic. I thought I'm going to apply QTGMC and all will be good.

wonkey_monkey
19th April 2021, 15:38
If all the scene changes are mid-frame like that, then I think you can "solve" the scene-change problem quite easily by doing

SeparateFields
Trim(1, framecount - 2)
Weave

before calling FieldDeinterlace. It'll leave your output half a (25fps) frame out of sync with your audio, though.

That doesn't mean it's necessarily a great idea to do this; see the points raised by others.

poisondeathray
19th April 2021, 15:59
You can use conditionalfilter or similar scene change detection methods to replace the scenechange blend frame

eg.
This relies on the frame before and after being very different (it should be, when current frame is the blended scenechange frame). It replaces that frame with single rate deinterlaced frame, not blended. It works on your sample , but tweak the thresholds to match your source


#sourcefilter
o=last

o
assumetff()
bwdif(field=3, edeint=nnedi3(field=3))
deint=last

deint
merge(selecteven, selectodd)
deintblend=last

deintblendhalf = deint.selecteven()

ConditionalFilter(deintblend, deintblendhalf, deintblend, "YDifferenceFromPrevious>19 && YDifferenceToNext>19")

Atlantis
19th April 2021, 16:18
Thank you so much.

SeparateFields
Trim(1, framecount - 2)
Weave
FieldDeinterlace()

Seem to work. Since I always try to do the easiest and the shortest solution, I am going to do a full encode with this to see if all is good and it is not choppy like TFM(pp=5).

Atlantis
19th April 2021, 18:06
OK, So unfortunately that doesn't work. Now I understand what it is doing, shifting one field. Unfortunately not all the scene changes have blended fields from 2 scenes. Some are good and from the same scene.

poisondeathray's script works on all scene changes as I'm comparing and also has no wave effect. I first want to understand it so that I can use it correctly.
It is also deintelacing and it is using nnedi3, correct? I just don't understand why it is not giving that wave effect. nnedi3 alone shows the wave effect.

Frank62
19th April 2021, 18:06
Any blend-deintelacing won't be choppy, but ghosting... ;)

Our postings crosed, so:
There are different types of deinterlacing. Most use ONE field and try to reconstruct the other field somehow. No matter what you use: These kind of deinterlacing will keep your moire.
The only way to make the moire invisible with deinterlacing seems to be BLEND-Deinterlacing, which blends the two fields together.
When aou use this you will have the problem with scenechanges (or you have to adapt by hand, once using field delay and once not).
But the main problem is the ghosting, that will always disturb when there is horizontal movement.
Once again: You will have to try it with defreq.

Atlantis
19th April 2021, 18:23
The chances of me trying defreq is close to zero. Unless someone posts the script. :D

poisondeathray's script looks working.

Frank62
19th April 2021, 18:40
God luck.

poisondeathray
19th April 2021, 20:24
poisondeathray's script works on all scene changes as I'm comparing and also has no wave effect. I first want to understand it so that I can use it correctly.
It is also deintelacing and it is using nnedi3, correct? I just don't understand why it is not giving that wave effect. nnedi3 alone shows the wave effect.



Yes, it's deinterlacing with bwdif+nnedi3 . A blend deinterlacing variation is applied by merging n, n+1 frames after double rate deinterlacing. It's analagous to blend deinterlacing with blending of top and bottom fields. bwdif+nnedi3 gives less aliasing or jaggy deinterlacing artifacts than fielddeinterlace - that was the reason for choosing it.

The wavy distortions are cancelled out because of the blend deinterlacing - same as fielddeinterlace

Blend deinterlacing in general is a "terrible" approach... But your source has this unique property that seems to cancel out when top and bottom field are combined (or n, n+1 frames when double rate deinterlaced)

Scene change blend frame from 2 scenes is detected with logic - if current frame is very different than next AND previous, then do "x" . Where "x" is replace with a single rate deinterlaced version - that "replaced" frame still has the original frequency distortion pattern (ie. the "wave" effect). But it's "less bad" than the blend frame from 2 scenes,and you only see it for 1 frame on blended scene changes

If you prefer to use a blended copy instead, you can replace it with a n+1 shifted version instead, but the total frame count will be increased by 1 . The timing should still be the same until the very end frame


deintblendplus = deintblend.loop(2,0,0)
ConditionalFilter(deintblend, deintblendplus, deintblend, "YDifferenceFromPrevious>19 && YDifferenceToNext>19")



I too would like to see defreq, or F1Quiver, or F2Quiver or similar script, because in theory they should give better results than "terrible" blend deinterlacing. The problem is finding the correct parameters...

zorr
19th April 2021, 22:02
I think this problem can be attacked with Zopti. Since the blend deinterlaced frame doesn't have the moire pattern, that can work as the target. Do normal deinterlacing and apply DeFreq, compare with blend deinterlaced frame. Let Zopti find the optimal values for DeFreq.

I'd like to try this but seems the download link of the original video isn't working.

poisondeathray
19th April 2021, 22:19
I think this problem can be attacked with Zopti. Since the blend deinterlaced frame doesn't have the moire pattern, that can work as the target. Do normal deinterlacing and apply DeFreq, compare with blend deinterlaced frame. Let Zopti find the optimal values for DeFreq.

I'd like to try this but seems the download link of the original video isn't working.

mirror of both clips
https://www.mediafire.com/file/7ewphbxi0h82ebr/atlantis_wave_artifact.zip/file

Also maybe look at
http://www.avisynth.nl/users/vcmohan/FFTQuiver/F1Quiver.htm
http://www.avisynth.nl/users/vcmohan/FFTQuiver/F2Quiver.htm

Frank62
19th April 2021, 23:00
If anyone should try this with zopti:
If I interpret correctly what had been said in another thread about DeFreq by its author, you will have to turn the picture first by 45 degrees so that the moire lines will be vertical.

Atlantis
19th April 2021, 23:44
deintblendplus = deintblend.loop(2,0,0)
ConditionalFilter(deintblend, deintblendplus, deintblend, "YDifferenceFromPrevious>19 && YDifferenceToNext>19")

I tried that but the old version is better. This new one gives 2 consecutive frames before some scene changes that are exactly like each other. It's like 2 fixed frames copied. The old version gives a frame that is a little different, so it's smoother.

Atlantis
19th April 2021, 23:57
Some scene changes were still blended, so I had to reduce the threshold to 7.
ConditionalFilter(deintblend, deintblendhalf, deintblend, "YDifferenceFromPrevious>7 && YDifferenceToNext>7")

What happens if you go too low?

poisondeathray
20th April 2021, 00:09
Some scene changes were still blended, so I had to reduce the threshold to 7.
ConditionalFilter(deintblend, deintblendhalf, deintblend, "YDifferenceFromPrevious>7 && YDifferenceToNext>7")

What happens if you go too low?

They get replaced by nonblended deinterlaced version. Artifact should be present in those replaced frames

You can use show=true to help identify which frames are replaced

ConditionalFilter(deintblend, deintblendhalf, deintblend, "YDifferenceFromPrevious>7 && YDifferenceToNext>7", show=true)


There might be better conditions to use, or other parameters that are more specific to identify that sceneblend frame

poisondeathray
20th April 2021, 00:13
eg. StainlessS has a bunch of detection and utility scripts - it might be better to run a first pass scene detection script to get metrics , then replace those scene blend frames - just throwing out ideas

StainlessS
20th April 2021, 14:48
eg. StainlessS has a bunch of detection and utility scripts
OK, I finally got a bit of time to knock this up [need some kind soul to integrate into the deinterlace thingy].
This is just demo, detect on original clip only [pre deinterlace], I dont kow what that BWDif thing is,
if assistance needed I could mod to work with double rate.

here tis, Just displayed metrics, choose which [or combination] you prefer [I have not really tweaked LPD_Th, probably anything about 4 -> 16 might be OK].


AvisourcE("clip3.mkv.avi")
o=last
assumetff()

# Config
LPD_Th = 10 # RT_LumaPixelsDifferent(), if corresponding pixels more different than this then is counted

SSS="""
n = current_frame
YAE = RT_AverageLuma(n=n,y=0,interlaced=True) # AverageLuma Even scanlines [ie even field]
YAO = RT_AverageLuma(n=n,y=1,interlaced=True) # AverageLuma Odd scanlines [ie odd field]
YAD = Abs(YAE-YAO) # AverageLuma Difference of Even,Odd Scanline [Brightness Diff)
YD = RT_LumaDifference(Last,Last,n=n,y=0,n2=n,y2=1,interlaced=true) # Average Per Pixel Diff betwwen Even and Odd fields
YC = RT_LumaCorrelation(Last,Last,n=n,y=0,n2=n,y2=1,interlaced=True) # Correlation Between Even and Odd scanlines
YDC = (1.0-YC)*255.0 # Difference by Correlation
YPD = RT_LumaPixelsDifferent(Last,Last,n=n,y=0,n2=n,y2=1,interlaced=true,Thresh=LPD_Th)
RT_Subtitle("%d]\nYAD=%7.3f : { YAE=%7.3f : YAO=%7.3f }\nYD =%7.3f\nYDC=%7.3f\nYPD=%7.3f",n,YAD,YAE,YAO,YD,YDC,YPD)
"""
Scriptclip(SSS)
#StackHorizontal(o,Last)
Return last
__END__

/*
RT_LumaPixelsDifferent(clip c,clip c2,int "n"=current_frame,int "delta"=0,int "x"=0,int "y"=0,int "w"=0,int "h"=0, \
int "n2"=current_frame,int "delta2"=0,int "x2"=x,int"y2"=y,bool "interlaced"=false, \
int "matrix"=(Width>1100||Height>600?3:2),int "Thresh"=0)

Compares clip c frame (n+delta) at x,y,w,h, and clip c2 frame (n2+delta2) at x2,y2,w,h, and returns amount of pixels
whose pixel luma difference is greater than Thresh (RGB converted to Luma-Y using Matrix).
Matrix 0=Rec601, 1=Rec709, 2=PC601, 3=PC709.
If Interlaced=True, then skips every other raster line, eg process only y, y+2, y+4 etc.
Thresh Default 0, returns number of pixels that are not exactly the same.
Return value is in range 0.0 (meaning none) to 255.0 meaning 100% of pixels.
*/


Frame 103
https://i.postimg.cc/JnQ2s105/f103.jpg (https://postimages.org/)

Frame 104
https://i.postimg.cc/KjvsLdgS/f104.jpg (https://postimages.org/)

Frame 105
https://i.postimg.cc/908gBJG4/f105.jpg (https://postimages.org/)

EDIT: If making frames.txt command file whotsit, [for double rated result clip, and eg ClipClop replaceemnt]
n*2 = last of current scene, n*2+1 = scene change, when decided to be different

EDIT: Maybe, if 2 (or maybe 3) out of 4 say scene change then is scene change, ie a voting system.
[but you need vote threholds for each, eg Brightness_Diff_Vote = (YAD > BRIGHT_TH) and where eg BRIGHT_TH=20]

EDIT: YAD is probably a bit weak a detector compared to others, so maybe voting system 2 out of 3 and skip the YAD metric.
The other 3 metrics are difference per pixel, whereas YAD is difference of field average.
EDIT: Yeh, skip the YAD metric.