Log in

View Full Version : DeFreq plugin - Interference frequency remover


Pages : [1] 2 3

Fizick
26th September 2004, 20:29
I have 2 bad TV channels in my internal analog TV-tuner. :(

Now I make and release beta version of DeFreq plugin - Interference frequency remover ;)

DeFreq spatial filter removes some frequencies from video frames.
It can be used for removal of interference frequency noise (regular inclined strips) from some TV capturing, and also for additional blurring.


Defreq uses Fast Fourier Transform method for frequency selecting an removing.
It is a spatial filter, and works as follows:
1) get frequency spectrum by forward FFT transform of frame image;
2) search some defined spectrum window (windows) for local maximum (extremum, most intense frequency);
3) remove frequencies at this sharp maximum from spectrum;
4) optional remove highest frequencies by low pass filter (for blurring, smoothing);
5) get output frame by inverse FFT transform of cleaned spectrum.

Defreq uses fast external FFTW library version 3 (http://www.fftw.org)
as Windows binary DLL (compiled with gcc under MinGW by Alessio Massaro),
which support for threads and have AMD K7 (3dNow!) support in addition to SSE/SSE2.
It may be downloaded from ftp://ftp.fftw.org/pub/fftw/fftw3win32mingw.zip
You MUST put FFTW3.DLL file from this package to some directory in path (for example, C:\WINNT).

Defreq will NOT work without it!

Try and post report!

scharfis_brain
26th September 2004, 21:28
could you provide some before/after shots?

I do not have TV-reception (I do not pay the fee for our crappy, blocky anlogue cable-TV) here, so I cannot test myself :(

Mug Funky
27th September 2004, 06:17
sorry, i can't see the link with the plugin? i've got fftw3.dll, but no defreq?

[edit]

never, mind. that "www" button is quite small :)

[edit 2]

hmm... it's killing virtualdub on load. fftw3.dll is in c:\winnt\system32, and defreq is being autoloaded.

i'm on a p3 733. could it be a cpu optimization problem?

[edit 3]

works fine when i manually load it... strange. the spectrograms are really pretty :)

hmm.... this is a REALLY sensitive comb-detector. all you need to is look for anything but noise in the middle bit of the spectrogram and you can be sure it's combing - it's a really distinct effect. i wonder if this could be used for anything?

JuanC
27th September 2004, 06:20
Originally posted by scharfis_brain
could you provide some before/after shots? You can see them at his WWW site.

@Fizick: I can't seem to download the plugin. Could there b a problem at your site?

EDIT: I got it now, I think there was something wrong in my browser. Thanks.

kingmob
27th September 2004, 09:50
Ah, i was thinking about this a few weeks ago, but i had no clue as how to program the Fourier Transforms :). I will try this out, sounds absolutely great.

[edit]Works great atm. Might be handy to work it out as a VDmod-filter. That would be easier with the tweaking. At the end you can always specify the paramaters in avisynth.

Mug Funky
27th September 2004, 11:36
hmm. an avisynth GUI would be useful here? maybe "show=true" or an apropriately named parameter could trigger a GUI for tweaking.

also, how are things like FFT size set? this would be a useful thing to play with (to make lowpasses have steeper or gentler rolloffs).

Fizick
27th September 2004, 19:12
Mug Funky,
1)Defreq is autoloaded well for my Athlon.
Can anybody else test this on P3, P4 ?

2)A common type of filter to use in frequency domain filtering is a Butterworth frequency filter. I use it as low pass filter.

But for sharp interference, Defreq02 simply (blindy) set 12 pixels around extemum to 0.

Now I prepare Defreq03 with adaptive frequency region size and degree of amplitude decreasing.

3) What is "Avisynth GUI" ?

As more far "to do", i think about mask using.
The draft mask may be produced by "show" mode, saved as image file, edited by Photoshop, and loaded as as frequency filter.
But it will be slow, and now i am not needed in it. :)

