Computing Raster Images from Grid Picture ... - Semantic Scholar

2 downloads 0 Views 304KB Size Report
Information and Control, 54:155{185, 1982. PJS92] Heinz-Otto Peitgen, Hartmut J urgens, and Dietmar Saupe. Chaos and Fractals. New. Frontiers of Science.
Computing Raster Images from Grid Picture Grammars Frank Drewes? , Sigrid Ewert?? , Renate Klempien-Hinrichs?, Hans-Jorg Kreowski? University of Bremen, Department of Computer Science P.O. Box 33 04 40, D-28334 Bremen, Germany fdrewes,sewert,rena,[email protected]

Abstract. While a 2-dimensional grid picture grammar may generate pictures (de ned as subsets of the unit square) with arbitrarily small details, only a nite number of them can be made visible as raster images for any given raster. We present an algorithm based on bottom-up tree automata which computes the set of all raster images of the pictures generated by a given grid picture grammar.

1 Introduction Picture-generating devices, such as iterated function systems, chain-code picture grammars, turtle geometry picture grammars, cellular automata, random context picture grammars and collage grammars, specify in general in nite picture sequences or languages. See, for example, [PJS92,CD93,MRW82,PL90,EvdW99, DK99]. Although they are intended and used for modelling visible phenomena of various kinds, due to their in nity additional prerequisites are required to make the generated pictures visible. Depending on the resolution of the chosen output medium, be it a display or a printer, the generated pictures must be transformed into raster images before we can have a look at them. In other words, a picture-generating system or grammar of the above kind speci es two languages. The rst language contains the intended pictures, which are usually described as geometric objects consisting of points, lines, squares, or other such parts in the Euclidean space of dimension 2, 3, or higher. The second language consists of the corresponding raster images for a given raster. The question arises how the picture language and the raster image language are related to each other. Clearly, one may transform each generated picture into its raster image using standard techniques. With such a transformation, the raster image language| which is always nite|can be computed from a nite number of appropriately chosen pictures of the original language. However, which choice is appropriate? Or vice versa, given a raster image and a picture-generating device, is the image associated with any of the generated pictures? ? Partially supported by the EC TMR Network GETGRATS (General Theory of Graph Trans-

formation Systems), the ESPRIT Basic Research Working Group APPLIGRAPH (Applications of Graph Transformation), and the Deutsche Forschungsgesellschaft (DFG) under grant no. Kr-964/6-1 ?? Postdoctoral fellow with a scholarship from the National Research Foundation, South Africa.

1

