digitalFAQ.com Forums [Archives]

digitalFAQ.com Forums [Archives] (http://www.digitalfaq.com/archives/)
-   Avisynth Scripting (http://www.digitalfaq.com/archives/avisynth/)
-   -   Avisynth: FixVHSOversharp (Beta) (http://www.digitalfaq.com/archives/avisynth/2851-avisynth-fixvhsoversharp-beta.html)

kwag 03-03-2003 10:31 PM

FixVHSOversharp (Beta)
 
Thanks to MrTibs for releasing an AviSYnth VHS oversharp filter :D

DLL here:
http://www.kvcd.net/FixVHSOversharp.dll
Readme here ( and listed below ):
http://www.kvcd.net/fixVHSoversharp.txt

For AviSynth 2.52 ( YUY2 *ONLY * )
www.kvcd.net/FixVHSOversharp2_5.dll


Code:

FixVHSOversharp (Beta)

This filter aims to repair the light and dark halos that follow high contrast edges in VHS sources. You can see this effect particularly in B/W videos or anywhere that is a high brightness.  (You sometimes see this same effect on DVD sources as well - not nearly as noticeable though.)  This filter targets the areas of the frame that are effected only thus avoiding applying any kind of blur or smooth filter to the entire frame.

The filter dll includes two filters: FixVHSOversharp, which fixes the edges where the oversharp is on the right of the edge and FixVHSOversharpL which fixes the problem on the left of the edge.  I usually run both filters on every frame.


Usage

FixVHSOversharp(clip clip, int brightness_change, int detection_width, int offset)

FixVHSOversharpL(clip clip, int brightness_change, int detection_width, int offset)


brightness_change: The minimum brightness change to examine for the oversharp problem.  (If there isn't an oversharp problem it won't try to fix anything.) I usually set this to 40.

detection_width: The width in pixels of the oversharp scanning window.  I usually set this value to 12 or 14.
Offset: The position in pixels of the working pixel.  I usually set this to 8 (or detection_width-4).


Limitations
This filter is YUV format only.


Known Issues

Some times a "flickering flame" appears on a repaired edge.  I think this is related to a noisy source (ala VHS) but it can usually be eliminated with temporal filters.


Usage Suggestions

Apply this filter high up in your filter chain.  The filter algorithm operates on the one scan line at a time so it is safe to use on interlaced material. If "flickering" edges appear after using this filter, try applying this filter after a temporal filter.


kwag 03-13-2003 04:46 PM

Update. Beta 2 is available here: http://www.kvcd.net/FixVHSOversharp_beta2.zip

Thanks MrTibs :wink:

-kwag

MrTibs 03-13-2003 04:49 PM

Please post any comments, suggestions, questions or requests here in this forum.

Once most people seem happy with the filter, I'll post the source (ala GPL).

Malcolm 03-19-2003 08:07 AM

Hi MrTibs,
i used your Filter some days ago while converting an old VHS-recording to SVCD with great success! Your Filter works perfect! Thank you for that piece of work!
I will do another conversion from VHS to SVCD this evening. I have to use avisynth 2.51 for that, because of some other filters which only works in YV12 colorspace. So, unfortunately i can't use fixVHSoversharp...

Don't you have a version for avisynth 2.51? :lol: Are you planning to convert it to avs 2.51 (and maybe to YV12 colorspace)?

Btw. I'd find it yery useful if your filter would also work vertically! I do have oversharpening on horizontal edges on my VHS-captures. Maybe, the user can get around interlacing problems by doing a separateFields() before applying your Filter and doing a weave() afterwards. If that doesn't work, because the left-out lines affect your filter so it can't work correctly, then maybe your filter could take care itself about interlaceing?!?
Btw. There's a filter (turn.dll) that can turn frames by 90 degree left or right. So, you can use your existing filter for eliminating vertical oversharpening. But it's very slow, because turn.dll only works in RGB colorspace, so you have to do a

convertToRGB()
turnLeft()
convertToYUY2()
vhsoversharp()
vhsoversharpL()
convertToRGB()
turnRight()
convertToYUY2()

bye,
Malcolm

MrTibs 03-19-2003 02:32 PM

I didn't have plans for a 2.5 version but if you want it, I'll take a look. (Perhaps I'll get the help from some more expericened 2.5 filter writers ...hint hint.)

As for oversharp problems on the vertical, I hadn't seen that so I never considered fixing it. I'll take a look at that too. Are you seeing oversharp problems above or below the edges?

sh0dan 03-20-2003 05:09 AM

Porting to 2.51 is quite easy, and can probably be done in 15 minutes.

Include the new avisynth.h, change AviSynthPluginInit to AviSynthPluginInit2 - cross your finger - compile.

If you're interested I could do it for you, if you mail the source to kpo (at) zenaria (dot) com

morsa 03-26-2003 03:09 AM

Well, first of all Hi to all members.
Second, I've been using FixVHS.. on some video not VHS source but DV.
The results aren't very good.The output has a lot of artifacts produced by FixVHS. Some letters on a public telephone get very messed up.And last but not least, the head of the guy who is talking by telephone gets merged with every structure that is behind it.
Am I making something terribly wrong?

MrTibs 03-26-2003 12:47 PM

I'm sorry to hear that you are having trouble with the filter but perhaps I can offer some suggestions:

First, make sure you are using the second beta of the filter. (It produces a much softer result with less dramatic errors.)

FixVHS does seem to mess up letters. This is due to the nature of text usually being bright (near white) on dark backgrounds as well as being closely spaced together. You can, however, make changes to the settings to minimize the problem:

1: Try raising the contrast change value until it only effects the problem areas.

2. Adjust the "detection width" to either below 8 or above 14. (Keep the Offset value 4 pixels below the Detection Width.)

3. Run the filter more than once with different Brightness_change and Detection_width settings to deal with different areas.

4. If my suggested values don't work, try your own. Don't be afraid to throw wild values at the filter.

5. Of course you can break up the source using Trim statements and apply the filter with different settings to different clips. This is time consuming but in the end it may be the only way.

Edit: Edge errors you see on your computer screen often don't show up on your TV. Test your results on your TV, only there will you be able to judge the results.


Some explanation on how the filter works:

The filter scans each line comparing the brightness values between pixel n and n+detection_width. If the difference between n and n+detection_width is above the brightness_change value, it then checks to see if there is an oversharp problem. (if pixel n+offset is greater than or less than n+detection_width) If there is an oversharp problem, it attempts to restore the edge by replacing the brightness value in the oversharped area (n+offset) with a blend the brightness values of n and n+detection_width.

Explanation of the various settings:

brightness_change: This is the minimum brightness change of the edge. The higher the value, the more edges that the filter will ignore.

detection_width: This value is theoretically the minimum width of the edge plus the width of the oversharp effect. In other words, this value needs to be wide enough to clear the oversharp problem. Setting this value very high (16+) will cause the filter to ignore edges that are closely spaced together (like text). Trial and error it the name of the game. This value must always be a multiple of 2.

offset: this value is the oversharp detection location. Only trial and error will find the best result for your source. This value must always be a multiple of 2.

Perhaps a Max_brightness_change value is needed to "ignore" certain areas or to allow the filter to more accurately "target" specific areas.

FredThompson 07-04-2003 02:52 PM

MrTibs,

any chance you'll be releasing a 2.5 version?

MrTibs 07-04-2003 09:33 PM

Yup. Actually I've been re-writing the filter but in the mean time, I'll compile a 2.5 version.

Do you need YV12 or is YUY2 OK for now?

jorel 07-04-2003 09:38 PM

8)
see what means knowledge,wisdom and frienship:

the developer show the "menu" to the next compilation!

:arrow: Do you need YV12 or is YUY2 OK for now?
:wink:

kwag 07-05-2003 09:34 AM

Message sent by MrTibs:
"Here is a simple re-compile of the FixVHS filter for Avisynth 2.5. It still
operates in YUY2 format and has very little testing but here it is:"
www.kvcd.net/FixVHSOversharp2_5.dll

Thanks MrTibs ;)

-kwag

FredThompson 07-05-2003 02:03 PM

Wow, that's really cool. Thanks

YUY2 is just fine as I'm cleaning up some DV passthru stuff lately. Thanks.

FredThompson 07-05-2003 10:44 PM

You know, a YV12 version would be nice when you have the time to work on it. ScriptClip requires YV12 so that sort of encourages moving everything in that direction.

FredThompson 07-15-2003 11:52 PM

Would someone please create some before and after screenshots for this filter? The hardware I've got is quite good and I don't seem to have the problem this filter is supposed to correct. I'd like to see what it does.

MrTibs 07-17-2003 09:55 AM

Before and after screen shots are included in the Beta 2 zip file posted on this page. I created both screen captures and a word document to demonstrate the results.

As for the VHS oversharp problem, I tested quite a number of VHS machines both new and old and they all had the same problem. Some old TV shows demonstrate the problem (but new ones don't).

I assume that Digital Video cameras don't have the problem (I've only worked with one DV camera) so if you are doing DV conversion, you may not need this filter.

Of course, I've never tested Beta tapes.

FredThompson 07-17-2003 12:18 PM

ok, in examining sample picture 5 I see what you are doing. If you look at the people, their immediate right edge has a light color halo int he before but not in the after. The after has some corruption, however, in the calendar and top of the open door.

FWIW, this type of thing also happens with NTSC DV and seems to be when there is a large contrast between two adjacent pixels. It shows up a lot on lettering because of the sharp edges and high contrast which is naturally on such items.

MrTibs 07-17-2003 01:33 PM

You are very correct about the corruption problem. When I wrote the filter, I was doing it without actually seeing the graph of the oversharp problem (since, I've written a luma graphing filter that actually allows me to see the oversharped edge's shape). Text is badly corrupted when using the filter but my overall feeling was that the frames looked better with the filter than without.

I am rewriting the filter with a new oversharp detection/correction method. I hope to correctly identify only the oversharpened edges and then correctly repair the edges. Believe it or not, this has proven to be quite a challenge since the oversharpened edges have different incorrect profiles depending on a number of factors surrounding the effected edge.

FredThompson 07-17-2003 01:54 PM

I'll be more than happy to test this against DV as well.

On my support page (http://www.geocities.com/fredthompson6) you'll see some red links in the middle of the page. Two of those are for screenshots from DV. THis is a pretty good test clip for a number of reasons. TemporalSoften wipes out a lot of subtle detail in the banner and smoke of this clip. You'll see some text but also a graphic image in the upper right of the banner.

MrTibs 07-17-2003 06:26 PM

@FredThompson

When capturing from you DV camera, are you going directly from the camera or are you using a VCR to play the tape?

FredThompson 07-17-2003 07:10 PM

My camcorder does passthru conversion so it can be done either way. The sample I mentioned is pure DV camcorder.

MrTibs 07-18-2003 10:18 AM

Hm... I hate to say this but not all DV camcorders have this problem.

I guess this does suggest that the FixVHS filter may find more use in the future. It seems that not many people are doing VHS-VCD conversons but more and more will be doing home movie conversions.

I'll get back on the FixVHS filter in the next few days. (Right now I'm woking on a motion adaptive temporal smoother. Sort of a PixieDust on steriods.)

FredThompson 07-18-2003 01:05 PM

Yes, I was surprised when I saw the halo in the DV sample. I don't remember exactly which camcorder was used to make it. I think it was bottom-end JVC but, even so, the exact model # would be necessary as things change between model years. I've never had this problem with my Canons.

Please let me know about your new filter. I've stopped with the KVCD optimal script because it appears to smooth some things inappropriately. If you look at the camcorder test shot on my discussion page you'll see what looks like an incense burner. The use of TemporalSoften is destroying that smoke. I've seen similar situations where motion is primarily in the luma channel and smoothers wipe it out because the chroma is stable. Unfortunately, I no longer have a good raw sample of that.

I've often thought temporal softening is great but only if it's got a motion-sensing or block-oriented aspect. Donald Graft's dup filter is a good example. It works great unless the image is somebody talking and their lips don't move much. Another example is a camcorder on a tripod with a stable backdrop. If you've got motion in the foreground but the background doesn't change, it would sure be nice to average the static background for noise reduction. The trick would be to ensure the edges of the parts in motion don't look too different and you create the appearance of cheap bluescreen. (Oh, there's an idea, you might find something helpful here: http://forum.doom9.org/showthread.php?s=&threadid=56277)

I've also stopped development because it appears there might be some problems with DV codecs. I'm losing information when converting to YUY2. Without a safe way to do this, it really doesn't matter what else is done to DV. I'm designing a test scenario. Description is here: http://forum.doom9.org/showthread.php?s=&threadid=57112 Please let me know if you have any suggestions for this test.

MrTibs 07-18-2003 05:41 PM

Kwag's script is limited because because the YDifferenceToNext() filter operates on the whole frame. So, if a car passes by [in a clip], the whole frame gets smoothed. The issue here is that there is no filter to identify fast moving parts of a frame. Of course this is exactly what is needed for a motion adaptive temporal smoother. (i.e I am writing a spec on just this kind of thing.)

On the other hand, there may be a simple way to modify my MADMask filter to mask on large fast moving areas only.... I'll give it some thought.

I'll let you know what I come up with.

FredThompson 07-18-2003 07:02 PM

Thank you, I'd be very interested in testing such a filter.

I'm almost to the point of capturing twice and combining for noise reduction. It requires more space but might be worth the effort.

FredThompson 07-21-2003 03:57 AM

If at all possible, please consider adding filtering of the saturated red and blue bleed which is common to 4:1:1 NTSC. There's a sample on my discussion page (http://www.geocities.com/fredthompson6) showing FlyVideo capture vs. Canopus ADVC. Been kicking this around with a few folks but no really good solution.

http://forum.doom9.org/showthread.php?s=&threadid=57013
http://neuron2.net/ipw-web/bulletin/...topic.php?t=10

I still think a dark smoother which sets a threshold before chroma is allowed on the pixel is a good idea. Would be best if there is weighting based on the luma of surrounding pixels, sort like how Smart Smoother works.

Also, don't use AviSynth 2.5.2 because there is a problem with colorspace conversion. It had me all messed up trying to locate what was destroying fine detail.

morsa 07-21-2003 05:41 PM

From my experience, IŽve seen that the oversharped feature on DV source has nothing to do with the format or the camcorder.It is related with the amount of detail/enhancement/sharpness you set in the camcorder menu.
Another topic is that thes artifacts are always pure black or pure white, so I guess that restricting the border detection to that values should improve results.Also I believe is better to work on the whole image rather than line by line.
By the way, if someone wants to test wavelet noise reducer for Vdub it detects very well those artifacts given the correct settings.

FredThompson 07-21-2003 06:48 PM

I'm not sure I understand what artifacts you mean. Can you describe?

I certainly do agree with your comment about sharpening features in the camcorder.

The 4:1:1 and 4:2:0 problems with colorspace are horizontal artifacts only because that is how the color is encoded. wrt my idea of testing the surrounding pixels to see if they are near-black, yes, that should be done in a 2D manner. If, for example, 6 out of 8 surrounding pixels are near-black, it's probably a safe assumption that the near-black with high red being tested should not have the red. Once this kind of filtering is done, however, you cannot go back to 4:1:1 without the problem reappearing.

The challenge with processing an entire frame of interlaced source is you don't really have a stream of 25/30 individual pictures. You have 2 distinct streams of 25/30 pictures each.

Spatial filtering on interlaced material, unless the filter is specifically set for it, will mess up your source. It's far safer to divide into 2 half-height streams, filter, then weave. That's assuming your source is true video.

morsa 07-21-2003 07:06 PM

IŽm always talking about FixOversharp filter.
With artifacts I mean those ugly full black or full white borders added to an image to simulate sharpness.
In this case the idea is to replace them by interpolation, but the dificult task is how to detect them.
In a normal video sequence usually the only pure black parts are these added borders.Even if this wasnŽt the case, replacing some other pure black parts wonŽt be noticeable.

FredThompson 07-21-2003 07:44 PM

ah, I understand.

MrTibs 07-22-2003 11:38 AM

This is an interesting thread. Morsa has confirmed what I suspected, that the oversharp effect is the result of some sharpening circuit.

From what I have seen, on VHS tapes, the oversharp effect can be found all over frame. Often I cannot see it by looking at the frame but when I graph the luma, the effect is easily identified. (If I could post a picture, I would show you the graph.)

As for Morsa's proposed solution, all I can say is I whish it was that easy. The FixVHSOversharp filter actually applies a smooth to the effected areas by looking just past the oversharpen edge. This of course can introduce errors as discussed higher in this thread. Another approach is to undo the oversharp error by proportionally adjusting the Luma value at the edge. This approach would be better but it assumes that you can determine the correct value for that pixel without looking on either side of it. My Lumagraph filter has shown that the oversharp effect varies quite a bit on each kind of edge. At times, the overhsharp effect can even trail the edge by a couple of pixels. (i.e. the ends of the edge are fine but suddenly a pixel or two later, the oversharp spike appears.)

In my re-write, I am attempting to use the slope of the areas leading to and following the edges to correct the oversharp spikes. The idea here is to rebuild the edge without copying values from around the edge boundaries. If it works, this new method would avoid the errors to text that the present filter creates.

I am NOT a C++ programmer so my source code is awful but if anyone wants the souce to FixVHS, send me your email address. Perhaps you could find a better method to deal with this issue.

morsa 07-22-2003 06:45 PM

Well, the oversharp everyone is acustomed with VHS is, usually, the result of applying unsharp mask in any of its flavors on the video to make it look sharp on VHS.
That's because of VHS poor resolution.Everytime I make a VHS copy from another source I need to perform this task, otherway the final VHS looks terribly blurry.
As for camcorders (all of them analog or digital, home or professional), I've been testing many of them (always digital ones) and what the circuit does is that it applyes a simple sharpen matrix or sometimes a much advanced unsharp mask always based on contrast.This has something to do with a known CCD limitation.CCD's are always a little blurry, it is on their nature.So if you eliminate the sharpen feature you'll end up with a little blurry image.Another issue is that standard video cameras doesn't use a mechanical shutter, which leads to some kind of blend between one image and the following.That's why new expensive professional cameras (as the ones used for sports events) have a mechanical one.Have you ever wonder why digital photo cameras have mechanical shutters too, even the cheapest of them?
There must be different approaches to correct VHS and to correct any other digital format.The tapes coming from a camcorder don't have this oversharp problem all over the image.They just have it on high contrast areas and it is always a black or white line beside an actual edge.

MrTibs 07-23-2003 03:07 PM

Here is a link to a quick page I set up for my filters:

http://www.geocities.com/mrtibsvideo/


Here is a link to a before/after page showing the oversharp problem with LumaGraph marked. Here you should be able to see how much oversharpening is actually on each frame.

http://www.geocities.com/mrtibsvideo...ore_after.html

morsa 07-23-2003 04:42 PM

Impressive results!!!!!!
But what IŽve seen with DV cameras (e.g. Sony PD150) doesnŽt look like that.
The borders arenŽt halos, they are black or white added borders.
IŽll try to send you an example.

MrTibs 07-23-2003 05:24 PM

@FredThompson and @morsa

Well, the only thing to do now is get a sample of the DV files. I've provided both of you an email account that can accept large files. If you could send me a sample video, I'll see if I can modify the filter to work better on a DV source. (i.e. FixDVOversharp)

MrTibs 07-24-2003 11:01 AM

@morsa

I got the video clip you sent and I see what you are talking about.

When I plotted the frame with LumaGraph, the oversharpened edge looked the same as it does in the VHS source. However, there are a couple of differences between the two sources which is effecting the FixVHS filter:

1. The frame is more than 352 wide. This means that the "halos" that follow the edges are too wide for FixVHS to fix. - You would have to resize the video to 352 in order to it to work. (There is no reason to capture VHS over 352 pixels wide so I allowed this limit to exist in the filter.)

2. In your sample, the overhsharpening effect also seen above and below edges. On VHS sources, the oversharpening effect is only on the horizontal. FixVHS would never be able to fix this.

When I wrote the filter, I gave it the VHS name because I realized that there was a specific pattern and limits to the VHS oversharp problem. With DV, however, things are quite different. I'll take a look the filter and see if I can modify it to work with your source. (I don't know how I'll deal with item 2 though. - I'm not much of a C++ programmer.)

MrTibs 07-25-2003 10:42 AM

Suggestions for better results...
 
I've been working on the filter but I tried this to see if I could improve results with the exisiting filter. Although this "workaround" may seem silly, the results it produced amazed me: Near PERFECT edges!

Quote:

#my source was 352x480 so I resized
bicubicresize(704,480)

FixVHSOversharp(30,28,24)
FixVHSOversharp(30,28,20)
FixVHSOversharp(30,24,16)
FixVHSOversharp(30,24,12)
FixVHSOversharp(30,24,8 )
This method also greatly reduces the errors to text. Give it a try!

morsa 07-31-2003 05:03 PM

Well, I've been testing it with really good results.Although it leaves some black spots on some corrected black borders(Anyone remember that I said the dark halos in DV are almost black?)
About the horizontal sharpenning: What would happen if the filter internally turns the image 90 degrees and makes a second pass?

kwag 07-31-2003 05:08 PM

Quote:

Originally Posted by morsa
What would happen if the filter internally turns the image 90 degrees and makes a second pass?

You mean 180 degrees to invert the phase, and cancel the signal, right :?: :cool:

-kwag

morsa 07-31-2003 08:03 PM

Not exactly.I just thought that , if the filter works a line at a time and it only can remove the vertical edges, turning the image would give me the horizontal ones as if they were vertical.So...


All times are GMT -5. The time now is 01:13 PM  —  vBulletin © Jelsoft Enterprises Ltd

Site design, images and content © 2002-2024 The Digital FAQ, www.digitalFAQ.com
Forum Software by vBulletin · Copyright © 2024 Jelsoft Enterprises Ltd.