import warnings,numpy as np
from skimage import io,transform
warnings.filterwarnings('ignore')
def load_img(file_path,file_name,img_size):
img=io.imread(file_path+file_name)
img=transform.resize(img,[img_size,img_size])
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)
return np.array(vectors)*255
def _vector(file1=[1,2,..,5],file2=[11,12,..,15],
steps=list(range(20,100,10)),img_size=[300,350,400]):
file_path='https://raw.githubusercontent.com/'+\
'OlgaBelitskaya/data/main/decors/'
file_name1='00_00_%03d'%(file1)+'.png'
file_name2='00_00_%03d'%(file2)+'.png'
img1=load_img(file_path,file_name1,img_size)
img2=load_img(file_path,file_name2,img_size)
imgs=np.vstack([interpolate_hypersphere(img1,img2,steps),
interpolate_hypersphere(img2,img1,steps)])
imgs[i],frame=False,transparent=True,figsize=4)
for i in range(2*steps)]).show()
No comments:
Post a Comment