, . , . 45- , , , , . , , /* */ ( , Python, :)).
, ! .
:
, , - 3D-, , "" "" . , , , . interp.
, , "before" "after" ideal true:). , - .
import pdb
import matplotlib.pyplot as plt
import numpy as np
from skimage import measure, transform, img_as_float
from mpl_toolkits.mplot3d import Axes3D
def flatten_list(L):
for item in L:
try:
for i in flatten_list(item): yield i
except TypeError:
yield item
true_input = np.array([range(i,i+10) for i in range(20)])
ideal = np.array([range(10)]*20)
true_control_pts = []
ideal_control_pts = []
OLD_true=[]
OLD_ideal=[]
for lam in [x+0.5 for x in ideal[0]]:
try:
tc = measure.find_contours(true_input, lam)[0]
ic = measure.find_contours(ideal, lam)[0]
nc = np.zeros(ic.shape)
nc[:, 0] = ic[:, 0]
tc_sorted = tc[tc[:,0].argsort()]
nc[:, 1] = np.interp(ic[:, 0], tc_sorted[:, 0], tc_sorted[:, 1],
left=np.nan, right=np.nan)
indices = ~np.isnan(nc).any(axis=1)
nc_nonan = nc[indices]
ic_nonan = ic[indices]
true_control_pts.append(nc_nonan.flatten().tolist())
ideal_control_pts.append(ic_nonan.flatten().tolist())
OLD_true.append(nc)
OLD_ideal.append(ic)
except (IndexError,AttributeError):
pass
true_flat = list(flatten_list(true_control_pts))
ideal_flat = list(flatten_list(ideal_control_pts))
true_control_pts = np.array(true_flat)
ideal_control_pts = np.array(ideal_flat)
length = len(true_control_pts)/2
true_control_pts = true_control_pts.reshape(length,2)
ideal_control_pts = ideal_control_pts.reshape(length,2)
image = np.array([range(i,i+10) for i in range(20)]) / 30.0
image_float = img_as_float(image)
fig = plt.figure()
plt.imshow(image_float, origin='lower', interpolation='none')
plt.title('Input image')
fig.show()
tform = transform.PiecewiseAffineTransform()
tform.estimate(true_control_pts, ideal_control_pts)
out = transform.warp(image, tform)
pdb.set_trace()
fig, ax = plt.subplots()
ax.imshow(out, origin='lower', interpolation='none')
plt.title('Should be parallel lines')
fig.show()
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
fig.show()
for rowidx in range(length):
ax.plot([true_control_pts[rowidx,0], ideal_control_pts[rowidx,0]],
[true_control_pts[rowidx,1], ideal_control_pts[rowidx,1]],
[0,1])
input()
:

:

, , .
import pdb
import matplotlib.pyplot as plt
import numpy as np
from skimage import measure, transform, img_as_float
from mpl_toolkits.mplot3d import Axes3D
def flatten_list(L):
for item in L:
try:
for i in flatten_list(item): yield i
except TypeError:
yield item
def equispace(data, npts):
x,y = data.T
xd =np.diff(x)
yd = np.diff(y)
dist = np.sqrt(xd**2+yd**2)
u = np.cumsum(dist)
u = np.hstack([[0],u])
t = np.linspace(0,u.max(),npts)
xn = np.interp(t, u, x)
yn = np.interp(t, u, y)
return np.column_stack((xn, yn))
true_input = np.array([range(i,i+10) for i in range(20)])
ideal = np.array([range(10)]*20)
true_control_pts = []
ideal_control_pts = []
OLD_true=[]
OLD_ideal=[]
for lam in [x+0.5 for x in ideal[0]]:
try:
tc = measure.find_contours(true_input, lam)[0]
ic = measure.find_contours(ideal, lam)[0]
nc_by_t = equispace(tc,ic.shape[0])
ic_by_t = equispace(ic,ic.shape[0])
true_control_pts.append(nc_by_t)
ideal_control_pts.append(ic_by_t)
except (IndexError,AttributeError):
pass
pdb.set_trace()
true_flat = list(flatten_list(true_control_pts))
ideal_flat = list(flatten_list(ideal_control_pts))
true_control_pts = np.array(true_flat)
ideal_control_pts = np.array(ideal_flat)
length = len(true_control_pts)/2
true_control_pts = true_control_pts.reshape(length,2)
ideal_control_pts = ideal_control_pts.reshape(length,2)
image = np.array([range(i,i+10) for i in range(20)]) / 30.0
image_float = img_as_float(image)
fig = plt.figure()
plt.imshow(image_float, origin='lower', interpolation='none')
plt.title('Input image')
fig.show()
tform = transform.PiecewiseAffineTransform()
tform.estimate(true_control_pts, ideal_control_pts)
out = transform.warp(image, tform)
pdb.set_trace()
fig, ax = plt.subplots()
ax.imshow(out, origin='lower', interpolation='none')
plt.title('Should be parallel lines')
fig.show()
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
fig.show()
for rowidx in range(length):
ax.plot([true_control_pts[rowidx,0], ideal_control_pts[rowidx,0]],
[true_control_pts[rowidx,1], ideal_control_pts[rowidx,1]],
[0,1])
input()
-: X Y , , ? , , . :
nc_by_t = equispace(tc,ic.shape[0])
ic_by_t = equispace(ic,ic.shape[0])
ic.shape[0] , . equispace . , , , , , , ic. , ; 100 .
, . , . X Y? ? ( )?
,
? !

