Everything is going well but ihe particles never form completely on the black area of…
- User
Everything is going well but ihe particles never form completely on the black area of two.jpeg, this image is of words those words are in black letters the particles should form them letters in the image you should never see the second image but you should see the particles form it does that make any sense? import numpy as np import os import time from PIL import Image from moviepy.editor import VideoClip from moviepy.video.fx.all import fadein, fadeout from tqdm import tqdm
Paths
image_one_path = '/home/daddy/morph/one.jpeg' image_two_path = '/home/daddy/morph/two.jpeg' # Changed to two.jpeg output_path = '/home/daddy/morph/output' output_filename = f'morph{int(time.time())}.mp4'
Function to create each frame of the video
def make_frame(t): if t < duration1: # Display the first image frame_array = img1_array.copy() elif t < duration1 + duration2: # Morphing effect with particle explosion and implosion progress = (t - duration1) / duration2 # Normalize progress to [0, 1]
code# Create an empty frame with transparency frame_array = np.zeros_like(img1_array) for idx, (x, y) in enumerate(particle_positions): # Extract the patch from the first image patch = img1_array[y:y+particle_size, x:x+particle_size].copy() # Explosion offsets offset_x, offset_y = explosion_offsets[idx] if progress < 0.5: # Explosion phase explosion_progress = progress * 2 # Scale progress to [0, 1] current_x = x + explosion_progress * offset_x current_y = y + explosion_progress * offset_y else: # Implosion phase implosion_progress = (progress - 0.5) * 2 # Scale progress to [0, 1] # Target positions in the second image target_x, target_y = particle_to_target_position.get((x, y), (x, y)) # Current position moves from exploded position to target position current_x = (x + offset_x) + implosion_progress * (target_x - (x + offset_x)) current_y = (y + offset_y) + implosion_progress * (target_y - (y + offset_y)) # Convert positions to integers and ensure they stay within frame boundaries current_x = int(np.clip(current_x, 0, width - particle_size)) current_y = int(np.clip(current_y, 0, height - particle_size)) # Place the current patch onto the frame frame_array[current_y:current_y+particle_size, current_x:current_x+particle_size] = patch else: # Display the second image frame_array = img2_array.copy() # Convert the NumPy array back to an image frame_image = Image.fromarray(frame_array, 'RGBA') # Return frame as an RGB image (MoviePy expects RGB format) return np.array(frame_image.convert('RGB')) - Assistant