Sign in to follow this  
Followers 0
TechnoRobbo

TR's Reverse Fisheye v1.0

4 posts in this topic

TechnoRobbo's Reverse Fisheye v1.0

Removes or reduces the fisheye distortion to produce a panoramic image.

 

This plugin was developed while assisting another user. It got some reps and downloads so I decided to publish it.

There were 2 algorithms I developed - Linear and Circular. Which one you use is up to you.

 

 

 
Image Attributions:
Jimee at en.wikipedia
Cezary Piwowarski
National Aeronautics and Space Administration 

 

ReverseFish.png?raw=1

 

The Codelab Source Code (for programmers)

Hidden Content:

// Submenu: Distort
// Name: TR's ReverseFishEye
// Title: TR's ReverseFishEye - v1.0
// Author: TechnoRobbo
// URL: http://www.technorobbo.com

#region UICode
byte Amount1 = 0; // [1] Reverse Type|Linear|Circular
#endregion

void Render(Surface dst, Surface src, Rectangle rect)
{
  
    Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
    double CenterX = ((selection.Right - selection.Left) / 2)+selection.Left;
    double CenterY= ((selection.Bottom - selection.Top) / 2)+selection.Top;

    double offx ,offy ,u, v;

    ColorBgra CurrentPixel;

    if (Amount1==1){
        
        for (float y = rect.Top; y < rect.Bottom; y++)
        {
            for (float x = rect.Left; x < rect.Right; x++)
            {
                //find direction and distance
                
                u = (x - CenterX ) / CenterX ;
                v = (y - CenterY ) / CenterY ;
    
                double wide = Math.Sqrt(1 - v * v);
                wide = wide * u * CenterX ;
    
                offx =wide + CenterX;
                offy =y;
    
    
                CurrentPixel = src.GetBilinearSample((float)offx,(float)offy);
                dst[(int)x,(int)y]=CurrentPixel;  
            }
        }
    }else{
        for (float y = rect.Top; y < rect.Bottom; y++)
        {
            for (float x = rect.Left; x < rect.Right; x+=.5f)
            {
                //find direction and distance
                double maxradx = x-CenterX ;
                double maxrady = y-CenterY;
                double howfar = Math.Sqrt(maxradx * maxradx + maxrady * maxrady);
                double dirz =  Math.Atan2(maxrady,maxradx);
                double mymax = maxradx *  Math.Tan(dirz);
                double maxfar = Math.Sqrt(CenterX * CenterX + mymax * mymax);
                double normal =  howfar/maxfar;
                offx = (float)(CenterX +  Math.Cos(dirz) * CenterX * normal);
                offy = (float)(CenterY +  Math.Sin(dirz) * CenterY * normal);
                
                CurrentPixel = src.GetBilinearSample((float)offx,(float)offy);
                dst[(int)x,(int)y]=CurrentPixel;
  
            }
        }
    }
   
}

 

The Plugin

ReverseFisheye.zip

 

PDN 3.5 version ReverseFisheye35.zip

Edited by TechnoRobbo
2

Share this post


Link to post
Share on other sites

Very interesting,,,hhhmmm,,,,already have some ideas for some other uses,,let you know how I make out.  Thanks TR

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0