Lab9-Blend-Chromakey


5130181321  ¹Ò³Ѱ¾ÑªÃì ÇÔ¹Ô¨Á§¤ÅÊÔ¹ (COM22023) (9/19/2012 (2:41:38 PM))

MiniQuiz + TestScript
JLab>java Selftest 

JLab> testBlend     : ok ok ok ok ok  (5.0/5.0)
JLab> testChromaKey : ok ok ok ok ok  (5.0/5.0)
JLab> : -----------------------------
JLab> : ?????? 10.0 ????? (???? 10.0)
JLab> : -----------------------------
JLab> :<POINT>10.0</POINT> (<TOTAL>10.0</TOTAL> )
JLab>

ä´é 10 ¤Ðá¹¹
Source Code
import jlab.graphics.DWindow;

public class ChromaKey {

  public static void main(String[] args) {
    DWindow fg = new DWindow();
    fg.loadImage("bird.gif");
    int w = fg.getWidth();
    int h = fg.getHeight();

    DWindow bg = new DWindow();
    bg.loadImage("sky.jpg",w, h);
    DWindow out = new DWindow(w, h);
    
    fg.setLocation(10, 10);
    bg.setLocation(10 + fg.getWidth(), 10);
    out.setLocation(10 + 2*fg.getWidth(), 10);
  
    out.setPixmap(chromaKey(fg.getPixmap(), bg.getPixmap(), DWindow.GREEN));
  }
  //-----------------------------------------------------------------
  public static int[][] chromaKey(int[][] fg, int[][] bg, int c) {
    int w = fg.length;
    int h = fg[0].length;
    int[][] b = new int[w][h];
    for (int x = 0; x < w; x++) {
      for (int y = 0; y < h ; y++) {
        if (fg[x][y] == c){
          b[x][y] = bg[x][y];
        }else{ 
          b[x][y] = fg[x][y];
         }
          
      }
    }
    return b;
  }
  //-----------------------------------------------------------------
}
import jlab.graphics.DWindow; public class Blend { public static void main(String[] args) { int w = 300, h = 300; DWindow pic1 = new DWindow(w, h); DWindow pic2 = new DWindow(w, h); DWindow out = new DWindow(w, h); pic1.loadImage("cat.jpg", w, h); pic2.loadImage("baby.jpg", w, h); pic1.setLocation(10, 10); pic2.setLocation(10 + w, 10); out.setLocation(10 + 2 * w, 10); while (true) { for (double a = 0; a <= 1; a += 0.1) { int[][] b = blend(pic1.getPixmap(), pic2.getPixmap(), a); out.setPixmap(b); } for (double a = 1; a >= 0; a -= 0.1) { int[][] b = blend(pic1.getPixmap(), pic2.getPixmap(), a); out.setPixmap(b); } } } //----------------------------------------------------------------- public static int[][] blend(int[][] b1, int[][] b2, double a) { int w = b1.length; int h = b1[0].length; int[][] b3 = new int[w][h]; for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { int rb1 = DWindow.getR(b1[x][y]); int rb2 = DWindow.getR(b2[x][y]); int gb1 = DWindow.getG(b1[x][y]); int gb2 = DWindow.getG(b2[x][y]); int bb1 = DWindow.getB(b1[x][y]); int bb2 = DWindow.getB(b2[x][y]); int re = (int)(a * rb1 + (1 - a) * rb2); int gr = (int)(a * gb1 + (1 - a) * gb2); int bl = (int)(a * bb1 + (1 - a) * bb2); b3[x][y] = DWindow.mixRGB(re,gr,bl); } } return b3; } //----------------------------------------------------------------- }
SM=0, CM=2, ST=3, KY=15, TR=60:00
ERR = 60:00 ;
ERR = 60:00 ;