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 Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 12th August 2003, 23:41   #1  |  Link
kevina
Registered User
 
Join Date: Jun 2003
Posts: 71
New Filters: Conditional Temporal Median Filter and DeSpot filter

I have created a Conditional Temporal Median Filter. The filter is designed to remove temporal noise in the form of small dots and streaks found in some videos. A common cause of this is dirty VHS heads but I have also seen small black or white streaks in broadcast material.

You can find it at http://kevin.atkinson.dhs.org/temporal_median/.

It requires my C API Plugin available at http://kevin.atkinson.dhs.org/avisynth_c/.

Please test it out and let me know what you think. It may occasionally cause AviSynth to crash, however it is definitely usable. It will generally only crash when previewing the video (ie lots of back and forth motion in the timeline). To be safe just reopen the script file before saving your final copy. I will release another version once I track down this bug, of course. Update: This bug is now fixed as of version 0.92

It works as follows:

1) Find pixes that are different from its neighbors by at least P1.

1b) Enlarge outliers based on P2.

2) Determine the size of the specks and reject all those larger than PWIDTHxPHEIGHT

3) Find moving areas of an image by simply comparing each pixel to the previous frame and considering all those which are greater than MTHRES.

3b) Remove pixels determined as noise from the motion map.

4) Denoise the motion map by diffusing and then diluting. This is probably the most important step.

5) Only remove the specks in which there was no motion in the current or the next frame.

Last edited by Wilbert; 1st June 2004 at 19:47.
kevina is offline   Reply With Quote
Old 14th August 2003, 20:31   #2  |  Link
Mug Funky
interlace this!
 
Mug Funky's Avatar
 
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,547
that's some good thinking there.

would this work for cigarette burns on bad film transfers?

or dust and scratch on film?

i haven't got a chance to test this yet, but it certainly sounds good.
__________________
sucking the life out of your videos since 2004
Mug Funky is offline   Reply With Quote
Old 14th August 2003, 20:44   #3  |  Link
kevina
Registered User
 
Join Date: Jun 2003
Posts: 71
It might, you need to try it and see. It has only really been tested well on one particular type of noise so the paramaters will most likely need adjusting.
kevina is offline   Reply With Quote
Old 18th August 2003, 02:42   #4  |  Link
cablemonkey
Registered User
 
cablemonkey's Avatar
 
Join Date: Oct 2002
Location: NTSC land
Posts: 9
I tried the ConditionalDenoise filter, and have the following to report:

1) Its quite good at detecting and removing spotting in poor film source. So far this is the only filter (other than SpotRemover for vdub) that has been effective in removing the "black dots" noise in my current project.

2) It still has some stability problems. While working with this, AVISynth many times would throw out the following error:

Avisynth read error: Avisynth read error: Avisynth: caught an access violation at 0x6c2016eb, attempting to read from 0x0b96400.

The first hex address would always be the same, but the second would vary. This was using avisynth 2.5.2. Even with it was he only filter in the script (except ConvertToYV12), it would kick out this error, even after closing vdub and reopening.

Looks like it has a good bit of potential, but definitely needs some more testing.
cablemonkey is offline   Reply With Quote
Old 18th August 2003, 03:11   #5  |  Link
kevina
Registered User
 
Join Date: Jun 2003
Posts: 71
Thanks for the report.

It should be OK to encode a video as it should't crash when not jumping around the video. I am not trying to make up an excuse for the bugs, just a work around.
kevina is offline   Reply With Quote
Old 18th August 2003, 05:07   #6  |  Link
kevina
Registered User
 
Join Date: Jun 2003
Posts: 71
Just to make sure. Are you using version 0.11 of the C API Plugin?
kevina is offline   Reply With Quote
Old 18th August 2003, 05:26   #7  |  Link
morsa
the dumbest
 
Join Date: Oct 2002
Location: Malvinas
Posts: 494
I have the same crash and I'm using c api version 11.
@Cablemonkey:
Could you post your setting for removing spots?
morsa is offline   Reply With Quote
Old 10th September 2003, 05:21   #8  |  Link
kevina
Registered User
 
Join Date: Jun 2003
Posts: 71
Version 0.92 Now Available

A new version is now available. This version fixes the nasty crash. It should work OK for everyone.

So please try it out again.

http://kevin.atkinson.dhs.org/temporal_median/
kevina is offline   Reply With Quote
Old 10th September 2003, 16:04   #9  |  Link
cablemonkey
Registered User
 
cablemonkey's Avatar
 
Join Date: Oct 2002
Location: NTSC land
Posts: 9
i've been swamped at work (gotta love post-acquisition integrations)and have had to put this project on hold for a bit. I'll let you know when i have have an opportunity to pick it up again.
cablemonkey is offline   Reply With Quote
Old 12th September 2003, 21:35   #10  |  Link
unplugged
Registered User
 
