http:^^www.cs.cornell.edu^info^projects^zeno^rivl^rivl.html
来自「This data set contains WWW-pages collect」· HTML 代码 · 共 343 行 · 第 1/3 页
HTML
343 行
<LI>Assembly. This class provides "cut and paste" type operations on images and sequences.<BR><LI>Conversion. This class provides functions to convert between images and sequences, and to map image operations over the frames of a sequence.<BR><LI>Transforms. Image transforms used in this paper.<BR></UL>Sections 2.1 and 2.2 contain examples that clarify the use of image primitives and sequence primitives, respectively.<p><pre><A NAME="REF64418">Table 1: Image and sequence primitives</A> -----------------------------------------------------------------------------------------------Type Image Sequence Description operations operations Input/Output im_read seq_read Read image/sequence from disk im_write seq_write Write image/sequence to disk Geometric im_trans seq_shift Translate an image in space / shift a sequence in time im_scale[C] seq_scale Scale an image in space / scale a sequence in time im_rotate[C] Rotate an image [C = around its center] Assembly im_crop seq_crop Crop the specified region to make a new image/sequence im_concat seq_concat Concatenate multiple images/sequences end to end im_overlay seq_overlay Overlay multiple images/sequences in place Conversion ims_to_seq seq_to_ims Convert between a list of images and a sequence seq_map Apply a script to each image in the sequence Transforms im_fade Fade the image by a specified percentage im_resample Resample the image at a specified size im_blur Apply a blur filter to the image im_mask Make transparent all pixels below a certain intensity -----------------------------------------------------------------------------------------------</pre><H3><A NAME="HDR4">2. 1. Image Operations</A></H3>Consider the following Rivl fragment:<p><PRE> set image2 [im_scaleC $image1 [expr 1 - $p]] set image3 [im_rotateC $image2 [expr 360 * $p]]</PRE><A NAME="REF84651">Program 1: "Whirlpool" effect</A><p><B></B><I></I> <p>image1 is a Rivl image and p is a floating point value between 0 and 1. The first line calls im_scaleC to shrink image1 about its center by a factor of 1-p and assigns the result to image1. The second line calls im_rotateC to rotate image1 about its center by 360*p and again stores the result in image1. Figure 1 shows the effect of this fragment with several values of p.<p>The repeated use of set in this fragment is cumbersome. To remedy this problem, we borrowed an idiom from Scheme: any operator with the character "!" appended destructively modifies its first argument. Taking advantage of this notation, we can rewrite program <!WA25><!WA25><!WA25><!WA25><!WA25><!WA25><!WA25><!WA25><!WA25><!WA25><!WA25><!WA25><!WA25><!WA25><!WA25><!WA25><A HREF="http://www.cs.cornell.edu/Info/Projects/zeno/rivl/mm-95.html#REF84651">1</A> as:<p><PRE> im_scaleC! image1 [expr 1 - $p]] im_rotateC! image1 [expr 360 * $p]</PRE>Notice that the destructive operation omits the "$" in front of its first argument, whereas the non-destructive form requires the "$". This artifact is caused by the way Tcl implements pass-by-reference, a point we discuss in a related paper [<!WA26><!WA26><!WA26><!WA26><!WA26><!WA26><!WA26><!WA26><!WA26><!WA26><!WA26><!WA26><!WA26><!WA26><!WA26><!WA26><A HREF="http://www.cs.cornell.edu/Info/Projects/zeno/rivl/mm-95.html#REF18623">14</A>].<p>More complex effects can be constructed using Tcl constructs for looping, branching, procedure creation, and recursion. The Rivl program in figure 2 creates a fractal (Sierpinski's Gasket) from an arbitrary image.<p><!WA27><!WA27><!WA27><!WA27><!WA27><!WA27><!WA27><!WA27><!WA27><!WA27><!WA27><!WA27><!WA27><!WA27><!WA27><!WA27><A HREF="http://www.cs.cornell.edu/Info/Projects/zeno/rivl/mm95.figure.id.12.gif"><!WA28><!WA28><!WA28><!WA28><!WA28><!WA28><!WA28><!WA28><!WA28><!WA28><!WA28><!WA28><!WA28><!WA28><!WA28><!WA28><img src="http://www.cs.cornell.edu/Info/Projects/zeno/rivl/mm95.figure.id.12.gif"><B><A NAME="REF69077"><BR></a>Figure 1:</B> Output from program 1 for p = 0.1, 0.4, 0.7<p><!WA29><!WA29><!WA29><!WA29><!WA29><!WA29><!WA29><!WA29><!WA29><!WA29><!WA29><!WA29><!WA29><!WA29><!WA29><!WA29><A HREF="http://www.cs.cornell.edu/Info/Projects/zeno/rivl/mm95.figure.id.1.gif"><!WA30><!WA30><!WA30><!WA30><!WA30><!WA30><!WA30><!WA30><!WA30><!WA30><!WA30><!WA30><!WA30><!WA30><!WA30><!WA30><img src="http://www.cs.cornell.edu/Info/Projects/zeno/rivl/mm95.figure.id.1.gif"><B><A NAME="REF69077"><BR></a>Figure 2:</B> Fractal program and output for n= 1,2,3<p></A><p><H5><!WA31><!WA31><!WA31><!WA31><!WA31><!WA31><!WA31><!WA31><!WA31><!WA31><!WA31><!WA31><!WA31><!WA31><!WA31><!WA31><A HREF="#HDR3"><-- The Rivl Language</A></H5><H3><A NAME="HDR5">2. 2. Sequence Operations</A></H3>A sequence, the Rivl abstraction for video, can be thought of as a set of time-stamped images. Like image commands, sequence commands can be composed to express new operations. For instance, a common video editing operation is assembly, when two sequences are connected and written. The following Rivl fragment assembles the first 10 seconds of the sequence raiders.mpg and the sequence bobo.mpg, writing the result to out.mpg (all files are MPEG format):<p><PRE> set raiders [seq_read raiders.mpg] set bobo [seq_read bobo.mpg] seq_crop! raiders 0.0 10.0 seq_write [seq_concat $raiders $bobo] out.mpg</PRE>An important primitive in Rivl is seq_map. seq_map applies image effects to sequences, executing a given script for each image of a sequence and combining the resulting images into a new sequence. Seq_map is similar to map in Scheme. For example, consider the command<p><PRE> seq_map $clip {im_resample %1 100 75} </PRE>Seq_map evaluates the template command (im_resample %1 100 75) on each image in clip, substituting the current image wherever %1 appears in the template. The results are gathered and returned as a new sequence. Thus, this command returns a new sequence containing 100x75 ("thumbnail") versions of the images in clip.<p>Sometimes, rather than applying the same operation on each image in a sequence, it is desirable to vary the operation over time. For example, consider the operation of fading a sequence to black. This effect can be achieved by calling im_fade on each image in the sequence with a parameter that decreases over time. In this case, seq_map must call a procedure with a parameter that indicates the time of the image being modified. To this end, seq_map performs the following additional substitutions:<p><UL><LI>%t: Substitute the time stamp of the current image, in seconds<BR><LI>%l: Substitute the length of the sequence in seconds<BR><LI>%p: Substitute the relative time of the current image: %t divided by %l<BR></UL>Using this mechanism, fade-to-black can be expressed<p><PRE> seq_map $clip {im_fade %1 [expr 1-%p]} </PRE>When combined with sequence assembly operations, seq_map simplifies the expression of effects that are often used in transitions between two parts of a movie. For example, the procedure in figure 3 connects two sequences with a transition. The first parameter, transition, is a script to be passed to seq_map. MovieA & movieB are the two sequences to be joined, and duration is the time (in seconds) to apply the transition effect. Thus, connectWithTransition {im_fade %1 [expr 1-%p]} $jack $jill 5 connects two sequences jack and jill with a five second fade.<p><HR><PRE> proc connectWithTransition {transition movieA movieB duration} { set lengthA [seq_length $movieA]<BR> set lengthB [seq_length $movieB] # Untouched parts of first and second movie set begin [seq_crop $movieA 0.0 [expr $lengthA-$duration]] set end [seq_crop $movieB $duration $lengthB] # Apply timed effect to end of first movie; overlay with # beginning of second movie set mid1 [seq_crop $movieA [expr $lengthA-$duration] $lengthA] set mid2 [seq_crop $movieB 0.0 $duration] set middle [seq_overlay [seq_map $mid1 $transition] $mid2] seq_concat $begin $middle $end }</PRE><B><BR>Figure 3:</B> Procedure to connect two sequences with an arbitrary transition<p><HR>The Rivl language extension thus provides a powerful notation for programming with video. Rivl's high level semantic description of video operations also allows the interpreter to optimize the execution of Rivl programs. The next section describes these optimizations.<p><H5><!WA32><!WA32><!WA32><!WA32><!WA32><!WA32><!WA32><!WA32><!WA32><!WA32><!WA32><!WA32><!WA32><!WA32><!WA32><!WA32><A HREF="#HDR3"><-- The Rivl Language</A></H5><H5><!WA33><!WA33><!WA33><!WA33><!WA33><!WA33><!WA33><!WA33><!WA33><!WA33><!WA33><!WA33><!WA33><!WA33><!WA33><!WA33><A HREF="#toc"><-- Table of Contents</A></H5><H2><A NAME="HDR6">3. The Rivl Interpreter</A></H2>This section discusses the implementation of the Rivl interpreter. In the first two subsections we discuss the efficient implementation of image and sequence operations. In the third subsection we discuss memory allocation issues for video computing and describe Rivl's custom memory management system. <p><H3><A NAME="HDR7">3. 1 Implementation of Image Computing</A></H3>There are two ways to optimize still image computing. First, we must make sure that individual image operations, such as scales, rotations, etc., are efficient. These issues have been addressed at length in the graphics literature, and good algorithms are readily available[<!WA34><!WA34><!WA34><!WA34><!WA34><!WA34><!WA34><!WA34><!WA34><!WA34><!WA34><!WA34><!WA34><!WA34><!WA34><!WA34><A HREF="http://www.cs.cornell.edu/Info/Projects/zeno/rivl/mm-95.html#REF25762">3</A>]. Second, we must be intelligent about which operations we call, in what order, to achieve our final result.<p>A feature of Rivl that allows us to exploit the second type of optimization is lazy evaluation, also known as demand-driven execution[<!WA35><!WA35><!WA35><!WA35><!WA35><!WA35><!WA35><!WA35><!WA35><!WA35><!WA35><!WA35><!WA35><!WA35><!WA35><!WA35><A HREF="http://www.cs.cornell.edu/Info/Projects/zeno/rivl/mm-95.html#REF67492">10</A>]. Rivl only computes video data when it is needed for output or display. The result is that at computation time, Rivl can plan a more intelligent computing strategy than if each command were executed immediately and independently. <p>The Rivl interpreter alternates between two modes of operation: graph-construction mode and graph-evaluation mode. In graph-construction mode, the interpreter evaluates Rivl programs, recording and storing operations in a directed acyclic graph (DAG) whose edges correspond to images and whose nodes correspond to primitive operations (e.g. scale or overlay). This process is typically very fast, since image operations are recorded but not executed. In effect, the DAG represents a dynamic instruction trace of the Rivl program's execution.<p>Consider the following program, which overlays a scaled and rotated version of the image tiger.jpg onto the image flowers.jpg:<p><PRE> set tiger [im_read tiger.jpg] im_scaleC! tiger 0.8 im_rotateC! tiger 288.0
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?