Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 26th January 2013, 05:20   #1  |  Link
Mystery Keeper
Beyond Kawaii
 
Mystery Keeper's Avatar
 
Join Date: Feb 2008
Location: Russia
Posts: 724
TempLinearApproximate. Filter for temporal linear approximation between pixels.

Takes several frames and for each pixel calculates linear approximation of its values through time, then returns its value in the middle (unless close to beginning or end of clip) of that line. Meant mainly for denoising aid in motion compensated clips. If you use it on plain video - you'll just get heavy ghosting.

Only works on planar formats.

[USAGE]
Code:
TempLinearApproximate(clip, int radius=5, int plane=7, bool inLsb=false, bool outLsb=false)
radius: The size of neighborhood of the current frame. Approximation is made by (radius * 2 + 1) points, unless close to beginning or end - it is trimmed in these cases.

plane: The sum of three flags of planes to process. 1=Y, 2=U, 4=V.

inLsb: Set to true if input clip is in stacked 16 bit format.

outLsb: Set to true if you want output to be in stacked 16 bit format, whether input clip is stacked 16 bit or not.

Download TempLinearApproximate r6
Get the source code from Bitbucket repository.

[CHANGELOG]
Code:
r6: Full AviSynth 2.6 support.

r5: Added support for stacked 16 bit format.

r4: Fixed clamping issue changing white to black and black to white.

r3: Optimization.

r2: Fixed handling the frames pitch.

r1: Initial release.
__________________
...desu!

Last edited by Mystery Keeper; 27th March 2013 at 18:40.
Mystery Keeper is offline   Reply With Quote
Old 26th January 2013, 16:23   #2  |  Link
wOxxOm
Oz of the zOo
 
Join Date: May 2005
Posts: 208
There is a similar filter, TemporalSoften, so what are the advantages of TempLinearApproximate and in which cases will it do a better job?

Last edited by wOxxOm; 26th January 2013 at 16:25.
wOxxOm is offline   Reply With Quote
Old 26th January 2013, 20:48   #3  |  Link
Mystery Keeper
Beyond Kawaii
 
Mystery Keeper's Avatar
 
Join Date: Feb 2008
Location: Russia
Posts: 724
Quote:
Originally Posted by wOxxOm View Post
There is a similar filter, TemporalSoften, so what are the advantages of TempLinearApproximate and in which cases will it do a better job?
Similar, but far from same. I can not say anything about advantages yet. Right now it is just a test thing. The idea behind it is assumption that in noiseless unmoving source colour of pixel either stays the same or changes smoothly. Both cases give you a straight line on the temporal scale. Another idea is that noise oscillates around that line. What this filter does is finding that line in the oscillating noise and aligning pixel colour to the line.

As I said, it will do a good job in well motion compensated clip.
__________________
...desu!
Mystery Keeper is offline   Reply With Quote
Old 26th January 2013, 23:33   #4  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
Pitch is a unique property of each PVideoFrame, your code uses the pitch of your output frame for everything and of course it does not work when the input frames do not have the same pitch value.

Use this as a pitch processing torture test for any plugins you develop.
Code:
....
A=SelectEvery(3, 0).AddBorders(0,0, 16,0).Crop(0,0, -16,0)
B=SelectEvery(3, 1).AddBorders(0,0, 32,0).Crop(0,0, -32,0)
C=SelectEvery(3, 2).AddBorders(0,0, 64,0).Crop(0,0, -64,0)
Interleave(A, B, C)
....
IanB is offline   Reply With Quote
Old 27th January 2013, 02:19   #5  |  Link
Mystery Keeper
Beyond Kawaii
 
Mystery Keeper's Avatar
 
Join Date: Feb 2008
Location: Russia
Posts: 724
IanB, thank you. Am I safe with planes width and height?
__________________
...desu!
Mystery Keeper is offline   Reply With Quote
Old 27th January 2013, 03:19   #6  |  Link
Mystery Keeper
Beyond Kawaii
 
Mystery Keeper's Avatar
 
Join Date: Feb 2008
Location: Russia
Posts: 724
Fixed it. Works with IanB torture test too. Updated the post.
__________________
...desu!
Mystery Keeper is offline   Reply With Quote
Old 27th January 2013, 04:24   #7  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
Quote:
Originally Posted by Mystery Keeper View Post
Am I safe with planes width and height?
Width and Height are both properties of the PClip.

