<p>Here is a solution in Python/OpenCV. It creates transformation maps that define the equations from output back to input and applies them using cv2.remap(). The equations come from <a href="https://arxiv.org/pdf/1509.06344.pdf" rel="nofollow noreferrer">https://arxiv.org/pdf/1509.06344.pdf</a> for the Elliptical Grid Mapping approach.</p>
<p>Input:</p>
<p><a href="https://i.stack.imgur.com/BiKqQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BiKqQ.png" alt="enter image description here" /></a></p>
<pre><code>import numpy as np
import cv2
import math

# References:
# https://arxiv.org/pdf/1509.06344.pdf
# http://squircular.blogspot.com/2015/09/mapping-circle-to-square.html
# Evaluate:
# u = x*sqrt(1-y**2/2)
# v = y*sqrt(1-x**2/2)
# u,v are input circle coordinates and x,y are output square coordinates

# read input
img = cv2.imread(&quot;rings.png&quot;)

# get dimensions and center
h, w = img.shape[:2]
xcent = w / 2
ycent = h / 2

# set up the maps as float32 from output square (x,y) to input circle (u,v)
map_u = np.zeros((h, w), np.float32)
map_v = np.zeros((h, w), np.float32)

# create u and v maps where x,y is measured from the center and scaled from -1 to 1
for y in range(h):
    Y = (y - ycent)/ycent
    for x in range(w):
        X = (x - xcent)/xcent
        map_u[y, x] = xcent * X * math.sqrt(1 - 0.5*Y**2) + xcent
        map_v[y, x] = ycent * Y * math.sqrt(1 - 0.5*X**2) + ycent

# do the remap
result = cv2.remap(img, map_u, map_v, cv2.INTER_LINEAR, borderMode = cv2.BORDER_REFLECT_101, borderValue=(0,0,0))

# save results
cv2.imwrite(&quot;rings_circle2square.png&quot;, result)

# display images
cv2.imshow('img', img)
cv2.imshow('result', result)
cv2.waitKey(0)
cv2.destroyAllWindows()
</code></pre>
<p>Result:</p>
<p><a href="https://i.stack.imgur.com/KcML9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KcML9.png" alt="enter image description here" /></a></p>
<p>Here is another example:</p>
<p>Input:</p>
<p><a href="https://i.stack.imgur.com/gQm8o.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gQm8o.png" alt="enter image description here" /></a></p>
<p>Result:</p>
<p><a href="https://i.stack.imgur.com/LiWuE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LiWuE.png" alt="enter image description here" /></a></p>
<p>And here is a 3rd example:</p>
<p>Input:</p>
<p><a href="https://i.stack.imgur.com/TbH2k.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TbH2k.jpg" alt="enter image description here" /></a></p>
<p>Result:</p>
<p><a href="https://i.stack.imgur.com/uw8vV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uw8vV.png" alt="enter image description here" /></a></p>
<p><strong>ADDITION</strong></p>
<p>Here is an alternate approach based upon the Simple Stretch equations in the reference above:</p>
<pre><code>import numpy as np
import cv2
import math

# References:
# https://arxiv.org/pdf/1509.06344.pdf
# Simple stretch equations
# read input
img = cv2.imread(&quot;rings.png&quot;)
#img = cv2.imread(&quot;ICM.png&quot;)
#img = cv2.imread(&quot;soccerball_small.jpg&quot;)

# get dimensions and center
h, w = img.shape[:2]
xcent = w / 2
ycent = h / 2

# set up the maps as float32 from output square (x,y) to input circle (u,v)
map_u = np.zeros((h, w), np.float32)
map_v = np.zeros((h, w), np.float32)

# create u and v maps where x,y is measured from the center and scaled from -1 to 1
# note: copysign(1,x) is signum(x) and returns 1 ,0, or -1 depending upon sign of x
for y in range(h):
    Y = (y - ycent)/ycent
    for x in range(w):
        X = (x - xcent)/xcent
        X2 = X*X
        Y2 = Y*Y
        XY = X*Y
        R = math.sqrt(X2+Y2)
        if R == 0:
            map_u[y, x] = xcent
            map_v[y, x] = ycent
        elif X2 &gt;= Y2:
            map_u[y, x] = xcent * math.copysign(1, X) * X2/R + xcent
            map_v[y, x] = ycent * math.copysign(1, X) * XY/R + ycent
        else:
            map_u[y, x] = xcent * math.copysign(1, Y) * XY/R + xcent
            map_v[y, x] = ycent * math.copysign(1, Y) * Y2/R + ycent

# do the remap
result = cv2.remap(img, map_u, map_v, cv2.INTER_LINEAR, borderMode = cv2.BORDER_REFLECT_101, borderValue=(0,0,0))

# save results
cv2.imwrite(&quot;rings_circle2square2.png&quot;, result)
#cv2.imwrite(&quot;ICM_circle2square2.png&quot;, result)
#cv2.imwrite(&quot;soccerball_small_circle2square2.png&quot;, result)

# display images
cv2.imshow('img', img)
cv2.imshow('result', result)
cv2.waitKey(0)
cv2.destroyAllWindows()
</code></pre>
<p>Input:</p>
<p><a href="https://i.stack.imgur.com/BjSfd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BjSfd.png" alt="enter image description here" /></a></p>
<p>Result:</p>
<p><a href="https://i.stack.imgur.com/qmXZz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qmXZz.png" alt="enter image description here" /></a></p>
<p>Input:</p>
<p><a href="https://i.stack.imgur.com/9S8V9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9S8V9.png" alt="enter image description here" /></a></p>
<p>Result:</p>
<p><a href="https://i.stack.imgur.com/tAn0h.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tAn0h.png" alt="enter image description here" /></a></p>
<p>Input:</p>
<p><a href="https://i.stack.imgur.com/7zoMI.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7zoMI.jpg" alt="enter image description here" /></a></p>
<p>Result:</p>
<p><a href="https://i.stack.imgur.com/E5wMj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/E5wMj.png" alt="enter image description here" /></a></p>
Turning Circle into Square. Solved: squircle package
<p>OpenCV / Python related:</p>
<p>Given a photo of a round object, how can you output that object flattened, <em>while adjusting for surface area?</em> Here is an example image of an input:</p>
<p><a href="https://i.stack.imgur.com/uotyY.jpg" rel="nofollow noreferrer">Soccer ball</a></p>
<p>It is similar to adjusting for camera distortion (turning a round object into flat one), but in this case the distortion comes from the object itself and not the camera.</p>
<p><a href="https://i.stack.imgur.com/1QSTz.jpg" rel="nofollow noreferrer">Distorted image</a>:</p>
<p><a href="https://i.stack.imgur.com/byDyY.jpg" rel="nofollow noreferrer">Undistorted image</a>:</p>
<p>Any suggestions would help. Thank you!</p>
<p>Edit: The package squircle is just what I needed, thank you fmw42!</p>