, .
( - . ===========)
import pdb
import matplotlib.pyplot as plt
import numpy as np
from skimage import measure, transform, img_as_float
from mpl_toolkits.mplot3d import Axes3D
def test_figure(data,title):
image_float = img_as_float(data)
fig = plt.figure()
plt.imshow(image_float, origin='lower', interpolation='none')
plt.title(title)
fig.show()
def flatten_list(L):
for item in L:
try:
for i in flatten_list(item): yield i
except TypeError:
yield item
def equispace(data, npts):
x,y = data.T
xd =np.diff(x)
yd = np.diff(y)
dist = np.sqrt(xd**2+yd**2)
u = np.cumsum(dist)
u = np.hstack([[0],u])
t = np.linspace(0,u.max(),npts)
xn = np.interp(t, u, x)
yn = np.interp(t, u, y)
return np.column_stack((xn, yn))
true_input = np.array([range(i,i+20) for i in range(30)])
ideal = np.array([range(20)]*30)
test_figure(true_input / 50.0, 'true_input')
test_figure(ideal / 20.0, 'ideal')
true_control_pts = []
ideal_control_pts = []
OLD_true=[]
OLD_ideal=[]
for lam in [x+0.5 for x in ideal[0]]:
try:
tc = measure.find_contours(true_input, lam)[0]
ic = measure.find_contours(ideal, lam)[0]
nc_by_t = equispace(tc,ic.shape[0])
ic_by_t = equispace(ic,ic.shape[0])
true_control_pts.append(nc_by_t)
ideal_control_pts.append(ic_by_t)
except (IndexError,AttributeError):
pass
true_flat = list(flatten_list(true_control_pts))
ideal_flat = list(flatten_list(ideal_control_pts))
true_control_pts = np.array(true_flat)
ideal_control_pts = np.array(ideal_flat)
length = len(true_control_pts)/2
true_control_pts = true_control_pts.reshape(length,2)
ideal_control_pts = ideal_control_pts.reshape(length,2)
image = np.array([range(i,i+10) for i in range(20)]) / 30.0
image = np.concatenate( (np.zeros((20,5)),image,np.zeros((20,5))), 1)
image = np.concatenate( (np.zeros((5,20)),image,np.zeros((5,20))), 0)
image_float = img_as_float(image)
fig = plt.figure()
plt.imshow(image_float, origin='lower', interpolation='none')
plt.title('Input image')
fig.show()
tform = transform.PiecewiseAffineTransform()
tform.estimate(true_control_pts, ideal_control_pts)
out = transform.warp(image, tform)
pdb.set_trace()
fig, ax = plt.subplots()
ax.imshow(out, origin='lower', interpolation='none')
plt.title('Should be parallel lines')
fig.show()
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
fig.show()
for rowidx in range(length):
ax.plot([true_control_pts[rowidx,0], ideal_control_pts[rowidx,0]],
[true_control_pts[rowidx,1], ideal_control_pts[rowidx,1]],
[0,1])
input()