kingmob,
do you want to program the "VDmod-filter" ?
BTW, RGB is not appropriate space.


Can anybody test DeFreq for color interference?
I have not such bad TV sources :( :)
May be VHS ?

Mug Funky
28th September 2004, 15:17
avisynth plugins (i think C only) can have GUIs that flash up when the script is run. i don't know exactly how it works, but a search for "GUIsample" will give you plenty to go on :)

your plugin is C++, so you might not have the option.

Fizick
28th September 2004, 20:13
I hate (and do not know how) any visual control programming ;)
Any buttons nor with C, nor C++, nor FORTRAN.

More questions?
Now I try make v.0.4 with not absolute, but relative (to image size)frequency input.

JuanC
29th September 2004, 04:04
Originally posted by Fizick
1)Defreq is autoloaded well for my Athlon.
Can anybody else test this on P3, P4 ?
I'm on a P4/1.6Ghz. I'm trying DeFreq on a noisy analog TV capture (NTSC 720x480, 29.97 fps, mpeg2 @9mbps). When not separating fields, I have no "vdub disappearing" problems, but as my clips are captured interlaced (I IVTC them afterwards)...

(I use WinXp, fftw3.dll is at \windows\system32)

So, when separating fields, 720x240, 59.94 fps, AND using show & info parameters, sometimes (when using "inappropriate" values for fx/fy ???) DeFreq is making VdubMod disappear when auto loading, and when manually loading, VDubMod disappears after advancing a few frames.

Here's my script: SetMemoryMax(192)
LoadPlugin("G:\Program Files\AviSynth 2.5\plugins\Test\DeFreq.dll")

video1=DGdecode_mpeg2source("test1.d2v")
audio1= WAVSource("test1.WAV")
video1a=AudioDub(video1, audio1)

#AssumeTFF().SeparateFields()
Return DeFreq(fx=68,fy=-75,show=true,info=true)
#Weave()...

Fizick
30th September 2004, 05:13
JuanC, Mug Funky,
It worked OK for me,
but now I changed something (with logarithm) in new version:

Defreq version 0.4, 30 September 2004 - change fx,fy,dx,dy,cutx,cuty parameters to (float) percent of FFT size

Try.

Hallo, anybody is here? :)

Mug Funky
30th September 2004, 07:28
hmm... the filtered result seems to come out strange. like the low frequencies have been replaced with black (rather like a diffuse glow filter set to subtract rather than add).

here's my setting:

defreq(fy=-40,fx=1,sharp=96)

[edit]

this only seems to happen after playing 1 or 2 frames. it doesn't seem to happen at all if you step-through the frames.

[edit 2]

just for fun, here's a nice "soft focus" effect :)
soft=last.defreq(cutx=5,cuty=5,plane=0).defreq(cutx=10,cuty=10,plane=1).defreq(cutx=10,cuty=10,plane=2)
overlay(last,soft,opacity=0.5)

it'd be nice to have 3 plane parameters, rather like masktools has (y=3,u=3,v=3 or something similar). this would save a little typing.

Fizick
30th September 2004, 21:23
Version 0.4.1, 01 October 2004 - fixed bug with init

JuanC
1st October 2004, 05:48
Fizick, thanks alot for the new version 0.4.1. I tried it:

I keep getting VDubMod "vanishing" problems on my P4, but you've narrowed the conditions to make the problem happen (it wasn't unadecuate values for fx or fy, now they're easier to undestand and use). Here's the problem: Every time I use the show=true parameter :( VDmod will vanish just when advancing 1 frame. Note: If I don't use the "show=true" parameter, VDMod won't vanish even after scrubbing the positional slider for a while.

Also, there is an oddity: Using the following script: SetMemoryMax(192)
LoadPlugin("G:\Program Files\AviSynth 2.5\plugins\Test\DeFreq.dll")

video1=DGdecode_mpeg2source("test1.d2v")
audio1= WAVSource("test1.WAV")
video1a=AudioDub(video1, audio1)

MyBlack=BlankClip(video1a, length=30).assumeTFF()
AlignedSplice(MyBlack, video1a)

AssumeTFF().SeparateFields()
Return DeFreq(fx=50,fy=80,show=true,info=true)
#Return Weave() Vdub will show the first 60 frames (0-59) without "vanishing", displaying "DeFreq Peaks: x=0.0 y=0.0 sharp=-1.$", then it will show the first original video clip frame (#60) displaying "normal" DeFreq info with it, but if I try to move to the next frame (#61), VDMod will "vanish".

Hope this report helps any way.

Mug Funky
1st October 2004, 12:34
tanks, muchly for the new version. i haven't found any bugs yet (the strange too-dark frames thing is solved it seems).

the lowpassing gives a very pleasant effect - gentle rolloff of highs, so there's still a bit left.

Fizick
2nd October 2004, 01:00
JuanC,
thanks fo report!
I found and fixed problem for pure black "DeFreq Peaks: x=0.0 y=0.0 sharp=-1.$"
But not with Defreq 0.4.1 not new 0.5, my VDUBMod do not "vanish".
I try almost your script:

setmemorymax(128)
loadplugin("defreq.dll")
avisource("i:\polos2.avi")
video1a=converttoyv12()

MyBlack=BlankClip(video1a, length=30).assumeTFF()
AlignedSplice(MyBlack, video1a)
AssumeTFF().SeparateFields()
Return DeFreq(fx=50,fy=80,show=true,info=true)


Try new released version 0.5.

I wonder, why somebody else do not post anything (my counter show about 100 dounloads of this buggy filter).

Mug Funky,
I like FFT smoothing too. :)
I do not want make processing of 3 color planes for the present (and probably in future). They are processed independently.


BTW, you can see spectrum before and after Defreq with help of two more Defreqs (for test) :)

before=defreq(show=true)
after=defreq(cutx=10,cuty=10).defreq(show=true)
interleave(before,after)

Probably, we can test some other denoising filters this way. :)

before=defreq(show=true)
after=vaguedenoiser.defreq(show=true)
interleave(before,after)

But I use in defreq variable (adaptive) scale for spectrum show,
from min to max (with logarifm).
May be fixed scale will be better for it.


P.S. I will absent some days because of Internet payment overdraft.:(

Fizick
9th October 2004, 00:40
Version 0.5.1, 07 October 2004 - more fast processing of frames which are not needed in cleaning,
source released under GPL.

EpheMeroN
9th October 2004, 01:19
Your plugins are on your WWW yes? What is your URL exactly? Call me stupid :-) but I cannot find it.

JuanC
9th October 2004, 01:46
clicking on the WWW icon under his post will take you to http://bag.hotmail.ru/

Unobtanium
17th October 2004, 05:12
Fizick

I'm testing version 0.5.1 of the filter on a Type-1 DV clip that I captured off-air. The spectrum shows multiple peaks but only one is listed in the info.
Your screen cap photo part 2 gives info on two peaks; is there a way that I can get Defreq to list the X and Y values of the other peaks that appear in the spectrum?

Since you are seeking feedback, some of the following information may be of value to you:

2.6 GHz Pentium 4C (Northwood)
Running at 3.12 GHz
Hyperthreading Enabled
AGP/PCI bus 66/33 MHz
Windows 2000 SP4 environment
1024 MEG of Corsair PC3200 RAM not overclocked
ABIT IC7 MAX3 Motherboard

I have not experienced any stability problems with DeFreq. I am currently viewing the clips with Media Player Classic. I haven't tried VDub or VDubMod yet.

Thank you for making DeFreq available. I think that it will be enormously useful once I learn how to use it effectively.

Fizick
17th October 2004, 20:19
Unobtanium,

