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 19th February 2010, 23:40   #1  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,492
"Defish", barrel and pincushion distortion correction filter

Updated 2010/02/21 - version 1.1

Download: defish

It's taken me several years since my first post on this subject, but I've finally written a usable fisheye distortion correction plugin:



It uses spline16 interpolation.

Code:
defish (v1.1) for Avisynth 2.5
(c) David Horman, 2010

This filter can be used to correct (or induce) barrel and pincushion
distortion.

USAGE
-----

The filter takes the following parameters (in addition to the input clip):

[unnamed]:
	Input clip. Must be RGB32 and have even width/height.

fov:
	useful range: -180.0 - 180.0
	default: 0
	The horizontal field of view, in degrees. Positive values will
	correct barrel distortion (induce pincushioning). Negative values
	should correct pincushion distortion (induce barreling), but note
	that this may currently be implemented incorrectly.

scale:
        range: 0.0 - infinity
	default: 1.0
	An adjustment parameter which scales the image after correction.

aspect:
	range: 0.0 - infinity
	default: 1.0
	The pixel aspect ratio of the input clip.

direction:
	values: "x", "y"
	This parameter restricts the correction to either horizontal or
	vertical only.

scaling:
	values: "fitx", "fity", "fitxy"
	This parameter automatically scales the image to fill the image
	horizontally, vertically, or both. The "scale" parameter above is
	still effective.

	The default behaviour when using fov is to scale the image such
	that the central area stays at the original scale.

	This parameter is not effective when using the polynomial values
	below.
a,b,c:
        sensible range: 0.0 - 1.0
        Parameters for correcting distortion polynomially. These are only
        effective when fov=0 (which is the default value).

        a+b+c must be less than or equal to 1.0 when pin=true.

pin:
	boolean
	Set this to true to correct pincushion distortion, and false to
	correct	barrel distortion - this may seem the wrong way around but
	it was chosen to match the behaviour of the similar parameter of
	V.C. Mohan's DeBarrel filter.
David

Last edited by wonkey_monkey; 16th March 2015 at 22:55.
wonkey_monkey is offline   Reply With Quote
Old 20th February 2010, 01:14   #2  |  Link
Lyris
Registered User
 
Join Date: Sep 2007
Location: Europe
Posts: 602
Wow! I think I have some footage somewhere that is begging for this. Looks like a fantastic tool!
Lyris is offline   Reply With Quote
Old 20th February 2010, 01:56   #3  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,492
It looks there are still some bugs to pin down - certain extreme values of fov aren't behaving as I thought they were, and the filter can crash (possibly only when using the scaling parameter), but it should be fine for any "sensible" usage.

David
wonkey_monkey is offline   Reply With Quote
Old 20th February 2010, 11:12   #4  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Looks very nice, think VcMohan has a filter called "DeBarrel" that does same type thing.
Never tried it.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 20th February 2010, 11:47   #5  |  Link
scharfis_brain
brainless
 
scharfis_brain's Avatar
 
Join Date: Mar 2003
Location: Germany
Posts: 3,653
defish is much faster than debarrel, but defish still is slower than the 'barrel distortion' filter from Emiliano Ferrari.

But I liked the different parameters for the distortion of debarrel.
__________________
Don't forget the 'c'!

Don't PM me for technical support, please.
scharfis_brain is offline   Reply With Quote
Old 20th February 2010, 13:01   #6  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,492
I could probably add those parameters pretty easily, though I find it more intuitive to work in degrees. As far as speed goes, there is probably still plenty of room for optimization.

David
wonkey_monkey is offline   Reply With Quote
Old 20th February 2010, 13:46   #7  |  Link
scharfis_brain
brainless
 
scharfis_brain's Avatar
 
Join Date: Mar 2003
Location: Germany
Posts: 3,653
this sound promising.
Also I like the spline interpolation since it is much smoother than linear or cubic distortion.
__________________
Don't forget the 'c'!

Don't PM me for technical support, please.
scharfis_brain is offline   Reply With Quote
Old 20th February 2010, 16:46   #8  |  Link
um3k
Registered User
 
Join Date: May 2007
Posts: 220
Would it be possible to add the option to correct for cameras with an offset sensor? I.E. one that isn't centered on the optical axis.
um3k is offline   Reply With Quote
Old 20th February 2010, 17:23   #9  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,492
Quote:
Would it be possible to add the option to correct for cameras with an offset sensor? I.E. one that isn't centered on the optical axis.
Not really, because the filter only calculates remapping and spline16 coefficients for one quarter of the image, which is why it can only accept evenly dimensioned images.

You can addborders to put the center in the center, if you see what I mean, then crop afterwards.

David
wonkey_monkey is offline   Reply With Quote
Old 20th February 2010, 18:22   #10  |  Link
um3k
Registered User
 