Hint:- You have structured your code with lots of work in the inner most loop. With some devious restructuring you might achieve a ten fold speed improvement. E.g. the if null test could be moved out entirely. The GetReadPtr and GetPitch values are constant for a given PVideoFrame, copy them out once to a local array. The index calculation H*pitch+W can be avoided by techniques like bumping the readptr's by their pitch's each time in the outer most loop. When using STL components always check in detail what you inherit under the covers, some are very good and expand to code equivalent to for(int i=0;i<K;i++), others are evil and resolve to a rats maze of deeply nested method calls.
IanB is offline   Reply With Quote
Old 27th January 2013, 11:57   #8  |  Link
Mystery Keeper
Beyond Kawaii
 
Mystery Keeper's Avatar
 
Join Date: Feb 2008
Location: Russia
Posts: 724
Thank you for suggestions, IanB. Done. New somewhat faster version.
__________________
...desu!
Mystery Keeper is offline   Reply With Quote
Old 29th January 2013, 11:26   #9  |  Link
Terka
Registered User
 
Join Date: Jan 2005
Location: cz
Posts: 704
im not able to load the dll.
Terka is offline   Reply With Quote
Old 29th January 2013, 13:39   #10  |  Link
Mystery Keeper
Beyond Kawaii
 
Mystery Keeper's Avatar
 
Join Date: Feb 2008
Location: Russia
Posts: 724
Quote:
Originally Posted by Terka View Post
im not able to load the dll.
How are you trying to load it, and what result do you get?
I scanned it with Dependency Walker, and it says you may need MSVCR110.dll and MSVCP110.dll - the MS Visual C Runtime.
__________________
...desu!

Last edited by Mystery Keeper; 29th January 2013 at 13:42.
Mystery Keeper is offline   Reply With Quote
Old 30th January 2013, 03:57   #11  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,664
I also couldn't load the plugin. When I tried, I got this error:
Code:
LoadPlugin: unable to load "TempLinearApproximate.dll", error=0x7e
I compiled it myself with MSVC 2010 (XP SP3), and now it works just fine. Perhaps a similar issue as this?
Reel.Deel is offline   Reply With Quote
Old 30th January 2013, 18:45   #12  |  Link
Mystery Keeper
Beyond Kawaii
 
Mystery Keeper's Avatar
 
Join Date: Feb 2008
Location: Russia
Posts: 724
Quote:
Originally Posted by Reel.Deel View Post
I also couldn't load the plugin. When I tried, I got this error:
Code:
LoadPlugin: unable to load "TempLinearApproximate.dll", error=0x7e
I compiled it myself with MSVC 2010 (XP SP3), and now it works just fine. Perhaps a similar issue as this?
Programs built with VS2012 don't work with XP? Never knew it. I'm on Windows 8, and yes, I built it with VS2012. Could you please upload your build so I could link it in here? mediafire.com preferably.
__________________
...desu!
Mystery Keeper is offline   Reply With Quote
Old 30th January 2013, 18:51   #13  |  Link
Rumbah
Registered User
 
Join Date: Mar 2003
Posts: 480
The first VS2012 update adds WinXP support.
Rumbah is offline   Reply With Quote
Old 31st January 2013, 01:29   #14  |  Link
Mystery Keeper
Beyond Kawaii
 
Mystery Keeper's Avatar
 
Join Date: Feb 2008
Location: Russia
Posts: 724
Tested my filter against TemporalSoften and TTempSmooth on BlankClip().AddGrain() with fixed seed for fair test. TemporalSoften just sucks. And judging by the resulting file size TempLinearApproximate did 8% better than TTempSmooth. For TTempSmooth I used the settings from MCTemporalDenoise function. On other hand, my filter gave some bright dots on the frames close to the beginning and the end. Quite possible with the pure noise oscillating between 0 and 255, but should never happen on real source.

Here goes proof.
__________________
...desu!
Mystery Keeper is offline   Reply With Quote
Old 31st January 2013, 01:43   #15  |  Link
LoRd_MuldeR
Software Developer
 