is there a way that I can get Defreq to list the X and Y values of the other peaks that appear in the spectrum?
What is your script?
You must set not only fx,fy but also fx2,fy2 to some values.

Unobtanium
18th October 2004, 23:31
Fizick,

Thanks for the prompt reply, the script is:

LoadPlugin(PluginPath + "defreq.dll")
DirectShowSource(SourcePath + SourceName, fps=30, video=true,
\audio=true, seek=true)
SeparateFields()
DeFreq(Show=true, Info=true)
Evens=SelectEven().Subtitle(("Even"), x=600, y=225)
Odds=SelectOdd().Subtitle(("Odd"), x=600, y=225)
StackVertical(Evens, Odds)

When I play the script, DeFreq lists one peak at ~x=10 ~y=-10. The exact frequency shifts a bit from scene to scene, and is mostly the same for both fields.

My question relates to the fact that the left part of the frame (the spectrum) shows additional peaks at higher frequencies. The do not appear to be harmonics of the listed frequency. Please forgive my stupidity if the answer is obvious, but I do not see how to get DeFreq to identify the higher frequency peaks.

Fizick
19th October 2004, 05:49
Unobtanium,
You must add some parameters to Defreq:

DeFreq(fx=10, fy=-10, fx2=10, fy2=20, Show=true, Info=true)



Then you must look to position of rectangles, and tune these parameters and may be others (sharp,dx,dy,dx1,dy2,fx3, fx4 and so on)

johnmeyer
6th November 2004, 21:56
I too have problems with Version 0.5.1, using AVISynth 2.55. Here's the script:
loadPlugin("c:\Program Files\AviSynth 2.5\plugins\defreq.dll")
AVISource("E:\NPS\NPS0001.avi")
converttoYV12(interlaced=true)
AssumeBFF
SeparateFields()
DeFreq(fx=10, fy=-10, fx2=10, fy2=20, Show=true, Info=true)
Weave()
If I run this with the SeparateFields() and Weave() parameters, VirtualDub gives me the following error:

Avisynth read error: Avisynth: caught an access violation at 0x77f581bd, attempting to write to 0x80808080

If I run this WITHOUT the SeparateFields() and Weave() parameters, it works fine. Also, if I remove the Show=true and Info=true, I can run with the SeparateFields() and Weave() parameters. Thus, the problem is only if I use the Show and Info parameters with the fields separated.

Can I simply proceed with the values I get when reading the interlaced source? If so, I can work around this bug.

Until I hear from you, what I am doing is using the values I get when reading the interlaced source.

Fizick
7th November 2004, 03:08
johnmeyer,
thanks for report.

It is a strange bug, for height < 540 only (not for my PAL).
I do not quite ungerstand it, but correct in new version 0.5.2.

Try!

johnmeyer
7th November 2004, 09:28
Thank you for such a quick response. I tried the new November 7, 2004 defreq.dll, and I am sorry to report that I get exactly the same error. However, while it is a pain, if I temporarily remove the SeparateFields() and Weave() commands, the numbers I get from the Show and Info settings seem to work extremely well. I just put them into Defreq, un-comment the SeparateFields() and Weave() commands, and proceed.

Thus, I can work around the bug.

The results from this plug-in are amazingly good. Thank you very much.

scharfis_brain
7th November 2004, 11:38
as workaround, you may use:

xxxsource("video.xxx")
assumetff
bob()

defreq()

converttoyuy2()
assumetff()
separatefields()
selectevery(4,0,3)
weave()

if your video is bff, set both assumexff to bff

johnmeyer
7th November 2004, 19:14
Good news: Your script stops the crash.

Bad news: Both x2 and y2 values now report 0.

--------------

Edit:

Ah, I looked back and your script, and added:

converttoYV12(interlaced=true)

before calling defreq, and it now works.

Fizick
7th November 2004, 21:29
Try version 0.5.3

johnmeyer
7th November 2004, 21:56
Good.