unplugged's Avatar
 
Join Date: Oct 2001
Location: Italia
Posts: 412
0.92

Crashes not resolved yet, at least for ConditionalDenoise, couldn't use that with (YV12) 768x576, 720x576 and 720x288; generally it never worked to me.
I haven't tried other res and avisynth is the lastest version.
unplugged is offline   Reply With Quote
Old 12th September 2003, 22:32   #11  |  Link
kevina
Registered User
 
Join Date: Jun 2003
Posts: 71
What processor are you using?

Make sure you are using the avisynth_c.dll included.
kevina is offline   Reply With Quote
Old 12th September 2003, 23:51   #12  |  Link
unplugged
Registered User
 
unplugged's Avatar
 
Join Date: Oct 2001
Location: Italia
Posts: 412
Athlon XP, the DLL is latest 0.14.
Must say that I have tried denoise only with defaults as follows: ConditionalDenoise(interlaced=false)
Maybe am I missing anything... ?

P.S.: there is not much doc about mwidth, mheight and mp parameters. Please add something, thanks .
unplugged is offline   Reply With Quote
Old 23rd September 2003, 22:17   #13  |  Link
slk001
Registered User
 
Join Date: Apr 2002
Posts: 399
I have the latest version and I cannot get ConditionalDenoise to even run. ConditionalMedian looks to be very useful for me, and I want to see if the Denoiser will also.

Whenever the Denoiser runs, Avisynth always catches an access violation.

I run on dual P4s. Your C plugin is used.

Here's the script I am using:

LoadPlugin("d:\program files\HOLDER\mpeg2dec3.dll")
LoadPlugin("d:\program files\AviSynth 2.5\plugins\avisynth_c.dll")
LoadCPlugin("d:\program files\AviSynth 2.5\plugins\CondTemporalMedian.dll")

#mpeg2source("d:\program files\HOLDER\TEST.D2V")
mpeg2source("d:\program files\HOLDER\TEST.D2V").bilinearresize(720,480)

ConvertToYV12

#ConditionalMedianMap()
ConditionalDenoise()

#fadein2(48)

#ResampleAudio(44100)

#version()


This filter has amazing potential - don't give up on it yet!
slk001 is offline   Reply With Quote
Old 24th September 2003, 14:35   #14  |  Link
slk001
Registered User
 
Join Date: Apr 2002
Posts: 399
One more thing... ConditionalDenoise causes Avisynth to give the error when it tries to access the second frame. The first frame holds steady.
slk001 is offline   Reply With Quote
Old 27th September 2003, 08:03   #15  |  Link
kevina
Registered User
 
Join Date: Jun 2003
Posts: 71
OK Everyone. I THINK I finally got it working right. I tested it on a Windows XP system (I normally use Windows 98) and was able to reproduce the problem and fix it.

So give it another go. http://kevin.atkinson.dhs.org/temporal_median/. A non iSSE version is now included.

I also expanded the readme a bit to give a quick guide to tuning the parameters.
kevina is offline   Reply With Quote
Old 29th September 2003, 16:40   #16  |  Link
slk001
Registered User
 
Join Date: Apr 2002
Posts: 399
Yes, it works quite well now. Here's a script that I have been testing with:

LoadPlugin("d:\program files\HOLDER\mpeg2dec3.dll")
LoadPlugin("d:\program files\AviSynth 2.5\plugins\avisynth_c.dll")
LoadCPlugin("d:\program files\AviSynth 2.5\plugins\CondTemporalMedian-isse.dll")

mpeg2source("d:\Experiment\CHHTEST.D2V").trim(195,0)

conditionalmedian(mthres=30,mwidth=6,mheight=4,mp=11)

ConditionalDenoise(mthres=16,mwidth=5,mheight=3,mp=11,p1=2,p2=2,interlaced=false)

converttoYUY2()

v1=declick(lthresh=35,cthresh=10,map=true)

#stackhorizontal(v1,v2)

V2=blankclip()

audiodub(v1,v2)


Notice that it also uses DG's DECLICK routine. I find that this .DLL helps remove clicks in the frames at scene changes, where there is no prior and post matches.

The CONDITIONALMEDIAN filter cleans up the overall video nicely (this test video is an old film with lots of dust, hairs, etc on the encoding - also, this video also has the chroma shifts due to the age of the film).

The CONDITIONALDENOISE filter removes horizontal noise (the "meteors") on my video (it is a laserdisk capture with scratches on the disk surface).

Many kudos to you, Kevin (and Donald). Thanks for your efforts.
slk001 is offline   Reply With Quote
Old 30th September 2003, 15:47   #17  |  Link
morsa
the dumbest
 