Join Date: May 2007
Posts: 220
Yeah, that works. I was just trying to avoid extra steps (for myself). :P
um3k is offline   Reply With Quote
Old 21st February 2010, 15:55   #11  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,492
First post updated - defish can now also take a,b,c parameters similar to DeBarrel (see updated readme). It should also be slightly faster (but consumes a little more RAM).

David
wonkey_monkey is offline   Reply With Quote
Old 30th April 2010, 20:40   #12  |  Link
Ashley_Pomeroy
Registered User
 
Join Date: Apr 2010
Location: England
Posts: 1
I'd just like to publicly thank David Horman for this plugin. It's esoteric, but I've been experimenting with defished fisheye images for a couple of years, and I've always wanted to try it with video; once I got a Canon 5D MkII I had a go. Until now I've been splitting the footage into individual frames, defishing them as a batch job, and then reassembling them into a movie again, but this plugin works a treat and is much faster.

In fact I've written a blog post about it, here, complete with a sample video of me on my bike:
http://women-and-dreams.blogspot.com...g-video-2.html

Here's a shot of it in action:


EDIT: It'd be interesting to run it on the "HAL's eye view" sequences from 2001: A Space Odyssey, but I can't find my DVD. There must have been lots of trippy films in the early 1970s that are crying out to be defished. I'm reminded of the bloke who destretched the slit-scan sequence at the end of the film.
Ashley_Pomeroy is offline   Reply With Quote
Old 30th April 2010, 21:21   #13  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,492
Hey, great to see someone's found a use for defish Just read through that blog post...

Quote:
The tricky thing is that it only works with AVISynth, a free, command-line video editor which can be run independently, or invoked as part of VirtualDubMod, an older version of VirtualDub with some novel features.
AviSynth works fine with new versions of VirtualDub, too.

Quote:
I chose 800x400 because they are good whole numbers, and I like the colours. Eight is yellow and four is blue and zero is water.
Do you have synesthesia?

David
wonkey_monkey is offline   Reply With Quote
Old 30th April 2010, 22:49   #14  |  Link
Wilbert
Moderator
 
Join Date: Nov 2001
Location: Netherlands
Posts: 6,364
Hi David,

Look interesting. Would you be willing to release your plugin under an open source license?
Wilbert is offline   Reply With Quote
Old 30th April 2010, 23:00   #15  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,492
Don't see why not - not really sure how I should package it up or anything. I've probably taken a few too many shortcuts with my VC++ Project, like having it compile straight into my AviSynth plugins folder - should I just put the .cpp file somewhere, maybe?

David
wonkey_monkey is offline   Reply With Quote
Old 30th April 2010, 23:39   #16  |  Link
Wilbert
Moderator
 
Join Date: Nov 2001
Location: Netherlands
Posts: 6,364
Quote:
Don't see why not - not really sure how I should package it up or anything. I've probably taken a few too many shortcuts with my VC++ Project, like having it compile straight into my AviSynth plugins folder - should I just put the .cpp file somewhere, maybe?
You could package the .cpp file, the documentation, the license file and the plugin itself. You can put something like this in the source file (at least if you release it under the GPL, like most plugins):

Code:
/*
	"Defish", barrel and pincushion distortion correction filter for AviSynth.

	Copyright (C) 2010 David Horman
  
	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2, or (at your option) any later version.
	 
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
		
	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
	
	The author can be contacted at:
	...
*/
License file for GPL.

If you want to release it in the public domain, you could package the .cpp file, the documentation and the plugin itself.
Wilbert is offline   Reply With Quote
Old 1st May 2010, 16:39   #17  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,492
I've updated the zip file linked above (and here).

I make no apologies for my coding style!

David
wonkey_monkey is offline   Reply With Quote
Old 2nd May 2010, 02:32   #18  |  Link
Zep
Registered User
 
Join Date: Jul 2002
Posts: 587
Quote:
Originally Posted by Ashley_Pomeroy View Post
In fact I've written a blog post about it, here, complete with a sample video of me on my bike:
http://women-and-dreams.blogspot.com...g-video-2.html

Great video nice job! music and speed up are really cool. What you need though is a surprise ending for those that watch the whole way. Like say a buxom blonde that you ride by and get caught looking so you then turn your head forward again but too late you hit a bench and flip over the handle bars all caught on camera. You can fade it to black just before you hit the ground. THAT i would love to see!


(haha all kidding aside great video keep making them!)
Zep is offline   Reply With Quote
Old 28th April 2011, 13:56   #19  |  Link
Efenstor
Registered User
 
Join Date: Aug 2008
Location: Krasnoyarsk, Russian Federation
Posts: 90
Multithreaded version

Just made a multithreaded version of Defish v1.1. Enjoy!
http://www.efenstor.net/defish_mt.zip (dll+source)
Efenstor is offline   Reply With Quote
Old 28th April 2011, 16:30   #20  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,492
Quote:
Originally Posted by Efenstor View Post
Just made a multithreaded version of Defish v1.1. Enjoy!
http://www.efenstor.net/defish_mt.zip (dll+source)
Nifty, thanks!

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 11:30.


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