This version does not cause problems with either my original script or with the modified bob() script you provided. My only remaining question is about the numbers provided by each script.

When I use this script:loadPlugin("c:\Program Files\AviSynth 2.5\plugins\defreq.dll")
AVISource("E:\NPS\NPS0001.avi")
converttoYV12(interlaced=true)
AssumeBFF
bob()
DeFreq(fx=6.1, fy=4.2, sharp=8.1, fx2=8.6, fy2=13.8,sharp2=7.3, show=true,info=true )
assumebff()
separatefields()
selectevery(4,0,3)
weave()

I get x=4.7, y=5.8, sharp=7.8, x2=7.2, y2=15.4, sharp2=6.2

for the first frame.

However, when I use this script:

loadPlugin("c:\Program Files\AviSynth 2.5\plugins\defreq.dll")
AVISource("E:\NPS\NPS0001.avi")
converttoYV12(interlaced=true)
AssumeBFF
separatefields()
DeFreq(fx=6.1, fy=4.2, sharp=8.1, fx2=8.6, fy2=13.8,sharp2=7.3, show=true,info=true )
weave() I get x=6.6, y=1.7, sharp=4.7, x2=7.2, y2=11.7, sharp2=4.6

Obviously, bob shifts fields, so maybe that's the difference, but I would not have expected such a huge difference. I am not sure which approach I should use. Since I got good results using the second script, I am tempted to continue to use that, unless you advise me otherwise.

Just to be clear, this video is NTSC 29.97 DV BFF video which originated from a camcorder, but then got the diagnol lines from an over-driven amplifier during a duplication process. I couldn't get access to the original tapes, so I had to clean up the copies.

Fizick
7th November 2004, 23:00
Do not use Bob here.
It doubles height by interpolation,
and it is scharfis_brain's "idee fixe" :)

johnmeyer
7th November 2004, 23:32
That's what I thought. I'll stick with the usual method for operating on separate fields.

Once again, thank you very much for all your help. I use most of your plug-ins, and they are all truly remarkable.

My next experiment (in a few days) is going to be to use Depan to generate super-smooth slow motion, much like Motionperfect. I got very interesting results with mvtools, and I want to see if I can do as well or better using depan.

Palmnut
18th November 2004, 21:23
In your html help script you say:

"Set fx=0 for strictly vertical frequency interference stripes, set fy=0 for strictly horizontal one."

I am trying to deal with purely vertical lines (see attached), however if I set fx=0, the show=true display (and the result I see if I subtract the processed from the input) shows horizontal lines. Setting fy=0 seems to produce the required purely vertical response.

Huh?

[EDIT}

Damnit - this should have been added to threadid=82978, but got posted here by mistake. Could a mod please move it to the correct home? Thanks.

Fizick
18th November 2004, 22:15
It is manual bug. Sorry my English :D

zilog jones
29th November 2004, 12:00
What am I supposed to be looking for exactly on the frequency spectrum? Is it only brighter parts of lines like the example on your site, or can it work with other things too?

And how do I set "sharp"? Do I put it higher or lower than what it's usually reading?

I'm trying to see if I can make it help with a VHS capture - there's no really profound stripes on the video (though there seems to be vertical stripes on that channel a lot - I can't really see if they were there on the capture though), but could it help with any other regular interference? I get a thick wobbly line around x=60 vertically down the spectrum (sorry I'm not at home so can't give a picture), broken in parts - could DeFreq do anything about that?

Fizick
29th November 2004, 20:00
try yourself :)

oledoe
2nd December 2004, 13:03
(fx2,fy2) doesn't work.
That can be seen by using watching the output of info=true.
The peak for (fx2,fy2) is always on (0,0)

Line 869-870 ("search Peak in windows" for YUY2) of defreq.cpp should be

