Sign in to follow this  
TechnoRobbo

TR's Reverse Fisheye v1.0

Recommended Posts

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
  • Upvote 2

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this