Join Date: Oct 2002
Location: Malvinas
Posts: 494
May be some source code from Declick should be included into Kevin Atkinson's filter, cause Graft has stop development and even download availability of Declick.
morsa is offline   Reply With Quote
Old 9th November 2003, 00:48   #18  |  Link
Fizick
AviSynth plugger
 
Fizick's Avatar
 
Join Date: Nov 2003
Location: Russia
Posts: 2,183
Recently I found "Conditional Temporal Median Filter".
Greate works! Thanks to Kevin Atkinson.
I tred to use it for my archive of old 8 mm kino-films (telecined with camcorder and tv-tuner).
These movies have many spots and scratches.
Before I tried similar filters for VirtualDub: "SpotRemover", "Pops", and "Random Noise Remover".
But CTmedian is the most advanced, it makes less artefactes (false detections) on moving parts. Also it removes spots more purely, completely (with outliers).
However, I have one question (proposition).
In many my (and similar) movies, almost all spots are black (from dust).
Sometimes, the CTmedian filter make false detections at transition from dark to light pixels.
Rarely, it transfers a dark spot from previous frame to current!
In contrast, there are another movies, captured from analog TV, with only white spots (snow).
I think, this filter would produce still less artefacts on similar movies, if it makes comparing of pixels not by absolute difference, but simple difference (as option).
For example, some new option may control filter's work as follows:
- detect and clear all transitions (default),
- detect and clear only black spots,
- detect and clear only white spots.
Is it possible in next version of the filter?
By the way, the POPS filter has similar control (tuned black and white spot detection levels).
P.S. I am not a real C-programmer.
P.P.S. Sorry my English.
Fizick is offline   Reply With Quote
Old 9th November 2003, 01:15   #19  |  Link
Fizick
AviSynth plugger
 
Fizick's Avatar
 
Join Date: Nov 2003
Location: Russia
Posts: 2,183
Sorry, the my previous post have been prepared 5 day ago (forum rules for first newibe post), but I decide to send it now.
During these days I try some c-programming.
In Kevin's source code (GNU) I found (in file med-f.cpp) function "find_outliers", and change some code (for non-CCE version).
( o - output, p - priveous frame, c - currrent, n - next)

o[x] = 0;
byte mn = min(p[x], n[x]);
byte mx = max(p[x], n[x]);
//Original code by Kevin Atkinson:
// if (c[x] < mn) o[x] = mn - c[x];
// if (c[x] > mx) o[x] = c[x] - mx;
// Modes added by Fizick:
// Set some black-white mode of spots search, from SIGN parameter:
switch (parms.sign){
case 1:
// sign=1 - only black (dark) spots and outliers
if (c[x] < mn) o[x] = mn - c[x];
break;
case -1:
// sign=-1 - only white (light) spots and outliers
if (c[x] > mx) o[x] = c[x] - mx;
break;
case 2:
// sign=2 - only black (dark) spots, any outliers
if (c[x] < mn) o[x] = mn - c[x];
if (c[x] > mx) o[x] = min( (c[x] - mx), parms.p1 );
break;
case -2:
// sign=-2 - only white (light) spots, any outliers
if (c[x] > mx) o[x] = c[x] - mx;
if (c[x] < mn) o[x] = min( (mn - c[x]), parms.p1 );
break;
case 0:
default:
// sign=0 - any spots and outliers (default)
if (c[x] < mn) o[x] = mn - c[x];
if (c[x] > mx) o[x] = c[x] - mx;

I add one new parameter "sign", and of course change some code for it also.
It works!
May be, Kevin Atkinson will put similar code in original source (I not understand some code in parameters parsing).

Last edited by Fizick; 13th November 2003 at 20:20.
Fizick is offline   Reply With Quote
Old 30th November 2003, 20:37   #20  |  Link
Fizick
AviSynth plugger
 
Fizick's Avatar
 
Join Date: Nov 2003
Location: Russia
Posts: 2,183
As Kevin does not respond, I modify the filter myself (GNU GPL v.2).
Changes:
1. "sign" parameter for removing only black or white specks.
(as described in my previous post.)

2. "per" parameter for more smoothed specks perimeter.
Set percent of smoothing for pixels near perimeter (border) of spot.
per=0 - all pixel at spot outliers are replaced to same pixels
from adjacent frames.
per=100 - pixels near border of spot outliers are not changed,
internal pixels at spot outliers are changed partially,
(with quadratic interpolation),
according to pixel differences from adjacent frames,
smoothing=0 when difference>p1
per=i - intermediate degree of perimeter smoothing.

default per=0, recomended value per=50.

3. More short filter name ctmedian.dll

The filter may be found at:
http://bag.hotmail.ru/ctmedian/ctmedian.dhtml

I am still waiting for Kevin answer.
And testers too.
Fizick 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 14:16.


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