LoRd_MuldeR's Avatar
 
Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,248
Quote:
Originally Posted by Rumbah View Post
The first VS2012 update adds WinXP support.
But you still need a special option: The "Platform Toolset" needs to be set to "v110_xp" explicitly. It's that option that was added with Update-1.
__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊
LoRd_MuldeR is offline   Reply With Quote
Old 31st January 2013, 02:17   #16  |  Link
Robert Martens
Registered User
 
Join Date: Feb 2010
Location: New York
Posts: 116
Quote:
Originally Posted by Mystery Keeper View Post
On other hand, my filter gave some bright dots on the frames close to the beginning and the end. Quite possible with the pure noise oscillating between 0 and 255, but should never happen on real source.
I hate to be the bearer of bad news, but I've got a clip here that shows some spotting: http://www.mediafire.com/?8yfw392di0e31mc

I'm loading the file in single threaded Avisynth 2.6 (Alpha 4) with AVISource, through Cedocida 0.2.2 at its default settings, and calling TempLinearApproximate with no arguments. Some small sections of the clip that are black, or close to it, turn white, and vice versa. You can accentuate the effect by first loading the clip as RGB, then doing the planar conversion manually with PC levels before calling TLA:

Code:
AVISource("TLAspots.avi", pixel_type="RGB32").ConvertToYV12(matrix="PC.601")
Setting radius to 1 eliminates the problem. I also notice that the last two frames show a dark ghost of the pickup truck, offset to the right, that becomes more pronounced with larger radii. I decided to try TempLinearApproximate out of curiosity, but I don't do much video processing with filters like these, so I don't know if that's a symptom of the problem or if it's a reasonable thing to expect.

If you need something longer to work on, the test clip is the first ten frames of this one, but that small snippet shows the black<->white issue fairly well.
Robert Martens is offline   Reply With Quote
Old 31st January 2013, 05:26   #17  |  Link
Mystery Keeper
Beyond Kawaii
 
Mystery Keeper's Avatar
 
Join Date: Feb 2008
Location: Russia
Posts: 724
Robert, when I first read your post, I thought: "I bet he just used the filter as is right after loading video." Please read the description in the first post more carefully. You should only use this filter on motion compensated clip. Otherwise, ghosts are to be expected. Still, I tried your video, was surprised, but the black<->white issue does present and looks like glitch. Thank you. I'll look into it. My first guess is me forgetting to clamp linear function to [0, 255].
__________________
...desu!

Last edited by Mystery Keeper; 31st January 2013 at 05:28.
Mystery Keeper is offline   Reply With Quote
Old 31st January 2013, 05:50   #18  |  Link
Robert Martens
Registered User
 
Join Date: Feb 2010
Location: New York
Posts: 116
I did see that you mentioned a "likely undesired motion blur effect", but I thought that was in reference to the obvious blur seen over the entire image when the filter's applied to a clip that hasn't been prepared correctly; when I use the word "ghost" I'm referring in particular to the dark, negative image of the bright white truck seen only in the last few frames. If that's to be expected when this filter's applied incorrectly, my mistake, sorry I jumped the gun there.
Robert Martens is offline   Reply With Quote
Old 31st January 2013, 05:54   #19  |  Link
Mystery Keeper
Beyond Kawaii
 
Mystery Keeper's Avatar
 
Join Date: Feb 2008
Location: Russia
Posts: 724
Was right. Clamping issue. Fixed. New version. Please test if it works with XP now.
__________________
...desu!
Mystery Keeper is offline   Reply With Quote
Old 31st January 2013, 06:00   #20  |  Link
Mystery Keeper
Beyond Kawaii
 
Mystery Keeper's Avatar
 
Join Date: Feb 2008
Location: Russia
Posts: 724
Quote:
Originally Posted by Robert Martens View Post
I did see that you mentioned a "likely undesired motion blur effect", but I thought that was in reference to the obvious blur seen over the entire image when the filter's applied to a clip that hasn't been prepared correctly; when I use the word "ghost" I'm referring in particular to the dark, negative image of the bright white truck seen only in the last few frames. If that's to be expected when this filter's applied incorrectly, my mistake, sorry I jumped the gun there.
You see, the last frames have white track that moves out of these spots. My filter sees that as pixels with fading out white. It constructs a line with negative gain and takes its value near the end. That's what gives you the black ghost.
__________________
...desu!

Last edited by Mystery Keeper; 31st January 2013 at 08:22.
Mystery Keeper is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:51.


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