Jump to content

I would like to be able to recreate spherize effect in Paint.NET


Reptillian

Recommended Posts

e7a802a7f29b4de83e53fcd9157ad44df7d8042d

 

What this effect is mapping a spherical deformation onto a image, the percentage represent the height at the center of the sphere. In Photoshop, the effect can be in reverse direction. I have yet to found a free solution to this. Not found in GIMP, Krita, or G'MIC either.

G'MIC Filter Developer

Link to comment
Share on other sites

^ Shape 3D certainly has the most advanced features. If you're looking for a lightweight alternative, try...

 

Drumskin. Has no lighting/shadowing options - it just reformats the image:

 

or even Planetoid. This has minimal lighting/shadowing options.

 

Link to comment
Share on other sites

Look in the Plugin Index (link in my signature) for plugins called Lens and Magnify

Link to comment
Share on other sites

These I've tried, still not quite the same. My option seem to be using a 3D program as a work around to get the same effect.

G'MIC Filter Developer

Link to comment
Share on other sites

I have attempted to replicate the effect on a 3D program, I think I am finding one thing. It appears the spherize works by not scaling the sphere, but rather lowering the elevation of a sphere, and lowering the y location of the sphere, and then scaling until it fits well, and finally apply reflection. That's probably how the the spherize effect in Photoshop works. For the reverse direction, it works in the reverse of this. 

G'MIC Filter Developer

Link to comment
Share on other sites

The TR's Fish Eye was definitely the one I was looking for. Now, the reverse isn't what I'm looking for. But, I think TR"s Fish Eye can be manipulated to get the reverse direction as the source code is released there. In Photoshop, you have the option to do the reverse direction of spherize, not fixing it.

G'MIC Filter Developer

Link to comment
Share on other sites

Here's some code I wrote a while ago (for some reason I can't recall) that may or may not help:

 

Spoiler

 


// Name: DeFisheye
// Submenu: Distort
// Author: MJW
// Title: DeFisheye
// Version: 1.0.*
// Desc: Reverse fisheye distortion
// Keywords: reverse fisheye distortion
// URL:
// Help:
#region UICode
PanSliderControl Amount1 = Pair.Create(0.000,0.000); // Center
DoubleSliderControl Amount2 = 100; // [1,1000] Radius
DoubleSliderControl Amount3 = 1; // [0,10] Distortion
DoubleSliderControl Amount4 = 0; // [-1,1] Tweak
#endregion

Surface Src;
double cX, cY;
double r, r2;
double k, k2;
double tweak;

void Render(Surface dst, Surface src, Rectangle rect)
{
    Src = src;
    
    // Delete any of these lines you don't need
    Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
    int CenterX = ((selection.Right - selection.Left) / 2)+selection.Left;
    int CenterY = ((selection.Bottom - selection.Top) / 2)+selection.Top;
    ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor;
    ColorBgra SecondaryColor = (ColorBgra)EnvironmentParameters.SecondaryColor;
    int BrushWidth = (int)EnvironmentParameters.BrushWidth;
    
    double xScale = 0.5f * src.Width, yScale = 0.5f * src.Height;
    cX = xScale * ((float)Amount1.First + 1.0f);
    cY = yScale * ((float)Amount1.Second + 1.0f);
    r = Amount2;
    r2 = Sq(r);
    k = Amount3 / r;
    k2 = Sq(k);
    tweak = Amount4;
    
    for (int y = rect.Top; y < rect.Bottom; y++)
    {
        if (IsCancelRequested) return;
        for (int x = rect.Left; x < rect.Right; x++)
        {
            dst[x, y] = Transform(x, y);
        }
    }
}

// Not coded with an eye (or fisheye) toward efficiency.
ColorBgra Transform(int x, int y)
{
    double scale = 1.0;
    double fX = x, fY = y;
    
    double dX = fX - cX, dY = fY - cY;
    double inD2 = Sq(dX) + Sq(dY);
    if (inD2 != 0.0)
    {
        if (inD2 > r2)
            return ColorBgra.Transparent;
        double inD = Math.Sqrt(inD2);
        double kD = 1.0 + k2 * inD2;
        double kR = 1.0 - k2 * r2;
        double outD = inD * (1.0 + Math.Sqrt(1.0 - kD * kR)) / kD;

        // Scale to 0-1 for the tweak adjustment;
        outD /= r;
        outD *= tweak * (1.0 - outD) + 1.0;
        outD *= r;
        
        scale = outD / inD;
    }
    fX = scale * dX + cX;
    fY = scale * dY + cY;
    return Src.GetBilinearSample((float)fX, (float)fY);    
}

double Sq(double x)
{
    return x * x;
}

 

 

 

 

 

 

 

Link to comment
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.

×
×
  • Create New...