In this paper, we study the relation between picture languages and raster image languages for the class of grid picture grammars, which are a normal form of grid collage grammars [Dre96] and which coincide with random context picture grammars [EvdW99] if one ignores the context conditions and xes a uniform grid size for all productions. Moreover, iterated function systems where the functions are similarities mapping the unit square onto some cell of the kk-grid, for some k  2, can be seen as a deterministic variant of grid picture grammars. For k = 2, this yields the `relatives of the Sierpinski gasket' discussed in [PJS92, page 244]. Mutually recursive function systems have been studied under the grid restriction in [BNA89,BM89]. Moreover, weighted nite automata, which were introduced in [CK93] as an image compression device, work on a similar grid in order to produce grey-tone images. As the main result of this paper, we show that the raster image language for each rr-raster of the unit square can be constructed from the given grid picture grammar. The construction is based on bottom-up tree automata which get derivation trees as input and compute the required raster information. The paper is organised in the following way. In Section 2, 2-dimensional grid picture grammars and their generated picture languages, called galleries, are de ned. The raster images of these pictures are de ned in Section 3, which also provides our main results. In the conclusion, we discuss various generalisations of our considerations.

2 Two-dimensional grid picture grammars Let the unit square be divided by an evenly spaced grid into k2 squares, for some k  2. A production of a (two-dimensional) grid picture grammar consists of a nonterminal symbol on the left-hand side and the square grid on the righthand side, each of the k2 small squares in the grid being either black or white or labelled with a nonterminal. X ::= p1

X

Y

X

Y

X ::= p2

Y ::= p3

X

X

Y ::= p4

Fig. 1. Four productions of a 22-grid picture grammar A derivation starts with the initial nonterminal placed in the unit square. Then productions are applied repeatedly until there is no nonterminal left, nally yielding a generated picture. A production is applied by choosing a square containing a nonterminal A and a production with left-hand side A. The nonterminal is then removed from the square and the square is subdivided into smaller black, white, and labelled squares according to the right-hand side of the cho2

X

?! 

X

Y

?! p1

XY Y XY

 ?!

Fig. 2. A derivation using the productions of Figure 1 sen production. The set of all pictures generated in this manner constitutes the generated gallery . Example 1. Let k = 2, and consider the four productions of Figure 1. With X chosen as the initial nonterminal, Figure 2 shows a derivation of a picture where these productions are used. The arrow ?!p1 denotes a direct derivation using p1 , whereas ?! denotes a derivation of arbitrary length. We note that, since the application of a production to a nonterminal square does not a ect the remaining squares, productions can also be applied to distinct squares in parallel. This yields the same result as the corresponding sequential derivation. (The context-freeness lemma for collage grammars expresses this fact formally, see e.g. [DK99, Lemma 11.4.1].) A picture generated by a grid picture grammar can be written as an expression in a convenient manner: Let the unit black square be represented by the symbol B and the corresponding white one by W. By de nition, each of the remaining pictures in the generated language consists of k2 subpictures 1;1 ; : : : ; 1;k ; : : : ; k;1; : : : ; k;k , each scaled by the factor 1=k, as illustrated in Figure 3. If ti;j is the expression representing i;j (for i; j 2 [k], where [k] denotes the set f1; : : : ; kg), then [t1;1 ; : : : ; t1;k ; : : : ; tk;1 ; : : : ; tk;k ] represents the picture itself (for k = 2 this is simply a quadtree).

.. .

.. .

...

k;1 k;2    k;k .. .

2;1 2;2    2;k 1;1 1;2    1;k

Fig. 3. Division of a square into k2 subpictures Formally speaking, any expression that represents a picture is a term (or tree ) over a certain signature. In general, a signature is a nite set  of symbols, each symbol f 2  being assigned a unique rank rank (f ) 2 N . The set T of terms over  is the smallest set such that for n 2 N , f (t1 ; : : : ; tn ) 2 T for all f 2  with rank (f ) = n and all t1 ; : : : ; tn 2 T . For n = 0, we may omit the parentheses in f (), writing just f instead. 3

t = [ [ [B; W; B; W]; [B; B; W; W]; [B; W; B; W]; [B; B; W; W] ]; W; [ [B; W; B; W]; [B; B; W; W]; [B; W; B; W]; [B; B; W; W] ]; [ [B; W; B; W]; [B; W; B; W]; W; W] ]

Fig. 4. A term t 2 T2 and its value val(t) Thus the terms that represent pictures in the kk-grid are the terms in Tk , where k = f[?] ; B; Wg, with rankk ([?]) = k2 and rankk (B) = rankk (W) = 0. As a notational convention, [?] (t1;1 ; : : : ; tk;k ) is written as [t1;1 ; : : : ; tk;k ]. It is now possible to de ne pictures and the relationship between pictures and terms in Tk formally. A picture  is simply a subset of the Euclidean plane, i.e.,   R2 ; intuitively,  is the set of black points. Each picture generated by a grid picture grammar is a subset of the unit square, i.e.,   SQ =  (x; y) 2 R2 j 0  x; y  1 . The value val(t ) of a term t 2 Tk is the picture de ned inductively as follows: { val(B) = SQ, { val(W) = ;, and { if val(ti;j ) = i;j for i; j 2 [k], then val([t1;1; : : : ; tk;k ]) is de ned as [ 1;1 ; : : : ; k;k ] = n

[

i;j 2[k]

transformki;j (i;j );



o

x i?1+y j (x; y) 2  for every picture  . where transformki;j ( ) = j ?1+ k ; k Hence, val([t1;1 ; : : : ; tk;k ]) is obtained by scaling and translating each picture i;j = val(ti;j ) so that it ts into the (i; j )-th square of the kk-grid. Example 2. The term in T2 shown on the left of Figure 4 represents the picture on the right. For instance, the upper right quarter of the picture is described by the last line of the term. Since there is a unique correspondence between terms and pictures, all we need in order to de ne grid picture grammars formally is an appropriate grammatical device for generating terms. Such a device is the regular tree grammar. De nition 3. A regular tree grammar is a tuple G = (N; ; P; S ) consisting of { a nite set N of nonterminals, which are considered to be symbols of rank 0, { a signature  disjoint with N , { a nite set P  N  T[N of productions, and { an initial nonterminal S 2 N . A term t 2 T [N directly derives a term t0 2 T [N , denoted by t ?!P t0 , if there is a production A ::= s in P such that t0 is obtained from t by replacing an occurrence of A in t with s. The language generated by G is L(G) = ft 2 T j S ?!P tg, where ?!P denotes the re exive and transitive closure of ?!P ; such a language is called a regular tree language.

4

De nition 4. A grid picture grammar is a regular tree grammar of the form

G = (N; k ; P; S ), for some k  2. The gallery generated by G is ? (G) = fval(t) j t 2 L(G)g. Example 5. For k = 2, the regular tree grammar G with nonterminals X; Y , productions X ::=p1 [X; Y; X; Y ], X ::=p2 B, Y ::=p3 [X; X; W; W], Y ::=p4 W, and initial nonterminal X formalises Example 1. C1 C2 C3 S ::= B1 B2 B3 A1 A2 A3 C1 ::=

B1 ::=

A1 ::=

Vr Vr

Hb C2 ::=

Vr Vr Vr Vr Vr

Hb Hb Hb X 2 Ht Ht X 1 Hb B2 ::=

C3 ::= Vl

X 2 Ht

Vl

B3 ::=

X 1 Hb Hb Ht

A2 ::=

A3 ::= Vl

Ht Ht Ht

Ht Ht Ht Hb ::=

Vr ::=

Ht ::=

Hb Hb Hb Vr Vr Vr

Vl Vl ::= Vl Vl

Vl X1 ::= Vl X1 Hb Hb

X2 Ht Ht X2 ::= Vl Vl

Fig. 5. Productions to generate E's 5

Example 6. A slightly more complex grid picture grammar is the following one. Our aim is to generate a gallery of pictures which resemble the capital letter `E', but with a rough outline similar to the outline of a printed letter seen under a microscope. For this, we use the 33-grid picture grammar GE = (N; 3 ; P; S ), where N = fS; A1 ; A2 ; A3 ; B1 ; B2 ; B3 ; C1 ; C2 ; C3 ; Ht ; Hb ; Vl ; Vr ; X1 ; X2 g and P is the set of productions given in Figure 5. (As usual, A ::= 1 j 2 abbreviates the two productions A ::= 1 and A ::= 2 .) Since each of the symbols S , Ai , Bi , and Ci (i 2 f1; 2; 3g) occurs exactly once as a left-hand side, the pictures in ? (GE) are those which can be derived from the unique nonterminal picture obtained from S by a parallel derivation of length 2. In fact, we could have used this as a production (see Figure 6) instead of those in the rst four rows of Figure 5. A similar technique will be used to simplify the proof of Theorem 13. The purpose of Ht , Hb , Vl , Vr , X1 , and X2 is to produce the desired rough outline of the letter by applying one of the two productions available for each of them in a nondeterministic manner. Some of the pictures in ? (GE ) are shown in Figure 7.

