Digital Signal Processing Reference
In-Depth Information
C.14 Operationen auf
Bildfolgen (Stacks)
// class AlphaBlendStack_ (continued)
47
48
49
public void run(ImageProcessor bgIp) {
Programm C.3
Alpha Blending (Teil 2).
// bgIp = background image
50
51
52
if(runDialog()) { //open dialog box (returns false if cancelled)
int w = bgIp.getWidth();
53
int h = bgIp.getHeight();
54
55
56
// prepare foreground image
ImageProcessor fgIp =
57
fgIm.getProcessor().convertToByte(false);
58
ImageProcessor fgTmpIp = bgIp.duplicate();
59
60
61
// create image stack
ImagePlus movie =
62
NewImage.createByteImage("Movie",w,h,nFrames,0);
63
ImageStack stack = movie.getStack();
64
65
66
// loop over stack frames
for (int i=0; i<nFrames; i++) {
67
// transparency of foreground image
68
double iAlpha = 1.0 - (double)i/(nFrames-1);
69
ImageProcessor iFrame = stack.getProcessor(i+1);
70
71
72
// copy background image to frame i
iFrame.insert(bgIp,0,0);
73
iFrame.multiply(iAlpha);
74
75
76
// copy foreground image and make transparent
fgTmpIp.insert(fgIp,0,0);
77
fgTmpIp.multiply(1-iAlpha);
78
79
80
// add foreground image frame i
ByteBlitter blitter =
81
new ByteBlitter((ByteProcessor)iFrame);
82
blitter.copyBits(fgTmpIp,0,0,Blitter.ADD);
83
}
84
85
86
// display movie (image stack)
movie.show();
87
}
88
}
89
90
91 } // end of class AlphaBlendStack_
Search WWH ::




Custom Search