View Full Version : Deinterlacing PAL gives wave artifacts
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.
StainlessS
20th April 2021, 16:26
Here, removed YAD (Brightness diff metric), and added frames file writing for singlerate, and doublerate even and doubrate odd scene change.
Voting thresholds not tweaked [I only got a single scene change clip].
Avisource("clip3.mkv.avi")
o=last
assumetff()
### Config ###
LPD_Th = 10 # RT_LumaPixelsDifferent() Threshold, if corresponding pixels more different than this then is counted
# Voting Thresholds, if above these then VOTE is counted
V_YD_TH = 30.0
V_YCD_TH = 100.0
V_YPD_TH = 100.0
###
SUBS=True
WRITE=True
SFrames = ".\SingleRate.txt"
DFramesE = ".\DoubleRateEven.txt"
DFramesO = ".\DoubleRateOdd.txt"
############################
############################
############################
if(WRITE) {
RT_fileDelete(SFrames)
RT_fileDelete(DFramesE)
RT_fileDelete(DFramesO)
}
COUNT = 0 # COUNT valid only on forward ONLY scan
SSS="""
n = current_frame
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 fields
YCD = (1.0-YC)*255.0 # Difference by Correlation [0.0->255, max poss 512.0=-1.0 -ve correlation]
YPD = RT_LumaPixelsDifferent(Last,Last,n=n,y=0,n2=n,y2=1,interlaced=true,Thresh=LPD_Th) # Population [0->255.0] where pixels different by LPD_Th or more
VOTE_YD = (YD > V_YD_TH) ? 1:0
VOTE_YCD = (YCD > V_YCD_TH) ? 1:0
VOTE_YPD = (YPD > V_YPD_TH) ? 1:0
VOTE_CNT = VOTE_YD + VOTE_YCD + VOTE_YPD
SC = VOTE_CNT >= 2
COUNT = (SC) ? COUNT + 1 : COUNT
(SUBS)?RT_Subtitle("%d]\nYD =%7.3f\nYCD=%7.3f\nYPD=%7.3f\nVOTE_YD =%.1s\nVOTE_YCD=%.1s\nVOTE_YPD=%.1s\nVOTE_CNT=%d\nSceneChange=%s (COUNT=%d)",
\ n,YD,YCD,YPD,VOTE_YD!=0,VOTE_YCD!=0,VOTE_YPD!=0,VOTE_CNT,SC,COUNT) : NOP
if(WRITE && SC) {
RT_WriteFile(SFrames,"%d",n,Append=True)
RT_WriteFile(DFramesE,"%d",n*2,Append=True)
RT_WriteFile(DFramesO,"%d",n*2+1,Append=True)
}
Return Last
"""
Scriptclip(SSS)
#StackHorizontal(o,Last)
Return last
EDIT: Slight mods to comments
Frame 103
https://i.postimg.cc/50NyXWVW/f103.jpg (https://postimages.org/)
Frame 104
https://i.postimg.cc/Rh2Zp3nv/f104.jpg (https://postimages.org/)
Frame 105
https://i.postimg.cc/LXb9hqDj/f105.jpg (https://postimages.org/)
.\SingleRate.txt
104
.\DoubleRateEven.txt
208
\DoubleRateOdd.txt
209
Could just use result of BOB() [Maybe SelectEven/Odd if singlerate] to fix scene change frame using ClipClop(cmd=Frames) after your dienterlace pass.
zorr
20th April 2021, 21:28
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
Thanks, those links work. I will try the Quivers too but I'd like to start with a simpler filter just to see how it performs.
Annoyingly I cannot get even Defreq to work, it's the classic "FFT3DFilter: Can not load FFTW3.DLL". It used to work with 32bit Avisynth but not with the 64bit one which I'm using now. I have updated fftw3.dll in Windows/System32 to a 64bit version but I suspect I still may have a wrong version. Could someone provide a link to a version that is known to work with 64bit Windows 10 and 64bit Avisynth? Here's the log from AvisynthInfoTool if it helps:
[OS/Hardware info]
Operating system: Windows 10 (x64) (Build 19041)
CPU: AMD Ryzen 9 3900X 12-Core Processor / Ryzen 9 (Matisse)
MMX, MMXEXT, SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, SSE4A, FMA3, RDSEED, ADX, AVX, AVX2
12 physical cores / 24 logical cores
[Avisynth info]
VersionString: AviSynth+ 3.7.0 (r3382, 3.7, x86_64)
VersionNumber: 2.60
File / Product version: 3.7.0.0 / 3.7.0.0
Interface Version: 8
Multi-threading support: Yes
Avisynth.dll location: C:\WINDOWS\SYSTEM32\avisynth.dll
Avisynth.dll time stamp: 2021-01-11, 21:36:39 (UTC)
PluginDir2_5 (HKLM, x64): E:\AviSynth\AVSPLUS370_x64\plugins
PluginDir+ (HKLM, x64): E:\AviSynth\AVSPLUS370_x64\plugins
[C++ 2.5 Plugins (64 Bit)]
E:\AviSynth\AVSPLUS370_x64\plugins\defreq.dll [2007-05-22]
[C++ 2.6 Plugins (64 Bit)]
E:\AviSynth\AVSPLUS370_x64\plugins\AddGrainC.dll [1.8.3.0]
E:\AviSynth\AVSPLUS370_x64\plugins\avsresize.dll [0.0.0.0]
E:\AviSynth\AVSPLUS370_x64\plugins\avstimer.dll [2018-09-11]
E:\AviSynth\AVSPLUS370_x64\plugins\ConvertStacked.dll [2021-01-11]
E:\AviSynth\AVSPLUS370_x64\plugins\DePan.dll [2.13.1.6]
E:\AviSynth\AVSPLUS370_x64\plugins\DePanEstimate.dll [2.10.0.4]
E:\AviSynth\AVSPLUS370_x64\plugins\DirectShowSource.dll [2021-01-11]
E:\AviSynth\AVSPLUS370_x64\plugins\EEDI2.dll [1.0.0.0]
E:\AviSynth\AVSPLUS370_x64\plugins\eedi3.dll [0.9.2.3]
E:\AviSynth\AVSPLUS370_x64\plugins\ffms2.dll [2020-08-22]
E:\AviSynth\AVSPLUS370_x64\plugins\fft3dfilter.dll [2.8.0.0]
E:\AviSynth\AVSPLUS370_x64\plugins\ImageSeq.dll [2021-01-11]
E:\AviSynth\AVSPLUS370_x64\plugins\KNLMeansCL.dll [2021-04-19]
E:\AviSynth\AVSPLUS370_x64\plugins\masktools2.dll [2.2.26.0]
E:\AviSynth\AVSPLUS370_x64\plugins\mvtools2.dll [2.7.44.0]
E:\AviSynth\AVSPLUS370_x64\plugins\neo-dfttest.dll [1.0.0.0]
E:\AviSynth\AVSPLUS370_x64\plugins\neo-fft3d.dll [1.0.0.0]
E:\AviSynth\AVSPLUS370_x64\plugins\nnedi3.dll [0.9.4.57]
E:\AviSynth\AVSPLUS370_x64\plugins\RawSourcePlus.dll [1.0.0.0]
E:\AviSynth\AVSPLUS370_x64\plugins\RgTools.dll [1.1.0.0]
E:\AviSynth\AVSPLUS370_x64\plugins\SangNom2.dll [0.6.0.0]
E:\AviSynth\AVSPLUS370_x64\plugins\Shibatch.dll [2021-01-11]
E:\AviSynth\AVSPLUS370_x64\plugins\TDeint.dll [1.8.0.0]
E:\AviSynth\AVSPLUS370_x64\plugins\TimeStretch.dll [2021-01-11]
E:\AviSynth\AVSPLUS370_x64\plugins\VDubFilter.dll [2021-01-11]
E:\AviSynth\AVSPLUS370_x64\plugins\yadifmod2.dll [0.2.7.0]
[Scripts (AVSI)]
E:\AviSynth\AVSPLUS370_x64\plugins\AiUpscale.avsi [2020-07-25]
E:\AviSynth\AVSPLUS370_x64\plugins\colors_rgb.avsi [2020-03-02]
E:\AviSynth\AVSPLUS370_x64\plugins\GMSD.avsi [2021-04-06]
E:\AviSynth\AVSPLUS370_x64\plugins\IQA_downsample.avsi [2021-03-27]
E:\AviSynth\AVSPLUS370_x64\plugins\MDSI.avsi [2021-03-27]
E:\AviSynth\AVSPLUS370_x64\plugins\mtmodes.avsi [2021-04-07]
E:\AviSynth\AVSPLUS370_x64\plugins\QTGMC.avsi [2021-04-19]
E:\AviSynth\AVSPLUS370_x64\plugins\RoundHalfToEven.avsi [2021-03-27]
E:\AviSynth\AVSPLUS370_x64\plugins\Zs_RF_Shared.avsi [2021-04-19]
[Uncategorized DLLs (64 Bit)]
E:\AviSynth\AVSPLUS370_x64\plugins\libfftw3-3.dll [2021-03-27]
E:\AviSynth\AVSPLUS370_x64\plugins\libfftw3f-3.dll [2021-03-27]
[Uncategorized files]
E:\AviSynth\AVSPLUS370_x64\plugins\ffms2.lib [2020-08-22]
E:\AviSynth\AVSPLUS370_x64\plugins\ffmsindex.exe [2020-08-22]
[Plugin errors/warnings]
____________________________________________________________________________________________
Function duplicates:
"undefined" : "[InternalFunction]"
"Undefined" : "E:\AviSynth\AVSPLUS370_x64\plugins\Zs_RF_Shared.avsi"
____________________________________________________________________________________________
'E:/AviSynth/AVSPLUS370_x64/plugins/KNLMeansCL.dll' cannot be used as a plugin for AviSynth.
____________________________________________________________________________________________
StainlessS
20th April 2021, 22:25
Zorr,
Some plugs use the same dll via different names,
fftw3.dll
libfftw3f-3.dll
And a few months back, another plug used yet another name, I dont recall which plug it was.
EDIT: Here [used by KPassFilterCL, Passfilter.dll]:- https://forum.doom9.org/showthread.php?p=1929800#post1929800
Some more recent plugs can use either of the two first mentioned names.
zorr
20th April 2021, 23:28
Zorr,
Some plugs use the same dll via different names,
fftw3.dll
libfftw3f-3.dll
Yes it's probably something like that. Because for example FFT3DFilter is working and it's using the same fftw3 library.
Just to be clear, I have downloaded the latest available (v3.3.5) 64 bit dlls from http://www.fftw.org/install/windows.html. There's source available for 3.3.9 but seems there are no binaries for that. In the package there are 3 dll files:
libfftw3-3.dll
libfftw3f-3.dll
libfftw3l-3.dll
I took libfftw3-3.dll and renamed it to fftw3.dll and put it into windows/System32. Are you suggesting that I should take the same file, rename it to libfftw3f-3.dll and put it into System32 also? Note that the package itself contains a file with that name, so it must be a different dll right?
EDIT:
The only link to 64bit Defreq I was able to find was in this post (https://forum.doom9.org/showthread.php?p=1006019#post1006019).
Interestingly the package claims to contain x64 version of fftw3.dll but it seems to be x86 - I get "Avisynth open failure: Cannot load a 32 bit DLL in 64 bit Avisynth..." when it's placed into Avisynth plugins folder. If I place it only to System32 the error message is the original "Can not load FFTW3.DLL". I think this means Defreq is not looking for it at System32 at all, and instead looking for it in the plugins folder.
EDIT2:
I can't find x64 Quivers either, does anybody have a link?
EDIT3:
Ah, the Quivers are within ManyPlus plugin. And x64 version is available. :)
Atlantis
21st April 2021, 01:58
I see there are interest in this. So for research and testing purposes I post a longer clip for people who want to do academic stuff!
2 minutes, includes wave patterns, clean cuts and bad combed cuts.
https://www.mediafire.com/file/nk1gfnek2orz5nd/clip.mkv/file
StainlessS
21st April 2021, 02:06
by zorr
libfftw3-3.dll and renamed it to fftw3.dll
Wrong one, remove it.
libfftw3-3.dll
libfftw3f-3.dll # THIS ONE, Copy as is to x64 system32 and make another copy and rename to fftw3.dll also in system32
libfftw3l-3.dll
EDIT: Remove this lot from plugins, [except ffmsindex.exe, if you use it via command line from plugins directory(ffms2 indexer)]
[Uncategorized DLLs (64 Bit)]
E:\AviSynth\AVSPLUS370_x64\plugins\libfftw3-3.dll [2021-03-27]
E:\AviSynth\AVSPLUS370_x64\plugins\libfftw3f-3.dll [2021-03-27]
[Uncategorized files]
E:\AviSynth\AVSPLUS370_x64\plugins\ffms2.lib [2020-08-22]
E:\AviSynth\AVSPLUS370_x64\plugins\ffmsindex.exe [2020-08-22]
StainlessS
21st April 2021, 05:47
Bit more tinker, Pre-scan on short bit of whole clip, to judge best thresholds to use for full clip.
#Avisource("clip3.mkv.avi") # Original Short clip
Avisource("clip.mkv.avi") # Longer one, but still short piece of whole clip.
o=last
assumetff()
### Config ###
SUBS = True
WRITE = True
LPD_Th = 10 # RT_LumaPixelsDifferent() Threshold, if corresponding pixels more different than this then is counted
SHOWMINMAX = True # Show Metric minimums where scenechange detected, AND metrics Maximums where NO Scenechange detected [tweak thresholds]
# Voting Thresholds, if above these then VOTE is for SceneChange.
V_YD_TH = 32.0 # I've made these the average of MAX when NO Scenechage and MIN when SceneChange, as shown when SHOWMINMAX=True.
V_YCD_TH = 107.0 # Ditto
V_YPD_TH = 162.0 # Ditto, # If you change LPD_Th, then re-scan and re-calc V_YPD_TH as Ave of YPD_MIN and YPD_MAX
# Intent, allow choose best setting for metric pre-scan on shorter piece of your clip. Then do full scan to write files.
# Can use Vdub2 Video Analysis pass for pre-scan and scan proper.
###
SFrames = ".\SingleRate.txt"
DFramesE = ".\DoubleRateEven.txt"
DFramesO = ".\DoubleRateOdd.txt"
############################
############################
############################
if(WRITE) {
SFrames = SFrames.RT_GetFullPathName
DFramesE = DFramesE.RT_GetFullPathName
DFramesO = DFramesO.RT_GetFullPathName
RT_fileDelete(SFrames)
RT_fileDelete(DFramesE)
RT_fileDelete(DFramesO)
}
YD_MIN = 255.0
YCD_MIN = 512.0
YPD_MIN = 255.0
YD_MAX = 0.0
YCD_MAX = 0.0
YPD_MAX = 0.0
COUNT = 0 # COUNT valid only on forward ONLY scan
SSS="""
n = current_frame
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 fields
YCD = (1.0-YC)*255.0 # Difference by Correlation [0.0->255, max poss 512.0=-1, -ve correlation]
YPD = RT_LumaPixelsDifferent(Last,Last,n=n,y=0,n2=n,y2=1,interlaced=true,Thresh=LPD_Th) # Population [0->255.0] where pixels different by LPD_Th or more
VOTE_YD = (YD > V_YD_TH) ? 1:0
VOTE_YCD = (YCD > V_YCD_TH) ? 1:0
VOTE_YPD = (YPD > V_YPD_TH) ? 1:0
VOTE_CNT = VOTE_YD + VOTE_YCD + VOTE_YPD
SC = VOTE_CNT >= 2
COUNT = (SC) ? COUNT + 1 : COUNT
(SUBS)?RT_Subtitle("%d]\nYD =%7.3f\nYCD=%7.3f\nYPD=%7.3f\nVOTE_YD =%.1s\nVOTE_YCD=%.1s\nVOTE_YPD=%.1s\nVOTE_CNT=%d\nSceneChange=%s (COUNT=%d)",
\ n,YD,YCD,YPD,VOTE_YD!=0,VOTE_YCD!=0,VOTE_YPD!=0,VOTE_CNT,SC,COUNT) : NOP
if(WRITE && SC) {
RT_WriteFile(SFrames,"%d",n,Append=True)
RT_WriteFile(DFramesE,"%d",n*2,Append=True)
RT_WriteFile(DFramesO,"%d",n*2+1,Append=True)
}
if(SHOWMINMAX) {
if(SC) {
YD_MIN = ( YD < YD_MIN) ? YD : YD_MIN
YCD_MIN = (YCD < YCD_MIN) ? YCD : YCD_MIN
YPD_MIN = (YPD < YPD_MIN) ? YPD : YPD_MIN
} else {
YD_MAX = ( YD > YD_MAX) ? YD : YD_MAX
YCD_MAX = (YCD > YCD_MAX) ? YCD : YCD_MAX
YPD_MAX = (YPD > YPD_MAX) ? YPD : YPD_MAX
}
RT_Subtitle(" SC: VD_MIN = %7.3f : VCD_MIN = %7.3f : VPD_MIN = %7.3f\n" + \
"!SC: VD_MAX = %7.3f : VCD_MAX = %7.3f : VPD_MAX = %7.3f\n" + \
"\a!SET: V_YD_TH= %7.3f : V_VCD_TH= %7.3f : V_VPD_TH= %7.3f",
\ YD_MIN,YCD_MIN,YPD_MIN,YD_MAX,YCD_MAX,YPD_MAX,
\ Round((YD_MIN+YD_MAX)/2.0),Round((YCD_MIN+YCD_MAX)/2.0),Round((YPD_MIN+YPD_MAX)/2.0),
\ align=1)
}
Return Last
"""
Scriptclip(SSS)
#StackHorizontal(o,Last)
Return last
Metrics on Final frame
https://i.postimg.cc/ZqPDKPCB/Last-Frame.jpg (https://postimages.org/)
EDIT: NOTED SceneChanges are of course mid frame (bottom field) scene changes. [the other scene changes are ignored, not detected]
(just for anybody thinking that this is a standard scene change detector, it aint)
EDIT: And the last of 3 detected mid frame scene changes in 3002 frames.
https://i.postimg.cc/LXHQqq1y/Frame1744.jpg (https://postimages.org/)
SingleRate.txt
492
581
1744
DoubleRateEven.txt
984
1162
3488
DoubleRateOdd.txt
985
1163
3489
Atlantis
21st April 2021, 19:00
I have to share another clip for completeness.
https://www.mediafire.com/file/hat1gxxndxppgmw/clip2.mkv/file
This is a dark clip where bad scene change detection is more difficult. This script did not work with this part of the video:
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")
wonkey_monkey
21st April 2021, 21:38
Had a stab at a hunch, more for fun than anything else, not intended to be a real solution (left is QTGMC output, right is my "filter"):
https://i.imgur.com/LiWKTe8.png
Atlantis
21st April 2021, 22:27
Not enough! :)
zorr
21st April 2021, 23:12
libfftw3-3.dll
libfftw3f-3.dll # THIS ONE, Copy as is to x64 system32 and make another copy and rename to fftw3.dll also in system32
libfftw3l-3.dll
SUCCESS! Defreq (and FFT3DFilter) works! :thanks:
I already have some promising results, stay tuned.
StainlessS
22nd April 2021, 00:47
OK, dropped two of the 3 voting metrics, just kept the difference by correlation metric as it is less affected by dark sequences.
I've mixed it into PDR's script, also shows metrics so is easier to mod if necessary. [Scriptclip is a lot more flexible than ConditinslFilter].
LoadPlugin(".\BWDif.dll")
##########
V_YCD_TH = 107.0 # Detect Threshold
SHOW = True # Metrics
STACK= True
##########
A=Avisource("clip3.mkv.avi") # Short clip
B=Avisource("clip.mkv.avi") # Longer one
C=Avisource("clip2.mkv.avi") # third one
A ++ B ++ C # All 3 clips [in supplied order]
Assumetff()
#########
o=Last
deint=bwdif(field=3, edeint=nnedi3(field=3))
deintblend=merge(deint.selecteven, deint.selectodd)
deinteven = deint.selecteven()
SSS= """
n = current_frame
YC = RT_LumaCorrelation(Last,Last,n=n,y=0,n2=n,y2=1,interlaced=True) # Correlation Between Even and Odd fields (ORIGINAL SOURCE CLIP)
YCD = (1.0-YC)*255.0 # Difference by Correlation [0.0->255, max poss 512.0=-1, -ve correlation]
SC = (YCD > V_YCD_TH)
(SC) ? deinteven : deintblend
(SHOW) ? RT_Subtitle("%d] %.3f %s",n,YCD,(SC)?Chr(7)+"!*** SCENECHANGE ***":"") : NOP
return Last
"""
Scriptclip(o, SSS) # Detect on o, o = original src, not deinterlaced
Return (STACK) ? StackHorizontal(o,Last) : Last
EDIT:
And you can maybe use this to pre-scan longer clip to estimate best V_YCD_TH threshold.
I've modified the SingleRate.txt output to be ClipClop format.
A=Avisource("clip3.mkv.avi") # Short clip
B=Avisource("clip.mkv.avi") # Longer one
C=Avisource("clip2.mkv.avi") # third one
A ++ B ++ C # All 3 clips [in supplied order]
assumetff()
o=last
### Config ###
SUBS = True
WRITE = True
SHOWMINMAX = True # Show Metric minimums where scenechange detected, AND metrics Maximums where NO Scenechange detected [tweak thresholds]
V_YCD_TH = 107.0 #
###
SFrames = ".\SingleRate.txt"
############################
if(WRITE) {
SFrames = SFrames.RT_GetFullPathName
RT_fileDelete(SFrames)
}
YCD_MIN = 512.0
YCD_MAX = 0.0
COUNT = 0 # COUNT valid only on forward ONLY scan
SSS="""
n = current_frame
YC = RT_LumaCorrelation(Last,Last,n=n,y=0,n2=n,y2=1,interlaced=True) # Correlation Between Even and Odd fields
YCD = (1.0-YC)*255.0 # Difference by Correlation [0.0->255, max poss 512.0=-1, -ve correlation]
SC = (YCD > V_YCD_TH)
COUNT = (SC) ? COUNT + 1 : COUNT
(SUBS)?RT_Subtitle("%d]\nYCD=%7.3f\nSceneChange=%s (COUNT=%d)",n,YCD,SC,COUNT) : NOP
if(WRITE && SC) { RT_WriteFile(SFrames,"1 %d",n,Append=True) } # Write Frame file in Clipclop style.
if(SHOWMINMAX) {
if(SC) { YCD_MIN = (YCD < YCD_MIN) ? YCD : YCD_MIN }
else { YCD_MAX = (YCD > YCD_MAX) ? YCD : YCD_MAX }
RT_Subtitle(" SC: VCD_MIN = %7.3f\n!SC: VCD_MAX = %7.3f\n\a!SET: V_VCD_TH= %7.3f",
\ YCD_MIN,YCD_MAX,Round((YCD_MIN+YCD_MAX)/2.0),align=1)
}
Return Last
"""
Scriptclip(SSS)
Return last
EDIT:
And here a Clipclop script, one advantage is that you can remove or add frame numbers to the clipclop SingleRate.txt
file, so easily modded if problem frames found. ClipClop needs frames in this format [where 1 is FIXED, and 6699 is frame number
where mid frame scenechange lives].
1 6699
Clipclop script [USES SingleRate.txt generated by 2nd script]
# Requires ClipClop
LoadPlugin(".\BWDif.dll")
##########
SHOW = True
STACK = true
Frames = ".\SingleRate.txt"
Frames = Frames.RT_GetFullPathName
A=Avisource("clip3.mkv.avi") # Short clip
B=Avisource("clip.mkv.avi") # Longer one
C=Avisource("clip2.mkv.avi") # third one
A ++ B ++ C # All 3 clips [in supplied order]
Assumetff()
#########
o=Last
deint=bwdif(field=3, edeint=nnedi3(field=3))
deintblend=merge(deint.selecteven, deint.selectodd)
deinteven = deint.selecteven()
ClipClop(deintblend,deinteven,cmd=Frames,Show=SHOW)
Return (STACK) ? StackHorizontal(o,Last) : Last
EDIT: The (1.0 - YC) thing is called Pearson's Distance [see WikiPedia]:- https://en.wikipedia.org/wiki/Pearson_correlation_coefficient#Pearson's_distance
We scale it by 255.0 to be more familiar [although max possible is 512.0 where correlation is -ve, -1.0, ie (1 - (-1)) * 255.0].
Pearson's distance
A distance metric for two variables X and Y known as Pearson's distance can be defined from their correlation coefficient as[37]
dx,y = 1 − ρx,y.
Considering that the Pearson correlation coefficient falls between [−1, +1], the Pearson distance lies in [0, 2]. The Pearson distance has been used in cluster analysis and data detection for communications and storage with unknown gain and offset[38]
Atlantis
22nd April 2021, 03:25
The first script works I suppose it's for inspection. 8 BW stacked images. The text are not readable.
The second script doesn't work. Can't find RT_GetFullPathName function.
poisondeathray
22nd April 2021, 03:49
The second script doesn't work. Can't find RT_GetFullPathName function.
You need RT_Stats. See bottom of StainlessS's posts, there are mediafire and sendspace links to a directory of his plugins
StainlessS
22nd April 2021, 11:32
Thanx PDR.
Use this one [RT_Stats]:- https://www.mediafire.com/file/xa3t1wx234gyzfq/RT_Stats_25%252626_x86_x64_dll_v2.00Beta13_20201229.zip/file
ClipClop:- https://www.mediafire.com/file/0992cb3ge40qh11/ClipClop_x86_x64_dll_v1-26_20181222.zip/file
If you already have BWDif.dll in plugins, remove the LoadPlugin line.
zorr
24th April 2021, 15:15
https://i.postimg.cc/m2jdkS7j/how-it-started.png
Making progress with Defreq and Zopti. I'm still trying to remove that slight vertical ringing on the door.
Atlantis
24th April 2021, 20:41
What is doing the deinterlacing? Do you get blended fields at some of the scene changes or do you get clean cut?
zorr
24th April 2021, 22:53
What is doing the deinterlacing? Do you get blended fields at some of the scene changes or do you get clean cut?
I used QTGMC with default settings, mainly because it makes the moire pattern more visible. You can use bwdif too if you prefer it.
I just checked the clips you've shared, there seemed to be no problems with the scene changes.
Atlantis
24th April 2021, 23:24
Yes there are. Some scene changes are 2 fields from 2 different scenes. QTGMC does the de-interlacing correctly. You don't see those blended scenes in QTGMC result.
zorr
24th April 2021, 23:43
Yes there are. Some scene changes are 2 fields from 2 different scenes. QTGMC does the de-interlacing correctly. You don't see those blended scenes in QTGMC result.
Yes that's what I meant, there are no problems with the scene changes when using QTGMC. So if QTGMC + Defreq is used, that solves the scene change problem also.
Atlantis
25th April 2021, 01:51
Yes. That would be the best possible result.
Atlantis
25th April 2021, 01:55
Did not know that Defreq works on the progressive clips. If it can work on interlaced materials, the best would be to use it before deinterlacing on the original.
zorr
25th April 2021, 02:21
Did not know that Defreq works on the progressive clips. If it can work on interlaced materials, the best would be to use it before deinterlacing on the original.
It does work on both. In this case you have to do the moire removal before you do deinterlacing, otherwise QTGMC interprets the moving moire pattern as actual movement and the textures behind it move also. I noticed this after I had done a lot of testing where Defreq was AFTER deinterlacing. :mad: The current version does Defreq both before and after.
BTW the door is now fixed but I noticed another problem on a different frame.
kedautinh12
25th April 2021, 02:27
Can you share script QTGMC + Defreq and some image before and after you used it?? zorr
StainlessS
25th April 2021, 14:02
Here is frame 2768 [from my ClipClop script] using PDR BWDif script, on Postimge as PNG.
https://i.postimg.cc/B88QmxCs/2769.png (https://postimg.cc/B88QmxCs)
[2768 is source frame for Zorr image - EDIT: Not a mid frame scenechange]
Left Source [interlaced], right BWDif with Even/Odd Merge to singlerate.
EDIT: Looks good enough to me, and no moire. [PDR's BWDif + E/O merge works great, don't tknow if it requires QTGMC + DeFreq]
zorr
25th April 2021, 23:20
Can you share script QTGMC + Defreq and some image before and after you used it?? zorr
Here's the current version.
orig = FFVideoSource("Clip1.mkv")
fields = orig.SeparateFields()
# create blend version (for comparison, also for Zopti)
blend = FieldDeinterlace(orig)
blend = QTGMC(blend, InputType=2, TR2=2)
# pass 1 with Defreq, apply to separate fields
fx = 57 # optimize fx = _n_ | 0..100 | fx
fy = -27 # optimize fy = _n_ | -100..100 | fy
dx = 19 # optimize dx = _n_ | 5..50 | dx
dy = 22 # optimize dy = _n_ | 5..50 | dy
sharp = 2
defreq = Defreq(fields, fx=fx, fy=fy, dx=dx, dy=dy, sharp=sharp, show=0, info=false)
# boost result by amplifying whatever Defreq did
boost = 60/100.0 # optimize boost = _n_/100.0 | 0..100 | boost
diff = mt_makediff(defreq, fields, chroma="-127")
defreq = defreq.mt_adddiff(diff)
boosted = Overlay(fields, defreq, opacity=boost)
# deinterlace
deinterlaced = SelectOdd(QTGMC(boosted.weave()))
orig_deinterlaced = SelectOdd(QTGMC(fields.weave()))
# create mask
diff = mt_makediff(deinterlaced, orig_deinterlaced, chroma="-127")
diff = diff.mt_adddiff(diff)
mask = mt_lut(diff, expr="x 128 - abs 6 > 255 0 ?")
mask = mt_expand(mask)
mask = mt_expand(mask)
mask = mt_inpand(mask, chroma="-127")
# pass 2 with Defreq, apply to deinterlaced frames
fx = 48 # optimize fx = _n_ | 0..80 | fx
fy = -11 # optimize fy = _n_ | -80..0 | fy
dx = 10 # optimize dx = _n_ | 5..50 | dx
dy = 16 # optimize dy = _n_ | 5..50 | dy
sharp = 2
defreq2 = Defreq(deinterlaced, fx=fx, fy=fy, dx=dx, dy=dy, sharp=sharp, show=0, info=false)
# combine with pass 1 using mask
defreq_masked = Overlay(deinterlaced, defreq2, mask=mask)
# final result
return defreq_masked
# compare different phases
return Interleave(
\ orig_deinterlaced.Subtitle("QTGMC only"),
\ diff.Subtitle("detected pattern"),
\ mask.Subtitle("mask"),
\ deinterlaced.Subtitle("after pass 1"),
\ defreq2.Subtitle("after pass 2"),
\ defreq_masked.Subtitle("final masked result"),
\ blend.Subtitle("blend deinterlaced"))
I have tested it on Clip1 so far and it's pretty good, there's only one small detail that needs some attention. I noticed there are different patterns in the other clips and they are not all removed by this version. I will take a look at them once I'm satisfied with Clip1.
Comparison shots below, the same frame as before but the door (and some other parts) are better.
https://i.postimg.cc/8510Rbwm/01-combined-before.png
https://i.postimg.cc/1XX7T5kg/01-combined-after.png
Some details about the script: I noticed that while Defreq can detect the correct pattern to remove it always doesn't do a perfect job at removing it. It's probably because it only removes "peaks" and scales the amplitudes so that they match the background level instead of removing them altogether. Therefore I added a "boost" which amplifies whatever changes Defreq did to the frame. This boost parameter was also optimized by Zopti to find the best value.
The first pass does a pretty good job at removing the pattern but a second pass is needed to remove the rest (and there's still a little bit left if you look at the right places). The problem is that the second pass also introduces interference patterns elsewhere (the door problem). I fixed that by making a mask which allows the correction to be applied only to those locations where it is needed. The mask is just a quick hack and could probably be improved but it seems to do its job just fine.
You can see the different phases of the script and the mask if you comment out the second last line ("return defreq_masked").
The final problem area I'm focusing on is that the first pass also creates some interference patterns on some frames. Below you can see one such example. On the left is the output of the script and on the right is blend deinterlaced version which doesn't have the pattern.
https://i.postimg.cc/pLzG3S6B/02-combined-issue.png
So while you can get pretty impressive results with Defreq it's not a walk in the park. As vcmohan stated: "As a sharp discontinuity requires all frequencies of spectrum to be present, any filtering that affects the balance can create undesirable ringing." This is just the case here, the crown has a sharp edge and removing some frequencies made it ring.
I think this can be fixed with another mask for pass 1. It can be created with Defreq using yet another set of parameters. I will let Zopti figure out the best combination. :D
I also tested the cutx and cuty parameters of Defreq but didn't see use for them. They make the result blurrier but we don't want that. By the way the documentation states that the max value for cutx and cuty is 300 but actually it's 200.
EDIT: forgot to mention that the script returns 25fps so that it can be compared to the blend deinterlaced frames. You can take out SelectOdd() calls to return 50fps but then it's out of sync with the blend version.
Frank62
26th April 2021, 10:58
Looks great!
My idea (again, in this case to remove the residual pattern): Turn the picture before DeFreq so that the moire is exactly vertical. Would be worth a try.
Atlantis
26th April 2021, 11:19
Boy I did well by not touching DeFreq! :scared::D
kedautinh12
17th July 2021, 11:32
Here is frame 2768 [from my ClipClop script] using PDR BWDif script, on Postimge as PNG.
https://i.postimg.cc/B88QmxCs/2769.png (https://postimg.cc/B88QmxCs)
[2768 is source frame for Zorr image - EDIT: Not a mid frame scenechange]
Left Source [interlaced], right BWDif with Even/Odd Merge to singlerate.
EDIT: Looks good enough to me, and no moire. [PDR's BWDif + E/O merge works great, don't tknow if it requires QTGMC + DeFreq]
Can you share me final script??
StainlessS
17th July 2021, 14:26
Was from post #62, ie
EDIT:
And here a Clipclop script, one advantage is that you can remove or add frame numbers to the clipclop SingleRate.txt
file, so easily modded if problem frames found. ClipClop needs frames in this format [where 1 is FIXED, and 6699 is frame number
where mid frame scenechange lives].
1 6699
Clipclop script [USES SingleRate.txt generated by 2nd script]
# Requires ClipClop
LoadPlugin(".\BWDif.dll")
##########
SHOW = True
STACK = true
Frames = ".\SingleRate.txt"
Frames = Frames.RT_GetFullPathName
A=Avisource("clip3.mkv.avi") # Short clip
B=Avisource("clip.mkv.avi") # Longer one
C=Avisource("clip2.mkv.avi") # third one
A ++ B ++ C # All 3 clips [in supplied order]
Assumetff()
#########
o=Last
deint=bwdif(field=3, edeint=nnedi3(field=3))
deintblend=merge(deint.selecteven, deint.selectodd)
deinteven = deint.selecteven()
ClipClop(deintblend,deinteven,cmd=Frames,Show=SHOW)
Return (STACK) ? StackHorizontal(o,Last) : Last
kedautinh12
17th July 2021, 16:04
Thanks, i will try
kedautinh12
20th July 2021, 04:29
I don't seen any SingleRate.txt creat by script 2
StainlessS
20th July 2021, 06:40
SingleRate.txt is created via the 2nd script in post #62.
kedautinh12
20th July 2021, 07:28
I used script 2 but don't seen SingleRate.txt. I think your scripts use for twopass encode. So sad cause i use one pass encode
StainlessS
20th July 2021, 12:41
OK, here TwoPass
LoadPlugin(".\BWDif.dll")
##########
A=Avisource("clip3.mkv.avi") # Short clip
B=Avisource("clip.mkv.avi") # Longer one
C=Avisource("clip2.mkv.avi") # third one
A ++ B ++ C # All 3 clips [in supplied order]
assumetff()
o=last
############################
### Config ###
V_YCD_TH = 107.0 #
FINAL = False # SWITCH OFF ALL THE OTHER STUFF if TRUE
SUBS = True
SHOWMINMAX = True # Show Metric minimums where scenechange detected, AND metrics Maximums where NO Scenechange detected [tweak thresholds]
###
CLIPCLOPSHOW = True
STACK = True
SFrames = ".\SingleRate.txt"
############################
If (FINAL) {
SUBS = FALSE
SHOWMINMAX = FALSE
CLIPCLOPSHOW = False
STACK = FALSE
}
SFrames = SFrames.RT_GetFullPathName
RT_fileDelete(SFrames)
YCD_MIN = 512.0
YCD_MAX = 0.0
COUNT = 0 # COUNT valid only on forward ONLY scan
SSS="""
n = current_frame
YC = RT_LumaCorrelation(Last,Last,n=n,y=0,n2=n,y2=1,interlaced=True) # Correlation Between Even and Odd fields
YCD = (1.0-YC)*255.0 # Difference by Correlation [0.0->255, max poss 512.0=-1, -ve correlation]
SC = (YCD > V_YCD_TH)
COUNT = (SC) ? COUNT + 1 : COUNT
(SUBS)?RT_Subtitle("%d]\nYCD=%7.3f\nSceneChange=%s (COUNT=%d)",n,YCD,SC,COUNT) : NOP
if(SC) { RT_WriteFile(SFrames,"1 %d",n,Append=True) } # Write Frame file in Clipclop style.
if(SHOWMINMAX) {
if(SC) { YCD_MIN = (YCD < YCD_MIN) ? YCD : YCD_MIN }
else { YCD_MAX = (YCD > YCD_MAX) ? YCD : YCD_MAX }
RT_Subtitle(" SC: VCD_MIN = %7.3f\n!SC: VCD_MAX = %7.3f\n\a!SET: V_VCD_TH= %7.3f",
\ YCD_MIN,YCD_MAX,Round((YCD_MIN+YCD_MAX)/2.0),align=1)
}
Return Last
"""
Scriptclip(SSS)
RT_ForceProcess # force Pass 1
# Pass 2
deint=bwdif(field=3, edeint=nnedi3(field=3))
deintblend=merge(deint.selecteven, deint.selectodd)
deinteven = deint.selecteven()
ClipClop(deintblend,deinteven,cmd=SFrames,Show=CLIPCLOPSHOW)
(STACK) ? StackHorizontal(o,Last) : Last
Return last
kedautinh12
21st July 2021, 05:55
It's work, many thanks
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.