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 27th June 2007, 17:39   #1  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,492
Defish plugin for correcting wide angle distortion

A little while back (in this thread) I asked if there was a plugin to correct the circular distortion caused by fisheye and other non-rectilinear lenses, such as you find in camcorders.

There wasn't then, but there is now - it's my first plugin and it's definitely beta (and this post is currently all the documentation there is), but if anyone thinks they can make use of it, please give it a try and let me know of any bugs. Source code is included, but is not well commented.

Here's what it does:



It takes a few parameters:
  • fov - the horizontal field of view of the image in degrees (must be greater than 0).
  • aspect - the pixel aspect ratio of the image (1 if you have square pixels, 0.6875 for anamorphic PAL, etc -defaults to 1)
  • scale - 0 by default, which automatically scales the image to show as much of the image as possible without showing the edges. scale=1 will keep the centre of the image at the original scale. You'll get an error if you try a value that is smaller than the automatic value (this restriction may be removed later, but for now if you want some crazy effects, try adding borders and increasing fov).
  • resample - 1 (default): nearest neighbour, 2: bilinear interpolation (a better interpolator will be added later)

I've missed out on some parameter checks, so don't be surprised if you play around and get a blank clip

Download

Oh yes, I almost forgot - input must be RGB32 (I haven't decided if I'll bother with other colour spaces later) and have an even width and height.

David
wonkey_monkey is offline   Reply With Quote
Old 27th June 2007, 19:51   #2  |  Link
Fizick
AviSynth plugger
 
Fizick's Avatar
 
Join Date: Nov 2003
Location: Russia
Posts: 2,183
congrat with a first plugin!

Is fish-eye focal length constant or variable (zoomed) in camcorders?

Is it possible to automaticaly calculate the needed anti-fish correction?
__________________
My Avisynth plugins are now at http://avisynth.org.ru and mirror at http://avisynth.nl/users/fizick
I usually do not provide a technical support in private messages.
Fizick is offline   Reply With Quote
Old 27th June 2007, 23:13   #3  |  Link
foxyshadis
ангел смерти
 
foxyshadis's Avatar
 
Join Date: Nov 2004
Location: Lost
Posts: 9,556
Does it correct barrel and pincushion distortion as well, or is it only good for linear distortion currently? (Pin/barrel distortions can be modeled on something like ±xⁿ where n is some high even number, rather than the linear/parabolic of fisheye. Mostly flat, then sharp upturn.)
foxyshadis is offline   Reply With Quote
Old 27th June 2007, 23:23   #4  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,492
Quote:
Is fish-eye focal length constant or variable (zoomed) in camcorders?
It's constant for a given level of zoom, if that's what you mean...

Quote:
Is it possible to automaticaly calculate the needed anti-fish correction?
Not with my plugin, but you could use something like PTAssembler. It allows you to mark what should be straight lines and will calulate the fov and other parameters (such as pincushion and barrel). I just adjust by eye until I get a pleasing result

Quote:
Does it correct barrel and pincushion distortion as well, or is it only good for linear distortion currently?
It's currently linear only, and I've noticed some slight remaining distortion in my test footage. I may update it sometime, but for now it does what I need

David
wonkey_monkey is offline   Reply With Quote
Old 18th July 2007, 23:50   #5  |  Link
vatz32
Registered User
 
Join Date: Jun 2007
Posts: 3
Dear David,

As an AVIsynth noob, I'm having trouble getting the correct script syntax to work with the Defish plugin. I managed to copy the cpp and dll files to my AVIsynth/Plugins folder, but then came a cropper ;-)

Please could you post a sample Defish script just to get me started.

I look forward to trying what promises to be a very useful tool.

Thanks, John.
vatz32 is offline   Reply With Quote
Old 19th July 2007, 00:09   #6  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,492
At its simplest, you'll need:

Code:
converttorgb32
defish(fov=120)
The three other parameters have defaults which are explained in the first post.

David
wonkey_monkey is offline   Reply With Quote
Old 23rd August 2007, 19:32   #7  |  Link
vatz32
Registered User
 
Join Date: Jun 2007
Posts: 3
Here's the avs script that worked for me:
Code:
Clip=DirectShowSource("E:\test-1.avi", fps=25)
ConvertToRGB32(Clip, interlaced=true)
defish(fov=77, resample=2)
I am mightily impressed with the output - the bilinear interpolation (resample=2) looks a lot better on my interlaced footage. Everything else works beautifully straight out-of-the-box.

For calculating the Horizontal FoV of a given (rectilinear) lens on a given camera, I used
Code:
"Horizontal FoV = 2 (arctan (d/2f))"

where d = horizontal width (mm) of the CCD 
and f = focal length (mm) of the lens
My test lens was a 3.8mm Aspherical on a 4:3 1/2" CCD.
(The specification claimed diagonal FoV as 108°, whereas the calculation suggested 96°. I guess the difference of 12% is the amount of barrel distortion ?)
The formula suggested a HFoV of 77°, which worked better than my guestimates as the Defish filter parameter.

One thing I especially like about this Defish is that it makes a very clean stretch&crop into the bargain - removing vignetting or aberration artefacts from the corners and (apparently) any black borders ... by doing all this in one resample / interpolation, it saves time and definition loss.

I take my hat off to you David
vatz32 is offline   Reply With Quote
Old 23rd August 2007, 19:38   #8  |  Link
scharfis_brain
brainless
 
scharfis_brain's Avatar
 
Join Date: Mar 2003
Location: Germany
Posts: 3,653
if you are filtering interlaced contents you need to bob-deinterlace it and afterwards reinterlace it corretly.

if you don't do this, you'll get messed up fields.
__________________
Don't forget the 'c'!

Don't PM me for technical support, please.
scharfis_brain is offline   Reply With Quote
Old 24th August 2007, 11:36   #9  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,492
Glad you like the plugin Vatz. There will eventually be a spline16 interpolator too, which will look better than bilinear.

Quote:
The specification claimed diagonal FoV as 108°, whereas the calculation suggested 96°
The difference is that the calculation is for horizontal FoV (which Defish uses), which will always be less than diagonal FoV.

David
wonkey_monkey 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 12:07.


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