S ::=

Vr Vr Vr Vr Vr Vr Vr

Hb Hb Hb Hb X 2 Ht Ht X 1 Hb Vl X 2 Ht X 1 Hb Hb Ht Ht Ht Ht

Vl

Vl

Fig. 6. Alternative production whose right-hand side is obtained after two parallel steps using the productions in Figure 5

Fig. 7. Pictures generated by the grammar GE in Example 6 6

Grid picture grammars are a normal form of 2-dimensional grid collage grammars. In a grid collage grammar the nonterminals in the right-hand sides of productions may be rotated and mirrored, but this does not enhance their generative power, as shown in [Dre96, Corollary 4.5]. The only other di erence is that grid collage grammars generate grid collages, which consist of individual squares (i.e., are sets of sets of points), whereas here we are only interested in the resulting pictures (i.e., sets of points), obtained by taking the union of all squares in a given collage. Strictly speaking, the formal de nition of grid picture grammars is more general than the informal one discussed in the beginning, as it allows productions such as A ::= [B; [W; A1 ; A2 ; W]; A3 ; B]. Intuitively, on the right-hand side of this production the lower right subsquare is re ned one level further than the other three. Productions of this kind are, however, not essential, due to the following well-known normal-form result on regular tree grammars (see, e.g., [GS97]).

Fact 7. For every regular tree grammar G one can e ectively construct a regular

