I have developed a rewiring network whose edges shrink or expand depending on some factors. This way some nodes get closer when the conditions are met, and some others move away from each other under those conditions. The rewiring process is controlled by a loop, and each stage of the loop creates an image that forms part of the resulting final GIF.
The original GIF can look like this, and as can be seen, the transition from one frame to the next is very abrupt, sharp:
The code I use for it was:
def generateGif():
images = []
nImages = len(os.listdir(f"./generatedImages/Network{networkNum}"))
for iter in range(0, nImages):
fileName = f"./generatedImages/Network{networkNum}/Random Network - {iter}.png"
images.append(imageio.imread(fileName))
create_folder("./generatedGif")
nGifs = len(os.listdir("./generatedGif"))
imageio.mimsave(f'./generatedGif/network{nGifs}.gif', images, fps=2)
Now, for I have tried including a transition between frames, modifying the previous code, in the following way:
def generateGif():
images = []
nImages = len(os.listdir(f"./generatedImages/Network{networkNum}"))
for iter in range(0, nImages):
fileName = f"./generatedImages/Network{networkNum}/Random Network - {iter}.png"
images.append(imageio.imread(fileName))
# Perform smooth transition between frames
blended_images = []
num_frames = len(images)
alpha_start= 0
alpha_end = 1
for i in range(num_frames - 1):
alpha = np.linspace(alpha_start, alpha_end, num=num_frames)[i]
blended_image = alpha_blend(images[i], images[i+1], alpha)
print('BLENDED IMAGES type and shape', blended_image.dtype, blended_image.shape)
blended_images.append(blended_image)
create_folder_if_non_existing("./generatedGif")
nGifs = len(os.listdir("./generatedGif"))
imageio.mimsave(f'./generatedGif/network{nGifs}.gif', blended_images, fps=2)
# Performs alpha blending between two frames to create a smooth transition effect.
def alpha_blend(image1, image2, alpha):
blended_image = (1 - alpha) * image1 + alpha * image2
blended_image = np.clip(blended_image, 0, 255).astype(np.uint8)
return blended_image
However, the result is bad (not showing continuity for the nodes movement):
Any help would be much appreciated. Thank you for reading.