if (fx2>0 || fy2 !=0)
DeFreq::SearchPeak(out, outwidth, src_height, fx2, fy2, dx2, dy2, fxPeak2, fyPeak2, sharpPeak2);

Instead, there was a couple of (fx3,fy3) parameters, maybe left over after a copy and paste.

Thanks.

zilog jones
2nd December 2004, 17:30
Originally posted by Fizick
try yourself :)
I've already tried, but I really don't know what I'm doing. Here's two examples of my VHS captures:
http://www.skynet.ie/~zilog/pics/defreq.png
This one is pretty recent, from a cable source (the channel's up somewhere on the hyperband if that's of any help), and it kinda looks like there's vertical striping among other things.

http://www.skynet.ie/~zilog/pics/defreq-crappy_reception.png
This is from a tape recorded in 1989, with a pretty bad reception (UHF). The vertical line on the right side of the spectrum is there nearly all through the capture, sometimes accompanied by a few others near it. The stuff at the left half is always there too.

Basically, where do I set the windows for these? And will it even help much? And can the low-pass filter help?

Fizick
2nd December 2004, 23:11
oledoe,
thanks fo exact report!
Tom barry said sometimes ago, how useful is source releasing for support :)

v.0.5.4 is out.

zilog jones,
i see jitter or interlace on top picture.
The bottom is really bad.

lark
3rd December 2004, 08:56
looks like you have invented a timemachine ;-)

Version 0.5.4 - December 8, 2004

BTW, i'd appreciate, if you'd add news to your home page (i.e. saying, when each plugin was last modified).

regards
t :)

Fizick
3rd December 2004, 09:26
:D

zilog jones
3rd December 2004, 09:55
zilog jones,
i see jitter or interlace on top picture.
The bottom is really bad.

The top one is actually progressive, it's just some of the noise is interlaced, and I know DeFreq can't fix that. I know the bottom one's bad, but how would I set DeFreq for these?!?

Fizick
3rd December 2004, 10:06
zilog jones,
No , defreq mostly can delete regular noise.

For your first (progressive) jittered frame, we must have some new plugin to de-jitter it firstly . But not from me, sorry :)

zilog jones
3rd December 2004, 11:25
But don't those straight lines going down the spectrum mean there's some regular noise there?

oledoe
3rd December 2004, 12:05
You've got to love GPL software.
:)

BruceL
18th December 2004, 17:06
Hello Fizick. I was not sure if you were still following this thread but thought I would write anyway. Thank you for a great filter. I have been experimenting with Defreq and have been getting terrific results as I also get diagonal vertical noise lines. I did notice and was not sure if you or anyone else have had this experience. When there is Credit Text, bolder more vertical lines appear. I attached screen shots showing with and without the filter. Any help or advise would be greatly appreciated.

Don't seem to be able to use attachments.

Fizick
19th December 2004, 00:05
BruceL,
May be you use too large search windows?
Post your script!
And spectrum (show mode) image.

BruceL
19th December 2004, 01:38
Fizick,
I spent the rest of today doing more experimenting. I am embarrassed to say one of the windows I made which I thought was helping me, was actually causing the problem. Thank you for your fast response but more importantly, thank you again for sharing such a terrific filter.

EpheMeroN
11th January 2005, 08:42
I think I've figured out DeFreq. A simple call of it like this: DeFreq(fx=x,fy=-x) and the "fx param" refers to the actual angle of the interference noise, while the "fy param" refers to the thickness of the interference noise yes?

The "fx param" from 0-100 goes from center and moves right and upward as you increase the number correct? So, in essence it goes from left to right until its completely vertical. My problem is, this bad analog station I receive in here has BAD interference noise at an extreme right-to-left pattern that I do not know how to fix using DeFreq. Below is an image of what I'm working with:

http://img101.exs.cx/img101/5976/noise019jt.jpg

http://img101.exs.cx/img101/6570/noise023qy.jpg

EpheMeroN
25th January 2005, 08:47
Nothing?