tree grammar G0 = (N; ; P; S ) such that { L(G0) = L(G) and { P contains only productions of the form A ::= f (A1; : : : ; An ), where f 2  , rank (f ) = n, and A; A1 ; : : : ; An 2 N .

In the special case of grid picture grammars this means that only productions of the form A ::= B, A ::= W, and A ::= [A1;1 ; : : : ; Ak;k ] are needed, where A and A1;1 ; : : : ; Ak;k are nonterminals. Bottom-up tree automata can be seen as the inverse of regular tree grammars. Instead of generating a tree from the root to the leaves, they `consume' an input tree, starting at the leaves and working upwards.

De nition 8. A bottom-up tree automaton is a tuple ta = (; Q; R; Qf ) consisting of { an input signature  , { a set Q of states which are considered to be symbols of rank 0, { a set R of rules f (q1; : : : ; qn) ! q, where f 2  , rank (f ) = n, and q1 ; : : : ; qn; q 2 Q, and { a subset Qf of Q, the set of nal states. For a term t 2 T [Q, t ?!R t0 if t0 is obtained from t by replacing a subterm of t which is identical to the left-hand side of a rule in R with the right-hand side of that rule. The set Acc(ta ) of accepted terms is given by Acc(ta ) = ft 2 T j t ?!R q for some q 2 Qf g. A nite bottom-up tree automaton is a bottom-up tree automaton with only nitely many states.

Due to the following fact (see, e.g., [GS97]), nite bottom-up tree automata are a useful tool if one aims at computability results concerning sets generated by regular tree grammars. 7

Fact 9. 1. A tree language T is regular if and only if T = Acc(ta ) for some

nite bottom-up tree automaton ta. Moreover, there are e ective constructions which yield for every regular tree grammar G a nite bottom-up tree automaton ta such that Acc(ta ) = L(G), and vice versa. 2. The set of all regular tree languages is e ectively closed under intersection. 3. The question whether L(G) = ; is decidable for any regular tree grammar G.

3 Computing raster images A raster , such as the one provided by the nite resolution of a computer screen, can be seen as an rr0 -grid that is evenly spaced in each direction. In order to simplify the situation, we shall consider in the following the idealised situation where r = r0 (and the area to be displayed is the unit square). Given a picture   SQ, our aim is to determine the raster image that corresponds to  . The latter can be de ned as follows: For a given square in the rr-grid, if any point of  lies properly inside the square, then that square is lled with the colour black, else it is coloured white. The upper raster image rasterur ( ) obtained in this way is the smallest set of raster squares which cover  , and thus the least upper bound on  with respect to theconsidered raster. More formally, let sq be SQ without its boundary, i.e., sq = (x; y) 2 R2 j 0 < x; y < 1 . Then   rasterur ( ) = val( bwu1;1 ; : : : ; bwur;r ), where 

r bwui;j = B if  \ transformi;j (sq) 6= ;

W otherwise : Analogously, one may de ne the lower raster image of  as the largest raster   image covered by  : rasterlr ( ) = val( bwl1;1 ; : : : ; bwlr;r ), where 

r bwli;j = B if transformi;j (sq)  

W otherwise : For a grid picture grammar G, the set of all upper rr-raster images obtained from picturesin ? (G) is denoted by Rur (G) = frasterur ( ) j  2 ? (G)g. Similarly, Rlr (G) = rasterlr ( ) j  2 ? (G) denotes the set of all lower raster images generated by G. Example 10. The picture considered in Example 2 ` ts' exactly into an 88-grid. Figure 8 illustrates how its upper raster image is computed for a 1010-raster: whenever the interior of a raster square is not completely white, it is painted black.

We shall now show that Rur (G) is computable for every grid picture grammar G and every r 2 N + (where both G and r are given in the input). A corresponding result for Rlr (G) will then follow without much ado. For notational simplicity, let us x an arbitrary grid size k  2 to be used throughout the rest of this section. In particular, we denote transformki1 ;i2 by transformi1 ;i2 . 8

Fig. 8. Computing the upper raster image of a picture Intuitively, if we perform a derivation in G, replacing all nonterminals in parallel in each step, the edge length of the remaining nonterminal squares is k?n after n steps. Thus, after nitely many steps all nonterminal squares have become smaller than the raster squares. This means that each of these small nonterminal squares is divided by at most one raster line horizontally, and similarly in the vertical direction. As depicted in Figure 9, this results in a segmentation of the nonterminal square into at most four rectangular subsets. If one of the dividing lines lies outside the square (or on one of its edges), or both of them do, two or even three of the rectangles are empty and are not considered. A

rec d1 ;d2 (0; 1) rec d1 ;d2 (0; 0)

Fig. 9. Segmentation of a non-

terminal square by raster lines

rec d1 ;d2 (1; 1)

d2 d1

rec d1 ;d2 (1; 0)

Fig. 10. Rectangular segments determined by d1 and d2

Suppose that we continue the derivation. Upon termination, some of the four rectangles may contain points of the derived picture, turning the raster squares to which they belong black, while the remaining rectangles do not. Thus, situations such as the one shown in Figure 9 have to be investigated to develop the algorithm we aim at. In order to become independent of the actual size of the square under consideration, we scale it to the size of the unit square SQ. Its segmentation into rectangles is uniquely determined by the positions of the corresponding raster lines, two real coordinates. As described above, each pair (d1 ; d2 ) 2 R2 of such coordinates divides the open square sq into at most four open rectangles. The set of these rectangles (excluding the empty ones) is denoted by DIVd1 ;d2 . More precisely, we can address the segments by the four corners (c1 ; c2 ) 2 f0; 1g2 of SQ by de ning rec d1 ;d2 (c1 ; c2 ) = f(x1 ; x2 ) 2 sq j cl < xl < dl or dl < xl < cl for l 2 f1; 2gg, as illustrated in Figure 10. Using this, we let DIVd1 ;d2 = frec d1 ;d2 (c1 ; c2 ) j c1 ; c2 2 f0; 1gg n f;g: 9

Now, given d1 ; d2 and a picture , we are interested in those rec 2 DIVd1 ;d2 which intersect with . The corresponding subset of DIVd1 ;d2 is denoted by divd1 ;d2 (): divd1 ;d2 () = frec 2 DIVd1 ;d2 j rec \  6= ;g: We now show that divd1 ;d2 () can be determined by a bottom-up tree automaton which processes the term denoting . In a rst step an in nite automaton is de ned; this is afterwards turned into a nite one that can be constructed e ectively.

Lemma 11. Let Q = fD  DIVd1 ;d2 j d1 ; d2 2 Rg. There is a bottom-up tree automaton ta = (k ; Q; R; Q) such that, for all terms t 2 Tk and all D  DIVd1 ;d2 with d1 ; d2 2 R, t ?!R D if and only if D = divd1 ;d2 (val(t)).

Proof. Let R contain the rule W ! ; and, for all d1 ; d2 2 R and D  DIVd1 ;d2 , the rules B ! DIVd1 ;d2 as well as all rules [D1;1 ; : : : ; Dk;k ] ! D such that (1) for i1 ; i2 2 [k], Di1 ;i2  DIVe1 ;e2 where (e1 ; e2 ) = transform?1 i1 ;i2 (d1 ; d2 ) and (2) D is the set of all rec 2 DIVd1 ;d2 for which there are i1 ; i2 2 [k] and rec 0 2 Di1 ;i2 such that transformi1 ;i2 (rec 0 ) \ rec 6= ;. Note that (1) implies that, for all rec 2 DIVd1 ;d2 and rec 0 2 DIVe1 ;e2 , either transformi1 ;i2 (rec 0 )\rec = ; or transformi1 ;i2 (rec 0 )  rec . Therefore, the following is an equivalent formulation of (2): (20 ) D is the set of all rec 2 DIVd1 ;d2 for which there are i1 ; i2 2 [k] and rec 0 2 Di1 ;i2 such that transformi1 ;i2 (rec 0 )  rec . We now prove the equivalence stated in the lemma by structural induction on t. For t = B or t = W the statement obviously holds, because the only derivations for these cases are B ?!R DIVd1 ;d2 and W ?!R ;, respectively. Suppose now that t = [t1;1 ; : : : ; tk;k ], where i1 ;i2 = val(ti1 ;i2 ) for i1 ; i2 2 [k], and assume that the statement holds for t1;1 ; : : : ; tk;k . ( ) The two inclusions D  divd1 ;d2 () and divd1 ;d2 ()  D are proved separately. As for D  divd1 ;d2 (), by (20 ) for every rec 2 D there must be i1 ; i2 2 [k] such that transformi1 ;i2 (rec 0)  rec for some rec 0 2 Di1 ;i2 . By the induction hypothesis, rec 0 \ i1 ;i2 6= ;. Consequently,

)

rec \   transformi1 ;i2 (rec 0 ) \ transformi1 ;i2 (i1 ;i2 ) = transformi1 ;i2 (rec 0 \ i1 ;i2 ) 6= ;

and therefore rec 2 divd1 ;d2 (). For the converse inclusion, consider some rec 2 divd1 ;d2 (). By the choice of e1 and e2 in (1), there must be i1 ; i2 2 [k] and rec 0 2 dive1 ;e2 (i1 ;i2 ) such that transformi1 ;i2 (rec 0 )  rec . Now, the induction hypothesis yields rec 0 2 Di1 ;i2 , which by (20 ) implies rec 2 D. 10

(

( ) By the induction hypothesis, for each pair of indices i1 ; i2 2 [k] and (e1 ; e2 ) = transform?1 i1 ;i2 (d1 ; d2 ), there exists some Di1 ;i2  DIVe1 ;e2 (namely dive1 ;e2 (i1 ;i2 )) such that ti1 ;i2 ?!R Di1 ;i2 . Furthermore, by the de nition of R, [D1;1 ; : : : ; Dk;k ] ?!R D for some D  DIVd1 ;d2 . However, the only-if direction of the lemma states that this implies D = divd1 ;d2 (), which nishes the proof. ut The next lemma shows that the automaton given by Lemma 11 can be turned into an e ectively computable, nite one, if we are interested in a particular pair of dividing lines d1 ; d2 , and these are rational numbers. Lemma 12. Let d1; d2 be rational numbers and D  DIVd1 ;d2 . One can e ectively construct a nite bottom-up tree automaton ta D such that Acc(ta D ) = ft 2 Tk j divd1 ;d2 (val(t)) = Dg: Proof. We de ne ta D = (k ; Q0 ; R0 ; fDg) by removing useless states and rules from the automaton ta de ned in the proof of Lemma 11, thus obtaining nite subsets Q0 and R0 of Q and R, respectively. Let D  DIVd1 ;d2 be the nal state given by the lemma and suppose R contains a rule [D1;1 ; : : : ; Dk;k ] ! D. If we consider any of the states Di1 ;i2 (i1 ; i2 2 [k]), according to the de nition of R we have Di1 ;i2  DIVe1 ;e2 , where (e1 ; e2 ) = transform?1 i1 ;i2 (d1 ; d2 ). Regarding e1 , for example, there are two cases: { If e1  0 or e1  1, then Di1 ;i2  DIV0;e2 , because, as a direct consequence of its de nition, DIVe1 ;e2 = DIV0;e2 . (Intuitively, if the line given by e1 does not intersect sq, then its actual position does not matter.) { Otherwise, by condition (1) in the de nition of R, e1 = k d1 ?(i1 ?1). In other words, if d denotes the representation of d to the base k and d1 = 0:a0 a1 a2    , then e1 = 0:a1 a2    (note that a0 = i1 ? 1). By induction, this means that a state D0 can occur in a derivation t ?!R D for some t 2 T only if D0 2 DIVe1 ;e2 , where e1 = 0 or e1 = 0:am am+1    for some m 2 N . Analogously, e2 = 0 or e2 = 0:bn bn+1    for some n 2 N , if d2 = 0:b0 b1    . Denote by E the set of all pairs (e1 ; e2 ) of this kind and de ne Q0 = fD0  DIVe1 ;e2 j (e1 ; e2 ) 2 E g and R0 = f([D1;1 ; : : : ; Dk;k ] ! D0 ) 2 R j D0; D1;1 ; : : : ; Dk;k 2 Q0 g: This yields the required nite bottom-up tree automaton ta D : Since d1 and d2 are rational numbers, d1 and d2 are eventually periodic, implying that E is nite. Consequently, Q0 is nite, since each DIVe1 ;e2 has at most four elements (which automatically implies that R0 is nite). The automaton ta D de ned in this way can easily be computed. This is because E can be obtained from d1 and d2 , which makes it easy to compute Q0 . Finally, in order to compute R0 we enumerate all rules [D1;1 ; : : : ; Dk;k ] ! D0 such that D0 ; D1;1 ; : : : ; Dk;k 2 Q0 and verify for each of them whether the conditions (1) and (2) in the de nition of R are satis ed. ut 11

Using the previous lemma, we can now prove the main theorem of this paper. Theorem 13. There is an algorithm which takes as input a grid picture grammar G and a number r 2 N + , and yields as output the set Rur (G). Proof. Consider a grid picture grammar G = (N; k ; P; S ) in normal form (see Fact 7). In order to simplify the technical details, we rst show that without loss of generality, k > r can be assumed. Suppose k  r. Then G can be turned into a k2 k2 -grid picture grammar 0 G = (N; k2 ; P 0 ; S ) such that ? (G0 ) = ? (G), as follows. For every production A ::= W or A ::= B in P , P 0 contains that production, too. Furthermore, for all productions A ::= [A1;1 ; : : : ; Ak;k ] and A1;1 ::= t1;1 ; : : : ; Ak;k ::= tk;k in P , P 0 contains the production A ::= [ t1;1 (1; 1); : : : ; t1;1 (1; k); : : : ; t1;k (1; 1); : : : ; t1;k (1; k); .. . t1;1 (k; 1); : : : ; t1;1 (k; k); : : : ; t1;k (k; 1); : : : ; t1;k (k; k); .. .

tk;1 (1; 1); : : : ; tk;1 (1; k); : : : ; tk;k (1; 1); : : : ; tk;k (1; k); .. .

tk;1 (k; 1); : : : ; tk;1 (k; k); : : : ; tk;k (k; 1); : : : ; tk;k (k; k) ]; where

8
r because this process can be repeated as often as necessary. Now, let us consider Rur (G). Since every derivation of a term in L(G) has the form S ?!P B, S ?!P W, or S ?!P [A1;1 ; : : : ; Ak;k ] ?!P [t1;1 ; : : : ; tk;k ], the following raster images (and only those) are contained in Rur (G): { SQ if P contains the production S ::= B, { ; if P contains the production S ::= W, and { all images of the form rasterur (), where  = [ val(t1;1); : : : ; val(tk;k )]] for some production S ::= [A1;1 ; : : : ; Ak;k ] in P and derivations Ai1 ;i2 ?!P ti1 ;i2 (i1 ; i2 2 [k]). 12

The raster images resulting from the rst two items are easy to compute. Thus, it remains to be shown how those resulting from the last item can be obtained algorithmically. Since P contains only nitely many productions of the form S ::= [A1;1 ; : : : ; Ak;k ], it suces to show how one of them can be dealt with. For this, let ?i1 ;i2 = fval(t) j Ai1 ;i2 ?!P t; t 2 Tk g denote the gallery which Ai1 ;i2 derives. We have to show how the set frasterur ([[1;1 ; : : : ; k;k ] ) j i1 ;i2 2 ?i1 ;i2 for i1 ; i2 2 [k]g can be computed. Consider some i1 ; i2 2 [k] and let e1 be the greatest rational number of the form n=r (n 2 N ) which is smaller than i1 . Similarly, let e2 be the greatest rational number n=r smaller than i2 . Thus, e1 and e2 determine the raster lines which cut the square given by i1 ; i2 in the kk-grid (if such lines exist). Now, let (d1 ; d2 ) = transform?1 i1 ;i2 (e1 ; e2 ) and de ne Di1 ;i2 = fdivd1 ;d2 (i1 ;i2 ) j i1 ;i2 2 ?i1 ;i2 g. By Lemma 12, in connection with Fact 9, Di1 ;i2 is computable, since ?i1 ;i2 is generated by the grid picture grammar Gi1 ;i2 = (N; k ; P; Ai1 ;i2 ) and Di1 ;i2 = fD 2 DIVd1 ;d2 j L(Gi1;i2 ) \ Acc(ta D ) 6= ;g, where ta D is as in Lemma 12. By the de nition of divd1 ;d2 and the choice of d1 and d2 , a raster image img has the form rasterur ([[1;1 ; : : : ; k;k ] ) with i1 ;i2 2 ?i1 ;i2 (i1 ; i2 2 [k]) if and only if img = rasterur ([[D1;1 ; : : : ; Dk;k ] ) for some Di1 ;i2 2 Di1 ;i2 (i1 ; i2 2 [k]). Figure 11 is an attempt to illustrate this situation. Since the ( nite!) sets Di1 ;i2 are computable, these raster images are computable as well. ut

scale A2;4

A2;4

choose D2;4 2 D2;4

insert & apply raster

Fig. 11. Using D2;4 to obtain a raster image (raster lines are dashed) 13

Example 14. In order to illustrate the algorithm in Theorem 13, we use it to compute Ru6 (G), where G is the grid picture grammar introduced in Example 1. To avoid unnecessary technical details, we concentrate on the main ideas rather than follow the construction in the proof to the letter. The rst part of the proof states that we have to consider all (possibly nonterminal) pictures that can be derived from the initial nonterminal X in two parallel steps, because then the side length of any nonterminal square is 1=8, which is less than the common side length of the raster squares. One of the pictures obtained in this way is shown in Figure 12(a). As a slight deviation from the proof, we shall not apply Lemma 7 in order to normalise the grammar. Thus, the aim is to compute all raster images of pictures which can be derived from the one in Figure 12(a). Adding the raster as shown in Figure 12(b) reveals that we

X

Y

X

Y

6=6

0 6

5=6

4=6

3=6

1 6

2 6

X

Y

X

Y

3 6

4 6

5 6

6 6

2=6

X

1=6

X

X

0=6

(a)

X

(b)

Fig. 12. A picture (a) derived in two parallel steps and (b) divided by the 66-raster have to investigate the ve situations depicted in Figure 13, which are obtained by scaling the nonterminal squares in Figure 12(b) so that each occupies an area equal to SQ. Note that, as pointed out in the proof of Lemma 12, the base-2 2 3

2 3

1=3

2=3

X

2=3

X

X

1 3

1 3

1=3

1 3

2=3

Y

Y

Fig. 13. Scaled nonterminal squares of Figure 12(b) 14

representations of 1=3 and 2=3 are 0:0101 : : : and 0:1010 : : : , respectively. Hence, only raster lines represented by these numbers (and the line represented by 0) will be considered in the following. Let us denote the ve situations in Figure 13 by (X; ), (X; ), (X; ), (Y; ), and (Y; ) (and similarly for the other segmentations which are used below). We have to determine the ve sets DX ( ) = fdiv2=3;1=3 () j  is derivable from X g; : : : ; DY ( ) = fdiv1=3;2=3 () j  is derivable from Y g. If implemented, the algorithm of Theorem 13 would do this iteratively (as this is how the algorithm in Fact 9 decides whether a regular tree language is empty), computing in parallel all DX (s) and DY (s) whose segmentation s is given by elements of the set f0; 1=3; 2=3g. Since our example is rather small, this can be done by hand, taking only those pairs DX (s) and DY (s) into consideration which contribute to the result. The iterative procedure to be applied is a greedy algorithm which starts by setting DX (s) = DY (s) = ; for all s. Thereafter, it uses the productions of G as patterns for combining already established elements of these sets to new ones. Intuitively, this means that raster patterns obtained through longer and longer derivations are computed. This is illustrated in Figure 14. Initially, since (X; ) (X; ) (X; ) (X; ) (X; ) (X; ) (X; ) (Y; ) (Y; ) (Y; ) (Y; ) (Y; ) 1 2 3 4

Fig. 14. Patterns in DX (s) and DY (s)

DX (s) = DY (s) = ; for all s, only the terminating productions can yield new

elements. In the present example, X ::= B and Y ::= W are the only terminating productions. This yields DIVe1 ;e2 2 DX (s) and ; 2 DY (s) for all s, where e1 and e2 correspond to the raster lines in s; see the topmost row in Figure 14. For the second row, let us consider, for instance, (Y; ). As is illustrated in Figure 15, if we apply the non-terminating production for Y while keeping the raster lines, this reveals that all patterns which we obtain by replacing the two nonterminals with elements of DX ( ) and DX ( ), respectively, and then applying the raster have to be added to DY ( ). Since DX ( ) and DX ( ) are still singletons at this stage, we add only one new element to DY ( ), namely the one shown in the second row of Figure 14. In the third row, the new elements resulting from the third iteration are shown. The fth iteration does not yield any new element. 15

X

X

scale nonterminal squares

X

X

choose

insert & apply raster

Fig. 15. Computing a new element of DY ( ) This means that now all elements of the sets DX (s) and DY (s) (for those s which we have considered) are known; the loop stops. Now, in order to determine which raster images correspond to the pictures derivable from the picture in Figure 12(a), we have to consider all possible instantiations of Figure 12(b) with the patterns in Figure 14, and apply the raster. The resulting set of raster images is depicted in Figure 16. The complete set Ru6 (G) is obtained by repeating this process for all nonterminal pictures derivable in two parallel steps. Theorem 13 is easily seen to carry over to the lower raster images of the pictures in a gallery. Theorem 15. There is an algorithm which takes as input a grid picture grammar G and a number r 2 N + , and yields as output the set Rlr (G). Proof. The picture  = val(t) represented by a term t 2 Tk can easily be inverted by turning all white squares into black ones and vice versa. Formally, inv() = val(t), where W = B, B = W, and [t1;1 ; : : : ; tk;k ] = [t1;1 ; : : : ; tk;k ] (see also [Dre96, Corollary 5.8]). Note that this de nition is sound, i.e., inv() does not depend on the choice of t. In order to compute Rlr (G) with the help of Theorem 13, let us construct a new grid picture grammar G0 = (N; k ; P 0 ; S ) from the given grammar G = (N; k ; P; S ) by exchanging the symbols B and W in the right-hand side of each production. Then ? (G0 ) = finv() j  2 ? (G)g. Furthermore, rasterlr () is equal to inv(rasterur (inv())) for every picture  2 ? (G), which means that Rlr (G) can be determined by computing Rur (G0 ) and subsequently inverting the resulting raster images. ut As an immediate consequence, the uniform membership problem is solvable for both Rur (G) and Rlr (G). Moreover, it is decidable, for given grid picture 16

Fig. 16. The set of all raster images obtained from the nonterminal picture in Figure 12(a)

17

grammars G and G0 , whether Rur (G) = Rur (G0 ) (or whether Rlr (G) = Rlr (G0 ), or Rur (G) = Rlr (G0)).

Corollary 16. The following problems are decidable.

1. Given as input a grid picture grammar G, a number r 2 N + , and an rrraster image img, is img 2 Rur (G)? 2. Given as input two grid picture grammars G and G0 (possibly based on different grids) and a number r 2 N + , is Rur (G) = Rur (G0 )? The analogous statements for Rlr instead of Rur hold as well.

4 Conclusion In this paper, we have presented an algorithm that computes the set of rr-raster images of the pictures generated by a 2-dimensional grid picture grammar. It is easily seen that some restrictions are imposed for technical reasons only and can be relaxed without problems. Since our reasoning works for the two axes of the plane independently and is closed under ane transformation, the underlying unit square may be replaced by a rectangle, or even a parallelogram, and the kk-grid underlying the grid picture grammar by any kk0 -grid, for k; k0  2. Similarly, the rr-raster may be generalised to an rr0-raster, for r; r0  1. In fact, as far as the raster is concerned, it may be worthwhile to note that only three of its properties are used in the proofs, namely that the raster lines be parallel with the axes, be determined by rational numbers, and be nite in number. Thus, one could use a non-uniform raster provided it does not violate any of these requirements. Clearly, our considerations remain also true if we deal with grids in the Euclidean space of dimension d with d  3, or if we deal with grammars where distinct productions need not use the same grid. In contrast to that, it seems much more dicult to get similar results for other types of picture generating devices, such as random context picture grammars, collage grammars, or iterated function systems, and for other modes of rewriting such as table-driven parallel or context-sensitive rewriting. Last but not least, one could investigate more complex rasterisation functions than rasteru and rasterl . An interesting candidate is the one which blackens a raster square whenever the corresponding picture occupies at least half the area of the square. To study questions like these remains a matter of future work.

References [BM89]

Jean Berstel and Michelle Morcrette. Compact representations of patterns by nite automata. Report 89-66, L.I.T.P., Universite Paris VI, 1989. [BNA89] Jean Berstel and A. Nait Abdallah. Tetarbres engendres par des automates nis. In Proc. AFCET-GROPLAN Languages et algorithmes du graphique, number 61-62 in Bigre+Globule, pages 167{175, 1989. Also as Report 89-7, L.I.T.P., Universite Paris VI.

18

[CD93]

Karel Culik II and Simant Dube. Ane automata and related techniques for generation of complex images. Theoretical Computer Science, 116:373{398, 1993. [CK93] Karel Culik II and Jarrko Kari. Image compression using weighted nite automata. Computer and Graphics, 17:305{313, 1993. [DK99] Frank Drewes and Hans-Jorg Kreowski. Picture generation by collage grammars. In Hartmut Ehrig, Gregor Engels, Hans-Jorg Kreowski, and Grzegorz Rozenberg, editors, Handbook of Graph Grammars and Computing by Graph Transformation, volume 2, pages 397{457. World Scienti c, Singapore, 1999. [Dre96] Frank Drewes. Language theoretic and algorithmic properties of d-dimensional collages and patterns in a grid. Journal of Computer and System Sciences, 53:33{60, 1996. [EvdW99] Sigrid Ewert and Andries van der Walt. Random context picture grammars. Publicationes Mathematicae (Debrecen), 54 (Supp):763{786, 1999. [GS97] Ferenc Gecseg and Magnus Steinby. Tree languages. In Grzegorz Rozenberg and Arto Salomaa, editors, Handbook of Formal Languages, volume 3, pages 1{68. Springer, Berlin, 1997. [MRW82] Hermann A. Maurer, Grzegorz Rozenberg, and Emo Welzl. Using string languages to describe picture languages. Information and Control, 54:155{185, 1982. [PJS92] Heinz-Otto Peitgen, Hartmut Jurgens, and Dietmar Saupe. Chaos and Fractals. New Frontiers of Science. Springer, New York, 1992. [PL90] Przemyslaw Prusinkiewicz and Aristid Lindenmayer. The Algorithmic Beauty of Plants. Springer, 1990.

19

Suggest Documents