510.84 IL6r no. 1139-11/15 1983-84 INC. cop. 3 Qof>. J Report No. UIUCDCS-R-84-1143 UILU-ENG 84 1703 A Prototype Binary Image Scaling Facility by Jeffrey Ely and Jane W. S. Liu January 15, 1984 m DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF ILLINOIS AT URBANA-CHAMPAIGN URBANA, ILLINOIS Report No. UIUCDCS-R-84-1143 A Prototype Binary Image Scaling Facilityf by Jeffrey Ely and Jane W. S. Liu Department of Computer Science University of Illinois 1304 W. Springfield Avenue Urbana, Illinois 61801 January 15, 1984 t This work was partially supported by the R. R. Donnelley Contract No. A-1378. ABSTRACT TABLE OF CONTENTS CHAPTER 1. CHAPTER 2. CHAPTER 3. CHAPTER 4. Introduction Boundary Finding Algorithm Approximate Boundary Summary 1 3 9 16 REFERENCES 32 APPENDIX A. Operations of the ASF APPENDIX B. Programs listings 33 35 Digitized by the Internet Archive in 2013 http://archive.org/details/prototypebinaryi1143elyj ABSTRACT This report describes some of the algorithms used in a prototype automatic binary image scaling facility. This facility was designed and implemented to encode scanned, digitized, binary images and to generate faithful reproductions of the images in different sizes and at different resolutions. CHAPTER 1. INTRODUCTION This report describes some of the basic algorithms for automatic scaling of scanned binary images. Typically, a binary image may represent a digitized font or logo. It is scanned into a text formatting or typesetting system and is later displayed or printed, frequently in different point sizes and on devices having different resolutions. The algorithms described here are used in a prototype automatic scaling facility (ASF) designed and implemented to carry out the following tasks: (1) Given the bit-map representation of a binary image, detects its boundary and generates an efficient encoding of the boundary. (2) Finds a set of piecewise polynomials which approximates the boundary with specified error tolerance. (3) Scales the approximate boundary to a reduced size. (4) Generates a bit-map representation of the image at the desired resolution by inking the interior of the boundary produced in the step above. This transformed bit-map representation may be used as input to a printer or display. The prototype ASF was designed to be used with a limited amount of user intervention. Specifically, the tasks of choosing the first point on the image boundary, marking up unconnected portions of the same image, and judging the visual quality of an approximate boundary are carried out by the user. Appendix A describes an example illustrating a way in which this facility may be used. Usually, fewer bits are required to encode and store a binary image when it is specified by its boundary points or by piecewise polynomials approximating the boundary. Hence, the technique described here can also be used to achieve data compression in representations of binary images. However, our primary objective is to generate faithful reproductions of the binary images in different sizes and at different resolutions. Minimization of the storage requirement is not an important consideration here. The problem of scaling binary images to different sizes or translating them to different resolutions has been studied using various techniques in digital filtering and in contour smoothing and adjustment [1, 2]. In these studies, image resolution is translated by either insertion or deletion of pixels and by smoothing the contours of the resultant image. The algorithms described in this report were designed to achieve the same objectives as in these two studies. The approach taken here is to first find the boundary of the given scanned image, represent the boundary by piecewise polynomials, reduce the boundary by scaling the polynomials, and then ink the interior of the boundary at the desired resolution. The use of piecewise polynomials to represent the boundary of a binary image was suggested in TEX [3]. In the case of TEX, mathematical representation of font boundaries provides a font designer the needed tool for shaping and adjusting the form of the character until a desirable form is found. In our case, the piecewise polynomials are used to approximate given boundaries. Because of this difference in our objectives, different polynomials were found to be more suitable for boundary representation. The relative merits of using different piecewise polynomials to approximate a curved boundary have been evaluated extensively. References [4 - 7] provide the bases for our choices of polynomials. In Chapter 2, the algorithm for finding the boundary of a binary image is described. The types of polynomials used to approximate image boundaries are described in Chapter 3 together with the justifications for choosing them. The error measure used to rank the merits of approximate boundaries and the equations relating the parameters of the polynomials to coordinates of boundary points are also described in this chapter. The descriptions of the equipment on which the prototype ASF was implemented and the programs used in this facility can be found in Appendices A and B. Chapter 4 contains a summary of the work described in this report. Several illustrative examples are given in this chapter. 3 CHAPTER 2. BOUNDARY DEFINITION This chapter describes the algorithm used to find the boundary of a binary image from the bit-map representation of the image. In particular, the algorithm is applied to each separate component of the binary image. When the given binary image has more than one component, (e.g., the letter "•" "), the boundary of each component is found independently. Similarly, in the case where the white region is not connected, (e.g, the letter "O"), the two disjoint boundaries are found separately. The relative positions of the disjoint boundaries and individual components are specified by the coordinates of one point on each of the boundaries. In this chapter, our attention is confined to the process of finding one boundary when a point on the boundary is given. We view each pixel as a small square. The coordinates of the pixel are the coordinates of the center of the square. For a given bit-map representation of a binary image, the value of a square is 1 if it is part of the binary image. The value of a square within the white space around the image is 0. Let #,• be a square whose value is equal to 1 and which shares at least one side with another square whose value is equal to 0. An arrow drawn along this common side is called a boundary vector associated with the 5,. (For the sake of concreteness, the direction of the boundary vector is always chosen so that as one transverses along and in the direction of the boundary vector, the square with value 1 is on the left of the path.) In the example shown in Figure 1, each of the squares B lt B 2 , and Z? s shares at least one side with a square whose value is 0. The boundary vectors associated with these squares are as shown. Two squares are said to be adjacent to one another when they shares one side or a corner. Let B it for t = 1, 2, , N, be N squares each of which shares one side with a square whose value is 0. Moreover, these N squares are adjacent to each other. We call these squares the boundary points of the binary image if, as one transverses along a path formed by the boundary vectors associated with the squares B x , B 2 , , and B N , the squares on the left of the path have value 1 and the squares on the right of the path have value 0. For the images shown in Figure 1, squares with value 1 are shaded. Boundary points are darker shaded squares. The closed path formed by the connecting the centers of the boundary points is called the boundary of the binary image. Given a binary image, our problem is to find its boundary. The boundary finding algorithm used in the prototype ASF, referred to as Algorithm BF, works in the • •** • • • :v.r:«. "'■j.'.-'l'- ••• • •?••< ■*-*■• !■• * - * * && ••:•*»: :?••»» C9 - ,ii-»' x -.» ^ 5, f£±§£ S, «£r?» s« i<\ i v. »".'m B, :•;:«*} ■.*•*:■ fc££& Figure 1. Examples of Boundary Points and Boundary Vectors following manner: Algorithm BF. The boundary points found by the algorithm are kept in the boundary stack. The algorithm works as follows: • The algorithm begins with a square that is known to be a boundary point. Also given is a boundary vector associated with the boundary point. They are referred to as the current boundary point and current boundary vector, respectively. • In order to find the next boundary point, four situations shown in Figure 2 are considered, (a). In Case a, the three squares adjacent to the current boundary point have the value and the current boundary vector is as shown on the left. The next step is to change the current boundary vector to be the one shown on the right. No new point is added to the boundary point stack, (b). In Case b, the current boundary vector is changed as shown. Square No. 1 is added to the boundary point stack, (c) and (d). In the Cases of c and d, the current boundary vector is changed as shown. Square No. 2 is added to the boundary point stack. • The algorithm terminates when the starting boundary vector becomes the current boundary vector again. Algorithm BF is conceptually simple. It is implemented by the subroutine called the Boundary Eater listed in Appendix B. This program is complex (see lines 10000 through 10700) due to the fact that all situations symmetrical to the four cases shown in Figure 2 must be dealt with. For example: the situation shown in Figure 3 is symmetric to Case d illustrated in Figure 2. To deal with all of the cases, a concept of a greater or a smaller relationship between a boundary point and its associated boundary vector is introduced. When the boundary point is below or is to the right of the current boundary vector, the point is said to be greater than the boundary vector. When the boundary point is above or is to the left of the boundary vector, the point is said to be smaller than the vector. Furthermore, with the current boundary point being square in Figure 2, square 2 is referred to as the diagonally opposite point. Square 1 is referred to as the other point of interest. Thus, the exact action taken by Boundary Eater depends on: Situation Next Step a 3 • '.'.'l :'■'■• :'•:'•', .':"«:5-?; '•'•'•'• 3^P '.•"••''■.' ..,;•; '.} ';;;". 3 .*••",. ijiji ■», i ( , ,,i,pi "".'•• •••'•'•'.'• : >::H' :;::'•.• •.•';/':''':•*" • ' .' < i ; > 1 »• •* 3 ■^v -*•• |S;|: "•"•" S3 * «.*.*.*. 3 : ; : :' :; : : . :;,; t i 3 •i* ••'•••,''•• ■'■'■:•: ■:::■•: :■'««'"':'• •■••"•'.'•''.'» . :,!».■;.•. '. 3 ^•Ki>;:':!:\ • *••'*■ C** "«* 3 1 III (7 Figure 2. Four Situations I -fa— - -a Figure 3. A Case symmetrical to Case d. (1) The direction of the boundary vector (stored in variable DR as U, D, L, or R for up, down, left, or right, respectively,) (2) The value of the diagonally opposite point (stored in variable DO as 1 or 0,) (3) The value of the other point of interest (stored in variable OT as 1 or 0,) (4) The relationship between the current boundary point and the boundary vector (stored in variable RL as either G or S for greater or smaller, respectively.) Observe that the coordinates of the diagonally opposite point and the other point of interest are functions of the coordinates of the current boundary point, the direction DR of the current boundary vector, and the relationship RL . Specifically, the subroutine Boundary Eater requires the following data as inputs: (1) the coordinates of the starting boundary point, (X(0), Y(0)), (2) the direction of the starting boundary vector, U,D ,L, or R , and (3) the relationship between the starting boundary point and boundary vector, G or S. The subroutine returns the coordinates of the boundary points in arrays X and Y from the starting point given by ( X(0), Y(Q) ) to the ending point given by (X(TP), Y(TP)) (which is the same as the starting point.) Whether the boundary defines a clockwise or counter-clockwise contour is reflected by the coordinates of adjacent points, (X(K + 1), Y(K + 1)) and ( X{K), Y(K)). The coordinates of the boundary points in arrays X and Y are subsequently used as inputs to curve fitting algorithms discussed in the next chapter. Since adjacent array elements contain coordinates of adjacent boundary points, it is only necessary to store the full coordinates of the first boundary point. Given the coordinates of a boundary point, which one of the 8 squares adjacent to this point is the next boundary point may be specified using 3 bits. This technique for encoding boundaries of binary images is known as chained link encoding and has been used to achieve data compression. For example, the image in Figure 4 is roughly 130 squares high by 200 squares wide, requiring 26,000 bits if stored as a bit map. However, the boundary consists of only 540 squares. If the boundary is stored using 3 bits/square, only 1,620 bits are required to store this image. Figure 4. An Example CHAPTER 3. ALGORITHMS TO FIND APPROXIMATE BOUNDARY This chapter describes the algorithm used to find an approximate boundary from the given coordinates of boundary points. In particular, the choices of the piecewise polynomials used to specify the approximate boundary and the error measure used to judge the quality of the approximation are justified. The algorithm, referred to as the Boundary Compacter, was designed to be used in an interactive environment. After the boundary of a binary image is found, the user would specify the amount of maximum tolerated error in the approximate boundary and call the Boundary Compacter to find an approximate boundary with error less than the specified maximum tolerated error. After comparing the resultant approximate boundary with the original, he may wish to repeat the approximation process with a smaller maximum tolerated error. Figure 5 illustrates a frequently encountered example of boundary points defining a segment of the image boundary. Note that the boundary points lie on a curve which is not a function of X or of Y . One approach to finding the piecewise polynomial approximation of such a curve is to segment the curve so that some pieces are functions of X and some pieces are functions of Y . However, this approach may force one to choose unnecessarily short segments. Moreover, a great deal of testing is required in order to determine which segments are functions of X and which are functions of Y. The approach taken here is as follows: Since different pieces of polynomials are used to approximate segments of the boundary, the straight line connecting the endpoints of each segment may be used to establish a new X-axis. That segment of the boundary may be approximated by a polynomial of this new variable X. This approach is illustrated in Figure 6. We note that for each pair of endpoints, (X$ Y$) and (Xg Yg), defining a segment of the boundary, there corresponds a coordinate system defined as follows: The new X axis is the line joining the two endpoints and the new point of origin is the point (X s Y s ). The coordinates of each point, (X K Y K ), on the boundary become the coordinates (X B t Y B ). We can now proceed to find the coefficients of the polynomial P(X B ) so that (1). P(0) = and P(X B ) = 0, and (2). Z[P{X B )- Y B ] 2 is minimized. 10 Figure 5. An Example of Boundary Segment (XsY. Figure 6. Definition of the New Coordinate System 11 3-1. Choice of the Polynomial P(X B ) The polynomials chosen to approximate segments of the image boundary are parabolic segments which can be oriented as desired. Such a parabola is given parametrically by the following two equations. X{t) = at{t-1)+ 0t + X s Y(t) = 1 t(t-1)+ 6t+ Y s where /?= Xg -X s and 6= Y E - Y$. The coefficients a and 7 can be determined with a little more work: Let T s =V s p-U s 6 T E = V E 0-U E 6 Dj^V s U E -V E U s Then a = (t/ £ r s + U S T E )/Dj 1 = (V E T S + V S T E )I Dj The last two equations will not yield finite solutions when Dj = which occurs only when V S U E = V E U s . That is, when the tangent lines at the two endpoints of the boundary segment are parallel. Note that the subroutine Quardratic in Appendix E does not deal with this situation. If Dj = , it merely stops. (See line 8080 of the program.) A variety of smooth curves may be created by chaining segments of parabolas together with matching slopes at common endpoints. On the other hand, a sharp corner at some point can be created by joining two parabolas at a common endpoint with different slopes at that point. Indeed, it is more advantageous for us to use parabolas here instead of cubic polynomials of the types suggested in [3 - 6]. Such a cubic polynomial may contain an inflection point which may be difficult to eliminate. It is relatively easy to approximate a segment with an inflection point by using two parabolas as shown in Figure 6. Since minimizing storage is not one of our objectives, the need for one more polynomial in this case is not an objection. 12 Alternatively, we may use cubic polynomials with the general form P(X) = (AX+ B)X(X-B b ) (1) where B b is as defined in Figure 6. For notational simplicity, X is used to mean Xq hereafter unless it is stated otherwise. Similarly, whenever the coordinates X K and Y K are referred to hereafter, we do not mean the original coordinates of the boundary point. Rather, they refer to the coordinates with respect to the new coordinate system defined in Figure 6. (Lines 18050 and 18060 of the program listed in Appendix B show how to compute the new coordinates from the original coordinates.) Note that in the range of (0, B b ), P(X) has no inflection point. Hereafter, we confine our discussions to the cubic polynomials of the form given by Eq.(l) unless stated otherwise. Similar statements and conclusions can be made for the case when the quardratic polynomials are used. 3-2. Determination of the Polynomial Coefficients Given P(0) === and P{B b ) = 0, we find the polynomial of the form given by Eq. (1) which interpolates {X S Y S ) and (X E ,Y E ). Let g(A,B) - UP(X K )- Y k ] 2 = U(AX K + B)X K {X K -B b y Y K ] 2 K K We wish to determine the values of A and B which minimize g(A ,B). Setting the partial derivatives -l 3 -=Y l 2[{AX K + B)X K {X K -B b )-Y K }X K \X K -B b ) dA K J£-=Y t 2\{AX K +B)X K {X K -B b )-Y K \X K {X K -B b ) db K to zero, we obtain A E X K *(X K -B b ) 2 + BY, X K *(X K -B b ) 2 = £ Y K X K \X K -B b ) A EV(4-B») 2 + BY l X K 2 {X K -B b f = £ Y K X K {X K -B b ) Rewriting these two equations using the notation in the subroutine Least Squares Cubic Coeff, we have A S b + BS i = S 2 (2a) 13 A S 4 + B S t = S t (2b) These two equations can easily be solved for A and B. (See lines 18160 - 18180 of the program in Appendix B.) 3-3. Finding A Better Approximate Boundary Once a polynomial segment is found to approximate a boundary segment, it is necessary to determine how good the approximation is. For the sake of tractability, the polynomial is chosen here to minimize the sum of the square errors Yj[^(^k)~ Yk] 2 • However, this error measure is not a good criterion when used to judge the "nearness" of B(X) to the actual boundary. Rather, the maximum absolute error, max \P(X K )- Y K \ should be used. Indeed, the maximum absolute error is the measure used in the subroutine Average Absolute and Maximum Error. The value of the maximum absolute error in the polynomial found to approximate a boundary segment is returned by the subroutine in the variable UR . (This subroutine re-calculates the values of the new coordinates from the original coordinates of every boundary point because the values of the new coordinates were not saved by the Least Squares Cubic Coeff Subroutine see lines 18440 and 18450. The value of P{X K ) is given by YT in the line 18400.) In order to allow for later drawing of the polynomial, the coordinates of the starting point, (X S ,Y S ), the coordinates of the endpoint, (X E , Y E ), and the coefficients A and B are retained. The segment of the polynomial is drawn using the following program segment: B l = X(E)-X{S): B 2 =Y(E)-Y(S) For XT = to B b Step H YT=(A *DT+ B)XT *(XT-B b ) P l = X(S)+ (YT *B 2 + XT *Bi)/B b P 2 =Y{S) + {XT *B 2 - YT *B i )j B b plot '(jyy Next XT The subroutine Better Plotter works in a similar manner. We note that the size of the step H must be determined to give an unbroken plot. To choose a reasonable value of H, we consider the general problem of plotting the point between two points (X l ,Y l ) and (X 2 ,Y 2 ). Roughly, one is inclined to do something 14 such as For T = to 1 Step// PlotX(r), Y{T) Next T The value of H must be selected so that the resulting plot is continuous on an integer grid. If the point (X(T), Y(T}) has already been plotted, then the next point to be plotted will be X(T + //), Y(T + //). To ensure a "continuous" plot on an integer grid, we must have \X(t + H)-X(t)\ < 1 and | Y{t + H)-Y(l)\ < 1 . In other words, if the parabolas of the form defined in Section 3-2 are used, \X{t+H)-X(t)\ = \X*(e)\ \H\ by the mean value theorem, where c E{t,t + H) < (0,1), we have \X(t+ H)-X(t)\ = \X'(e)\ \H\ = \2ae+ (/?- alpha) | |//|. The right hand side is less than or equal to max[|/?-a| \H\,\0+a\ \H\]. for eG (0,1). Similarly, \Y(t+H)-Y(t)\• «2 xxi — ' • 1 " 1 r~- i 1 ■r i -o 1 ■* ij-j ^T -=r u-j LTJ ■r ij-j -. -O c-4 ^"T r--. 'X o-* ^ CO <- 2 w c3 6 e O CO C-| CM ,~, — -■ u-j CO i-, f'J c--i u -j co cl. ce a 0) ch r> CM 0> bO co ,-. ••-•* CO f"^ u-i CM H"> e o a "o Oh O u-a CD "*■ 5t **> 2 •<■ C-4 i"> h"i ■*'" u-j H 22 only the coordinates of the starting point, X(S), Y(S), and the parameters of the polynomial are retained. The approximate boundary reconstructed from the data in Table 2 is shown in Figure 8. This approximate boundary is generated from 9 segments and a maximum tolerated error of 1.3. Figure 9 shows a different approximate boundary with a smaller maximum tolerated error (0.7). The 17 segments of this approximate boundary are listed in Table 3. In this example, both approximate boundaries are visually acceptable. Another example considered was the binary image whose boundary is shown in Figure 10a. This boundary consists of ellipic and circular segments and was generated from the data in line 5 of the program listed in Appendix B. The resultant boundary found by Boundary Eater is shown in Figure 10b. With maximum tolerated error of 0.9, the approximate boundary is given by the data in Figure. 11. In this case, we can see an undesirable result where the last segment wraps around and covers part of the first. The resultant approximate boundary is not satisfactory visually because the symmetry in the original image was not preserved. Figures 12-15 show the approximate boundaries of this image when the maximum tolerated error was 0.5, 0.3, 0.15 and 0.0001, respectively Unfortunately, the quality of the approximate boundary suffers severely when the maximum tolerated error is too small. This may be due to problems in the subroutine Better Plotter which graphed the segments. 4-2. Further Work To scale a binary image, the approximate image boundary found by the Boundary Compactor needs to be reduced to the desired size. The smaller image at the desired resolution may then be obtained by inking the interior of the reduced boundary. The codes required to carry these two steps are not included in this report. Several experiments were carried to determine the visual qualities of reduced images produced in this fashion. When the numbers of pixels in all portions of an image are large, the quality of the reduced image in coarser resolutions is usually good as expected. When some parts of the image contain very few pixels (e. g., around 5), the quality of the resultant image was found poor in some cases. The poor quality is due to "quantization noise" in these cases. In order to assure high visual quality in the final result, supports which allow the user to edit the bit-map representation generated automatically by the scaling facility must be provided. These supports need to be implemented in the future. 23 "V. V" "^-M-.™" X V—-" Figure 8. Approximate Boundary with Maximun Tolerated Error = 1.3. 24 I \ n H f i ■ _■ I ,-' i \ / i i «, f 1 \ / ■ H \. a ii 1 n ■-« u tat ■i ) \ \ u •■Si nan » aa aan I / / i i / Figure 9. Approximate Boundary with Maximum Tolerated Error = 0.7 25 ~~* a- *• » O- -o --* — < ^j- in -O «r cr O CM — "■ — o- r--. "^- O* CO O ci~ h -, J3 ^. c; CM cm -O cm 13-. c-i " cm t--- m f"- CO 'J" 1 CM i-_. «S- (-■-. — ** 1 N »» g -j CO cm t-O i i*-.i .—j — « CM *~* I 1X1 UJ |_U ■JO . , <•'> on rn UXJ ^Tl crj CN CM O- OS L -1 •«- i-"j 't IJ-J -3- CH Y't •^r u-j ""^ ■cr UJ uj C* ■*—• m co o 7 1 i i u 1 t-U 1 1 i u li J r~-. i:m rn 1.1- .n r j ■_'- CM r-- f • CN •w» r-i •XI m t-'j T -CI IT. 1 -1 i.l- .^ O" on IX l— j h'J -o n- CO cm t> n i-- «r -~* 1--4 O o- «3- cm .— • -o r-.. a- _ in H^- ' e T* a 0) «»■ o ,1 O r-i co m ~o ^ •"* « o "• « -; « £M '^ ■-' co '•"j CO —• — • _ CM CM tN C-I c-i _ »-« co .-. co u j ■3- «r 0~ I-. CN i -| u-j 5 C» „ -O I — . o-- «. -O m Ci- CO CI-- o-- ^-! h-:i co **"■• r-. u-j ci m cm cm M UJ CO H u_ ^ i — as: _i a a: * •a: i—i ca > o g i- CC. CC a- 1% UJ UJ UJ U. WZ *^ CO x CO •— • *x: i_u i~ <»i s: CO CO co co co -o in -o f-~ a-- — • r .. — .- . ,_, ~-i „., CM cm tN h- 13- CO |--- 133 h-i -O o a- cm CM — • bO GO CO a CM . '-' CM CM CM CM CO U"» J3 - r-i .— . co CM h -i co ci- co u-j o CL, CO ® 3 20 -« l — ..' ■ 1 1 1 "i / \ \ 1 1 i » [ \ .« \ ■ ■ ■ •«..,« ■ Figure 10a. Actual Boundary of a Symmetrical Image / \ Figure 10b. Boundary of the Image in 10a Found by Boundary Eater 27 * OF POINTS IN FIGURE HI ERROR = .9 SEGMENT INFO: S E = 113 XiS> TIMER VALUE = 21140 SUE) y(E) 27 100 80 119 99 1)1 i. t 39 119 99 116 111 39 70 Hi ill Si 114 70 84 Si 114 SO 100 84 111 SO 100 99 81 111 12 99 81 112 35 -i.i093393iE-04 -.0202965577 3. 17499075E-03 -.0463298339 -3.12933132E-05 -.0298496551 5.53i37077E-05 -.011062779 -4.63658051E-04 -,02422i2i2 2.09200i55E-03 -.04429S0384 •■■^■■i Figure 11. Approximate Boundary with Maximum Tolerated Error = 0.9 28 TIMER VALUE = 13302 * OF POINTS i N FIGURE = 11 7 RAX ERROR = .5 , SEGMENT INFO s E US) Y(S) X(E) y(E> A B 3 100 30 108 83 -.0143353513 .0455495721 3 27 10S 33 119 99 -i.47635913E-04 -.0350511749 97 x i 32 119 99 119 104 .0666666664 -.205128204 ■Ji 46 119 104 110 116 -1.8351422SE-03 -.0143093192 46 55 110 116 101 119 -2.61399818E-03 -.0300369323 cc 3 j 60 101 119 96 119 .0666666664 -.205123204 60 80 96 119 31 104 5.73961749E-04 -.0333432019 30 85 31 104 81 99 -.066666666D .128205123 85 99 81 99 37 85 1.39506771E-03 -.0394263529 99 ■111 37 85 99 31 -2.32948168E-03 -.0106035967 111 3 99 81 103 81 ,138333389 -.477777773 Figure 12. Approximate Boundary with Maximum Tolerated Error = 0.5 20 TIMER VALUE = 37504 1 OF POINTS IN FIGURE = 11 7 i hi ERROR = 7 i SEGMENT INFO: s E JUS) Y(S) X(E) VIE) A B 6 100 30 106 32 -.0463950603 .148295201 6 15 106 82 115 37 1. 7607832 1E-03 -.0245704791 15 19 115 87 117 91 -.104166667 .232923743 i? 22 117 91 119 94 .216666666 -.390601386 LL 28 119 94 120 100 .0258001044 -.0128243104 23 34 120 100 118 106 -.0468950603 .148295201 34 40 118 106 115 112 9. 7677561 7E-04 -.0294034334 40 43 115 112 113 114 -.666666667 .942309042 .4 7 47 113 114 109 117 .0232917236 -.102122003 47 54 109 117 102 119 -.0142736324 .0174700328 54 57 102 119 99 119 -.5 .5 57 63 99 119 93 118 -.0258001044 .0128243104 ; 7 66 93 113 90 117 .238095238 -.376461627 66 70 90 117 86 114 -.0282917236 .102122003 70 74 86 114 84 110 -.104166667 .232923748 74 80 84 110 31 104 -9.76775628E-04 -.0223510732 30 84 81 104 30 100 .0672693342 -6.63219132E-04 34 91 80 100 82 93 -.0319234992 .116203291 91 94 82 93 33 90 .238095238 -.376461627 94 100 83 90 38 85 -.0275986739 .0569116488 100 104 88 85 92 32 .0282917236 -.102122003 104 109 92 82 97 81 -.0209738723 -8.00942196E-04 109 97 31 100 80 .119047619 .0376461633 n V Figure 13. Approximate Boundary with Maximum Tolerated Error = 0.3 30 * OF POINTS IN FIGURE MAX ERROR = .15 SEGMENT INFO : S E 6 6 9 9 12 12 16 16 19 19 22 22 27 -7 30 30 34 34 37 37 40 40 43 43 46 46 49 49 52 52 56 56 / 7 6<> . 7 0-.' 66 66 69 69 t i. 72 75 75 78 78 34 84 91 91 94 94 97 97 100 100 103 103 106 106 111 111 2 = 113 X(S> 100 106 109 112 115 117 119 119 119 118 117 115 113 110 107 104 100 93 90 87 85 83 82 80 82 83 35 88 91 94 99 Y(S) 80 82 83 85 88 91 94 99 102 106 109 112 114 116 118 119 120 118 117 115 112 109 106 100 93 90 87 35 83 81 81 XiE) 106 109 112 115 117 119 119 119 118 117 115 113 110 107 104 100 93 90 37 30 TIMER VALUE = 17256 Y(E) 91 94 99 102 82 -.0463950603 .148295201 83 .238095238 -.376461627 85 -.216666666 .390601386 88 -.136974426 .166125652 91 -.I083rnv, .0600925211 94 .216666666 -.390601386 99 i02 . j -1 106 -.0672693342 6.63219132E-04 109 .238095238 -.376461627 112 -.216666666 .390601386 114 -.666666667 .942309042 li6 { AQTTTT7T .0600925211 118 .216666666 -.390601386 119 -.238095238 .376461627 120 .0672693342 -6.63219132E-04 118 -.0319234992 .116203291 117 .238095238 -.376461627 115 ,108'''''' -.0600925211 112 .216666666 -.390601386 109 ,216666666 -.390601336 106 -.238095238 .376461627 100 .0468950603 -.148295201 93 -.0319234992 .116203291 90 .233095238 -.376461627 87 -.0600925211 85 1 ^0777777 .0600925211 83 .0600925211 81 .216666666 -.390601386 81 81 c .J -1 V Figure 14. Approximate Boundary with Maximum Tolerated Error = 0.15 31 TIMER VALUE = 15341 1 OF POINTS IN FIGURE m ERROR = IE -04 SE6MENT INFO : E E 3 6 6 9 9 12 12 15 15 19 19 22 11 27 27 30 i5v 33 Jv> 36 71 ->0 39 39 42 42 46 46 49 49 52 Ji 55 J J 58 58 62 62 65 65 69 69 72 71 75 78 78 81 81 84 84 87 87 90 90 93 93 97 97 100 100 103 103 106 106 111 111 2 113 XIS) 100 103 106 109 112 115 117 119 119 119 119 117 116 114 110 107 104 101 98 94 91 87 82 81 SO 31 81 33 85 88 91 94 99 Y(S) 80 81 32 33 35 37 91 94 99 102 105 108 ill 114 116 113 119 119 119 119 117 115 112 109 106 103 100 97 94 91 37 85 83 81 31 X(E) 103 106 109 112 115 117 119 119 119 119 117 116 114 110 107 104 101 93 94 91 37 35 83 32 81 30 81 81 33 85 88 91 94 99 102 Y!E> 81 -.119047619 .414107787 82 -.119047619 -.0376461633 S3 .233095238 -.376461627 85 -.216666666 .390601386 87 -.216666666 .390601386 91 -.104166667 .232923743 94 ,216666666 -.390601386 99 102 .5 -1 105 103 -.216666666 .390601336 111 .233095233 -.376461627 114 1 nij?7?T77 -.0600925211 116 -.104166667 .232923743 118 .216666666 -.390601336 119 -.233095238 .376461627 119 119 .5 -1 119 117 -.216666666 .390601336 515 .104166667 -.232923748 112 .216666666 -.390601386 109 .216666666 -.390601336 106 -.238095238 .376461627 103 .119047619 -.414107787 100 .119047619 .0376461633 97 -.119047619 .414107737 94 91 -.216666666 .390601386 87 .104166667 -.232923748 85 1 nQ777777 .0600925211 83 -.108333333 .0600925211 81 .216666666 -.390601386 81 32 j J -1 _mmJnmm Figure 15. Approximate Boundary with Maximum Tolerated Error = O.OOOl M.-' 32 REFERENCES [1] Schafer, R. and L. Rabiner, "A Digital Processing Approach to Interpolation," Proc. IEEE, Vol. 61, No. 6, June 1973. [2] Casey, R. G., T. D. Friedman, and K. Y. Wong, " Use of Pattern Processing Techniques to Scale Print Fonts," Technical Report No. RJ2979, IBM Research Laboratory, San Jose, California, October, 1980. [3] Knuth, D., TEX and Metafont, New Direction in Typesetting, Beford, Ma., American Mathematics Society. [4] Reeves, W. T. and P. Sermer, " Efficient Representation of Curves in Computer Graphics," Technical Report No. 153/81, Department of Computer Science, University of Toronto, Toronto, CANADA, 1981. [5] Ichida, K., K. Takeshi, and Y. Fujiichi, " Curve Fitting by a One Pass Method with a Piecewise Cubic Polynomial," ACM Transactions on Mathematical Software, vol. 3, No. 2, June, 1977. [6] Rice, J. R., " Algorithm 525, ADAPT, Adaptive Smooth Curve Fitting," ACM Transactions on Mathematical Software, Vol. 4, No. 1, 1978. [7] Chung, W. L., " Automatic Curve Fitting Using an Adaptive Local Algorithm," ACM Transactions on Mathematical Software, Vol. 6, No. 1, 1980. 33 APPENDIX A. OPERATIONS OF ASF The programs listed in Appendix B were ran on a TRS-80 Color Computer. An EPSON MX-80 Printer was used to plot figures described in Chapter 4. The operating instructions are listed below. Lines of text in italics indicate commands or responses entered by the user. Similarly, actions taken by the user are shown in italics. Bold face text indicates prompts from the system. The text in Roman indicates comments. (1) CLEAR 100, 32500 This command is entered before loading the program, clearing space for a machine language subroutine — see (7). (2) PMODE 4,1: PCLS 5: RUN This command sets proper graphics mode, clears graphics screen, runs the program. (3) MAGNIFICATION? 1. (4) Circle is drawn, BREAK This action returns the program to user control. (5) PCLS 5: GOSUB 1100 (6) The image shown in Figure 4 *» drawn, BREAK (7) GOSUB 18000 This command loads a machine language routine which assists subroutine 12000 in posting the screen to the printer. (8) GOSUB 12000 This command posts the screen to the printer. (9) GOSUB 10000 This program finds the boundary of the screen image. The user is prompted to enter data needed. The data entered here include the coordinates of the starting point (a point on the boundary), the direction of the associated boundary vector, and the relationship between the boundary point and the boundary vector. START PT? 83,40 83 and 40 are coordinates of boundary point. 34 START VECTOR DIR U, D, L, R, ? R U, D, L, and R means Up, Down, Left, or Right, respectively. START PT-VEC REL G, S? G G and S means Greater or Smaller than the vector, respectively. This subroutine when completed, erases the original image and draws the boundary on the screen. The Coordinates of the boundary points are saved in arrays X and Y, each with TP elements. (10) GOSUB 12000 This command causes the image boundary to be dumped to the printer. (11) GOSUB 21000 This command starts the Boundary compacter to find the approximate boundary. The user is prompted to enter the maximum tolerated error. STARTING PT #? maximum tolerated error? 1.3 A value between .25 and 1.9 seems reasonable. As this program runs, error information on various segments is printed. When this subroutine is completed, the information about the curves which approximate the boundary is erased and the approximate boundary is graphed. (12) GOSUB 12000 This command sends the approximate boundary to the printer. (13) By comparing the output generated in step No. 12, the approximate boundary, to the output generated in step No. 10, the original boundary, the user can decide if he is satisfied visually by the approximation. If he is not satisfied, he may repeat step No. 11 with a smaller tolerated error. 35 APPENDIX B. PROGRAMS USED IN ASF 1 REM COPYRIGHT ©HAY 7,1983 BY JEFFREY S. ELY 2 INPUT"MA6NIFICATI0N H ;MG 5 DATA C, 100, 100,20,. 20 DATA 1,50,20,110,20 22 DATA L, -,-,70,60 24 DATA L,-, -,130,60 26 DATA L,-,-, 170, 20 28 DATA L,-,-, 230, 20 30 DATA L,-,-, 130,70 32 DATA L, -,-,20,70 34 DATA L,-,-,20,50 36 DATA L,-, -,50,20 33 DATA F, 60,40,. 50 DATA P,0,0,P,20,0,P,40,0,P,60,0,P,80,0,P,100,0,P,120,0,P,140,0,P,160,0,P,180,0,P,200,0,P,220,0,P,240,0 60 DATA P,0,20,P,0,40,P,0,60,P,0,80,P,0,100,P,0,120,P,0,140,P,0,160,P,0,180 100 DATA 0,83,40,-1,0,27,95,0,1 105 DATA Q, -,-,-,-,117, 137, 9, -12 110 DATA 9, -,-,-,-, 176, 98,4,1 115 DATA Q,-, -,-,-,228,70,-2, -15 120 DATA 0,228,70,-1,0,210,43,0,1 125 DATA 0,210,43,-70,-43,140,60,-55,50 130 DATA 0,-,-,-,-, 83, 40, -6,-19 135 DATA F,60,80,. 930 mmmmmmmmmmmmmmmmmmm$ 950 REH MAIN PROGRAM TO READ DATA AND INTERPRET COMMANDS 970 mimwmfflmmmminnnmmmMmimmm 1000 SN=5:DIM SY$(SN) 1020 SY$(1)="L":SY$(2)="C':SY$(3)="P":SY*(4)="F H :SY$(5)="S" 1030 LM=550:DIM X(LM),VtHG 4010 IF LS*="-" THEN LX=9Y ELSE LX=VAULXt>tH6 4020 LINE, PRESET 4040 QX=LY:BY=LZ 4060 DX=LY-LW:DY=LZ-LX 4100 RETURN 4930 RErtiii335333WS35wJJ33iJSSS3^i5i35#ij>3i**ii3 : iW^3ii*5id 4950 REM CIRCLE 4970 REt1^iiii333W3£*3*J353i'5Wi*i v iW-i5i^i3w^JMi»i5ii35i.}J 5000 READ CA,CB,CR 5015 CA=CAiM6:CB=CB*M6:CR=CRtMe 5020 CIRCLE 8010 REM DETERMINE COEFFICIENTS A,B,C,D 8020 B=X2-X1;D=Y2-Y1 8040 Ti=VUB-UltD : T2=V2tB-U2»D 8060,DI=VltU2-V2tUl 8080 IF DI=0 THEN PRINT "DI=0 n :80T0 1500 8300 C=(V2»T1+VUT2)/DI 8120 A=(U2tTl+UltT2)/DI 8130 REM DETERMINE LARGEST PARAMETER SPACING, H, FOR CONTIN PLOT 8140 G1=ABS(B-A):G2=ABS(B+A):G3=ABS!D-C):G4=ABS(D+C) 8160 HX=G1 8180 IF 62>MX THEN MX=G2 37 8200 IF 63>HX THEN HX=S3 8220 IF 64>HX THEN MX=S4 8240 IF MX=0 THEN PRINT "HX=0":S0T0 1500 8260 H=1.9/MX 8270 REH PLOT THE CURVE 8273 X4=INT(X2+.5):Y4=INT(Y2+.5>:PSET(X4,Y4,0} 8275 X3=INT(XH-.5):Y3=INT(Y1+.5):LINE(X3,Y3)-(X3,Y3),PRESET 8280 T=H 8285 IF T>=1 THEN 8335 8300 : Rl=T*iT-l> 8320 : Pl=A*Rl+BtT+Xl:PI=INTiPH-.5}:XD=flt(T+T-l)+B 8340 : P2=C»Rl+DtT+Yl:PJ=I»ITtP2+.5hYD=Ct+D 8343 IF (INT(P1)=L1) AND (INTIP2>=L2> THEN 8380 8345 : L1=INT(P1):L2=INTABSiXD) THEN 3363 8353 : 9U=INT(P2+(YD/XD>*Ul-Pl)+.5) 8354 LINE-iLl,8U>, PRESET 3360 : GOTO 8380 8363 REH 60 ON 3366 : B»=INT(Pl++.5) 8367 LINE-(BW,L2>, PRESET 8330 T=T+H:60T0 8285 8385 LINE-(X4,Y4), PRESET 8390 9X=X2:BY=Y2 3395 BX=U2:DY=V2 8400 RETURN 9930 mmmmmmmmdmmdiJim^*mi*ummM 9950 REM BOUNDARY EATER 9970 mmmmmmmmmmmmm^immmmM 10000 INPUT "START PT";X,Y 10005 INPUT "START VECTOR DIR U,D,L,R";DRt 10010 INPUT "START PT-VEC REL G,S";RL$ 10020 T6=.5:T7=.5:T8=.5:T9=.5 10022 IF RL$="S" THEN T6=-.5:T7=-.5:T8=-.5:T9=-.5 10024 IF DR*="R" THEN T6=-.5:T3=.5 10026 IF DRt="D" THEN T7=-.5:T9=.5 10028 IF DRt="L" THEN T8=-.5:T6=.5 10030 IF DRt="U" THEN T9=-.5:T7=.5 10035 BX=X+T6:8Y=Y+T7;EX=X+T8:EY=Y+T9 10050 WH=5:BL=0:REH WHITE, BLACK 10060 TP=-1:REH INIT POINTER TO TOP OF POINT STORE 10070 TP=TP+1:X"R" THEN Dl=-1 10230 D2=l 10240 IF DR$="U" THEN D2=-l 10250 IF RL*="S" AND DRJO°D" THEN D2=-l 10270 REM COMPUTE DO AND OT 10280 IF PP0INT:NE)iT K 10668 SCREEN 1,1 10670 FOR K=0 TO TP:PSET (X (K) , Y ,BL) :NEXT K 10700 RETURN 1 1 930 REMMM3MMS3 JS mi immmmm mmmm mi mi 11950 REM POST SCREEN TO PRINTER 11970 re mm mmm i a mmummm m am m mmi n 12000 PRINT#-2,CHRt(27);"A";CHR$(0);CHR$«15) 12020 AD=1536 12040 FOR R=l TO 64 12060 FOR C=i TO 32 30 12070 Bl=PEEK(AD>:B2=PEEK 12080 POKE 32500, Bl: POKE 32501, B2:P0KE 32502, B3 12090 IFiBl AND B2 AND B3)=255 THEN PRINT#-2," °;:GOTO 12180 12100 FOR U=l TO 4:EXEC 32504:PRINTi-2.CHRt(PEEK(32503)*160);:NEXT U 12180 AD=AD+1 12200 NEXT C 12220 PRINT#-2," " 12230 AD=AD+64 12240 NEXT R 12250 RETURN 12930 mmmmmmmmmmmmmmmmmma 12950 REM HACH LAN6 SCREEN DUMP SUPPORT 1 2970 REMiiiiiiSii h Ji m s mn namm mmm i w nmm 13000 DATA 121,126,244,118,126,247 13010 DATA 121,126,244,118,126,247 13020 DATA 121,126,245,118,126,247 13030 DATA 121,126,245,118,126,247 13040 DATA 121,126,246,118,126,247 13050 DATA 121,126,246,118,126,247 13060 DATA 67,118,126,247 13070 DATA 67,118,126,247 13080 DATA 115,126,247 13090 DATA 57 13100 FOR 1=32504 TO 32551 13110 READ A 13120 POKE I, A 13130 NEXT I 13200 RETURN 1 7930 mmmmmnmnmimmmmmmmmmt 17950 REM LEAST SQUARES CUBIC C0EFFS 1 7970 mmmmmmmmmmmimmmiimmij 18000 INPUT "S,E";S,E 18010 Bl=X(E)-X 1 8020 S1=0: 32=0: S3=0: S4=0: S5=0 18030 K=S 18040 REH BEGIN LOOP (D0NT DELETE) 18050 A1=X(K)-X(S):A2=YTP THEN K=0 18150 GOTO 18040 18155 REH GO ON (D0NT DELETE) 18160 DT=S3tS5-S4tS4 18170 IF DT=0 THEN PRINT 'NO SOL TO LEAST SQUARES":60TQ 18200 18180 A=(32tS3-SUS4)/DT:B=(SltS5-S2tS4)/DT 18200 RETURN 40 18330 9£mmm*mwwnwwwnmmmm9mMnm 18350 REH AVE ABSOLUTE AND HA)! ERROR FOR LEAST SQ CUBIC 1 83?o re ii id m w a m i j m n a m i » m S3 nm m mm m 18400 ER=0:UR=0:CN=0 18410 K=S 18420 REH LOOP (DONT DELETE) 18430 CN=CN+1 18440 A1=K(K}-X(S)jA2=Y(K>-Y 13480 ER=ER+LR 13490 IF LR>UR THEN UR=LR 13500 IF K=E THEN 18530 18510 K=K+1:IF IOTP THEN K=0 18520 GOTO 18420 13530 REH 60 ON (DONT DELETE) 18540 ER=ER/CN 18550 PRINTf-2,"ER = ";ER,"UR = ";UR 18600 RETURN 19030 m%M%M%%%%%m%%fflimwmmmnnwmmnwti 19050 REH BETTER PLOTTER FOR LEAST SQUARES CUBIC 19070 REHi3SiWWSJSWJi35WWW53W3WW^i3iJMWJ3iwSi55i 19100 IF A=0 AND B=0 THEN LINE(SUS),Y(S))-()i(E},Y(E)i,PRESET:GOTO 19450 19105 IF A=0 THEN 81=0:60T0 19140 19110 X9=(A*BB-B)/(3tA) 19120 IF (X9>BB> OR (X9<0> THEN 81=0:6010 19140 19130 61=ABS{3tAtX9tX9+2t(B-AtBB)«X9-BtB8) 19140 REH 60 ON (DONT DELETE) 19150 62=ABS(BtBB) 19160 63=ABS((At3B+B)tBB) 19170 HX=61 19180 IF 62>HX THEN HX=62 19190 IF B3>HX THEN WX=63 19200 IF MX=0 THEN PRINT "HX=0":60T0 1500 19210 H=1.9/HX:REH MAX XBAR CHAN6E FOR 600D GRAPH 19220 REH PLOT THE CURVE 19230 X4=INT(X(E)+.5):Y4=INW(E}+.5)jPSETU4,Y4,0) 19240 X3=INT(X(S> + . 5) :Y3=INT«-.5>:LINEIX3,Y3>-IX3,Y3>, PRESET 19250 XT=H:Z1=X3jZ2=Y3:L1=X3jL2=Y3 19260 IF XT>=BB THEN 19410 19270 YT=(AW+B)Wt()(T-BB) 19230 Pl=X(S)t(YTtB2+XT»Bl)/BB:PI=INT(Pl+.5):XD=Pl-Zl;Zl=Pl 19290 P2=Y:L2=INT(P2):H1=L1+1:H2=L2+1 19320 IF ABS!YD))ABS(XD) THEN 19360 19330 QU=INT(P2+(YD/XD>*(L1-P1)0) 19340 LINE-(L1,BU), PRESET 19350 GOTO 19390 19360 REM 60 ON (DONT DELETE) 19370 BW=INT(PH-(XD/YD)t(L2-P2>+.5) 41 19380 ljne-(b»,l2>, preset 19390 xt=xt+h 19400 SOTO 19260 19410 LINE-(X4,Y4), PRESET 19450 RETURN 20930 REMM3Mtt«M«MittMWM3iMMa«MM3MMM«aMM 20950 REM FASTER BOUNDARY COMPACTOR 20970 REHtt9W339WW33attdWWftftft33d393ttWW33WWW3 21000 INPUT "STARTING PT i";SR 21003 INPUT "MAX ERROR TOLERATED"; UP 21006 JS=5:REM JUMP SIZE 21010 IP=-1:CR=0:S=SR 21015 TIMER=0 21020 REM REPEAT FINDING THE LARGEST SEGMENTS (DONT DELETE) 21040 E=S 21050 REM REPEAT JUMPING UNTIL TOO BIG (DONT DELETE) 21060 CR=CR+JS:E=E+JS:IF E>TP THEN E=E-TP-1 21070 GOSUB 18010:G0SUB 18400:REM OBTAIN A,B,UR,ER 21030 IF URUP THEN 21090 21130 IP=IP+1:S(IP)=SjE(IP)=E:A(IP)=A:B(IP)=B:REM SAVE SEGMENT INFO 21140 S=E 21150 IF CR