import numpy as np; from skimage import io,transform
file_path='https://raw.githubusercontent.com/'+\
'OlgaBelitskaya/data/main/patterns/'
file1,file2='01_01_001.png','01_01_002.png'
def preprocess_img(file1,file2,file_path=file_path):
img1,img2=io.imread(file_path+file1),io.imread(file_path+file2)
imgbw1,imgbw2=np.ones(img1.shape[:2]),np.ones(img2.shape[:2])
imgbw1[img1[:,:,1]<int(128)],imgbw2[img2[:,:,1]<int(127)]=0,0
coord1=np.array(np.where(imgbw1<1)).T; coord=coord1
coord2=np.array(np.where(imgbw2<1)).T
if coord1.shape[0]>coord2.shape[0]: coord1,coord2=coord2,coord
while not coord2.shape==coord1.shape:
0,coord2.shape[0]-1,coord2.shape[0]-coord1.shape[0])
coord2=np.delete(coord2,list(randi),axis=0)
coord1,coord2=preprocess_img(file1,file2)
def create_coords(coord1,coord2):
for el in [coord1,coord2]:
fx=.025+.95*(fx-fx.min())/(fx.max()-fx.min())
fy=.025+.95*(fy-fy.min())/(fy.max()-fy.min())
el=np.array([[fx[i],fy[i]] for i in range(len(fx))])
coords=create_coords(coord1,coord2)
steps=20; img_size_out=256
def interpolate_hypersphere(v1,v2,steps):
v1norm=np.linalg.norm(v1); v2norm=np.linalg.norm(v2)
vectors=[]; v2normalized=v2*(v1norm/v2norm)
for step in range(steps):
interpolated=v1+(v2normalized-v1)*step/(steps-int(1))
interpolated_norm=np.linalg.norm(interpolated)
interpolated_normalized=\
interpolated*(v1norm/interpolated_norm)
vectors.append(interpolated_normalized)
[interpolate_hypersphere(coords[1],coords[0],steps),
interpolate_hypersphere(coords[0],coords[1],steps)])
No comments:
Post a Comment