SlideServe
Menu
Préférences
© SlideServe · v2026

Animate Birds on Background using Loops in MATLAB

linore avatar
9 diapositives · 233 Views · Sep 15, 2014

This MATLAB tutorial by Dr. Cynthia Lee from UCSD focuses on using loops to create animations of birds over a large background image of Zion National Park. The presentation demonstrates how to read multiple bird images and animate them sequentially on a canvas while utilizing a greenscreen technique to paste the bird images onto the background. It includes scripts for both simple and offset animations, offering a hands-on approach for understanding loops and image manipulation in MATLAB. The example highlights the importance of adapting filenames to your own images.

Animate Birds on Background using Loops in MATLAB - slide 1
01 / 9Animate Birds on Background using Loops in MATLAB
1 / 17

Télécharger la présentation

Animate Birds on Background using Loops in MATLAB
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Introduction to Programming in MATLAB Intro. MATLAB Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.Based on a work at www.peerinstruction4cs.org.

  2. LOOPS: ANIMATION WITH LOOPS

  3. Write a loop that displays all six bird images in order % script: AnimateBird bird1 = imread(‘bird1.jpg’); bird2 = imread(‘bird2.jpg’); bird3 = imread(‘bird3.jpg’); bird4 = imread(‘bird4.jpg’); bird5 = imread(‘bird5.jpg’); bird6 = imread(‘bird6.jpg’); birds = cat(4,bird1,bird2,bird3,bird4,bird5,bird6); for i = 1:6 imshow(birds(:,:,:,i)); drawnow; end

  4. [NOT A SLIDE: raw images] This is a container for these image files from the example. Please use your own NOT these! And then you would change the text of the slides in this lecture to have filenames that make sense for YOUR example. But these give you an idea of what kind/size images I was using for this example.

  5. Greenscreena small image (bird) onto a large background (Zion Natl. Park) function [zion] = PasteBirdonBackground(bird,zion) % create a white canvas the size of the background largecanvas = uint8(zeros(size(zion))); % canvas is all black, same size as zion image largecanvas = 255-largecanvas; % change to all white % paste the bird into the top left corner of the canvas ?????? % select only the bird part of the canvas filter = largecanvas(:,:,1) < 30; filter = cat(3,filter,filter,filter); % greenscreen zion(filter) = largecanvas(filter); end

  6. Animate a small image (bird) on a large background (Zion Natl. Park) % script: AnimateBird zion = imread(‘zion.jpg’); bird1 = imread(‘bird1.jpg’); bird2 = imread(‘bird2.jpg’); bird3 = imread(‘bird3.jpg’); bird4 = imread(‘bird4.jpg’); bird5 = imread(‘bird5.jpg’); bird6 = imread(‘bird6.jpg’); birds = cat(4,bird1,bird2,bird3,bird4,bird5,bird6); for i = 1:6 bird = birds(:,:,:,i); imshow(PasteBirdonBackground(bird,zion)); % this function on previous slide drawnow; end

  7. Greenscreena small image (bird) across a large background (Zion Natl. Park) function [zion] = PasteBirdonBackground(bird,zion) % create a white canvas the size of the background largecanvas = uint8(zeros(size(zion))); % canvas is all black, same size as zion image largecanvas = 255-largecanvas; % change to all white % paste the bird 10 PIXELS TO THE RIGHT OF the top left corner of the canvas ?????? % select only the bird part of the canvas filter = largeanvas(:,:,1) < 30; filter = cat(3,filter,filter,filter); % greenscreen zion(filter) = largecanvas(filter); end

  8. Greenscreena small image (bird) across a large background (Zion Natl. Park) function [zion] = PasteBirdonBackground(bird,zion,offset) % create a white canvas the size of the background largecanvas = uint8(zeros(size(zion))); % canvas is all black, same size as zion image largecanvas = 255-largecanvas; % change to all white % paste the bird “OFFSET” PIXELS TO THE RIGHT OF the top left corner of the canvas largecanvas(1+offset:size(bird,1)+offset,1:size(bird,2),:) = bird; % select only the bird part of the canvas filter = largeanvas(:,:,1) < 30; filter = cat(3,filter,filter,filter); % greenscreen zion(filter) = largecanvas(filter); end Add an “offset” argument to the function, so we can decide how far to the right we want to paste.

  9. Move a small image (bird) across a large background (Zion Natl. Park) % script: AnimateBird zion = imread(‘zion.jpg’); bird = imread(‘bird1.jpg’); for offset = ?????? imshow(PasteBirdonBackground(bird,zion,offset)); drawnow; end Goal: Use “offset” version of the function—on previous slide—so we can specify different offsets to make the bird move. ZION BIRD BIRD