<img src='../figures/cartesianas.jpg',width=300pt></img>
<img src='../figures/polar.jpg',width=300pt></img>
In [2]:
import numpy as np
def polar(f, domain, thetamax = 2 * np.pi):
import ia898.src as ia
m,n = f.shape
dm,dn = domain
Ry,Rx = np.floor(np.array(f.shape)/2)
b = min(Ry,Rx)/dm
a = thetamax/dn
y,x = np.indices(domain)
XI = Rx + (b*y)*np.cos(a*x)
YI = Ry + (b*y)*np.sin(a*x)
g = ia.interpollin(f, np.array([YI.ravel(), XI.ravel()]))
g = f[YI.astype(np.int),XI.astype(np.int)]
g.shape = domain
return g
In [3]:
testing = (__name__ == "__main__")
if testing:
import numpy as np
import sys,os
ia898path = os.path.abspath('../../')
if ia898path not in sys.path:
sys.path.append(ia898path)
import ia898.src as ia
%matplotlib inline
import matplotlib.image as mpimg
In [4]:
if testing:
f = np.array([[1,0,0,0,0,0],
[0,0,0,0,0,0],
[0,0,0,1,0,0],
[0,0,0,0,0,1],
[0,0,0,0,0,0]])
g = polar(f, (6,6))
print(g)
In [5]:
if testing:
f = mpimg.imread("../data/cameraman.tif")
ia.adshow(f, "Figure a) - Original Image")
g = polar(f,(250,250))
ia.adshow(g, "Figure b) - Image converted to polar coordinates, 0 to 2*pi")
g = polar(f,(250,250), np.pi)
ia.adshow(g, "Figure c) - Image converted to polar coordinates, 0 to pi")
In [6]:
if testing:
f = mpimg.imread('../data/astablet.tif')
ia.adshow(f,'original')
g = polar(f, (256,256))
ia.adshow(g,'polar')
f1 = f.transpose()
ia.adshow(f1,'f1: transposed')
g1 = polar(f1, (256,256))
ia.adshow(g1,'polar of f1')
In [ ]: