UBI 516 Advanced Computer Graphics Fractal Geometry Methods Aydın Öztürk ozturk@ube.ege.edu.tr http://www.ube.ege.edu.tr/~ozturk Fractals Many objects in nature aren't formed of squares or triangles, but of more complicated geometric figures. Many natural objects - ferns, coastlines, etc. - are shaped like fractals. Fractals(cont) All the object representations we have considered so far used Euclidean geometry methods that is object shapes were described with equations. Natural objects can be realistically described with fractal geometry methods, where procedures rather than equations are used. Fractals(cont.) A fractal has two basic charecteristics - Infinite detail at every point - Self similarity between the object parts. Self Similarity Geometric figures are similar if they have the same shape. The two squares are similar. The two rectangles are not similar. But the two rectangles are similar. Self Similarity Many figures that are not fractals are self-similar. Notice the figure to the right. The outline of the figure is a trapezoid. All the trapezoids inside make up the larger trapezoid. Self Similarity: Examples Construction of Self Similar Fractals To construct a deterministic self-similar fractal, we start with a geometric shape called initiator. Subparts of of initiator are then replaced with a pattern called generator. Initiator Generator Construction of Self Similar Fractals To construct a deterministic self-similar fractal, we start with a geometric shape called initiator. Subparts of of initiator are then replaced with a pattern called generator. Construction of Self Similar Fractals The Sierpinski Triangle The Sierpinski Triangle(cont.) Step One Draw an equilateral triangle with sides of 2 triangle lengths each. Connect the midpoints of each side. Shade out the triangle in the center The Sierpinski Triangle(cont.) Step Two Draw another equilateral triangle with sides of 2 triangle lengths each. Connect the midpoints of the sides and shade the triangle in the center as before. Notice the three small triangles that also need to be shaded out in each of the three triangles on each corner - three more holes. The Sierpinski Triangle(cont.) Step Three Draw an equilateral triangle with sides of 4 triangle lengths each. The Sierpinski Triangle(cont.) Step Four We follow the above pattern and complete the Sierpinski Triangle. Example-1 Example-2 Example-3 Example-4 Example-5 Example-6 Example-7 Example-8 Example-9 Example-10 Example-11 Example-12 Example-13 Example-14 Example-15 Example-16 Example-17 Example-18 Example-19 Example-20 Classification of Fractals Self-similar fractals have parts that are scaled-down versions of the entire object. Self-affine fractals have parts that are formed with different scaling parameters sx , sy , sz in different coordinate directions. Invariant fractal sets are formed with nonlinear transformations. Fractal Dimension The detail variation in a fractal object can be described with a number D, called fractal dimension, which is a measure of roughness, or fragmentation of the object. More jagged-looking objects have larger fractal dimensions. Fractal Dimension(cont.) A point has no dimensions – no length, no width, no height. A line has one dimension length. It has no width and no height, but infinite A plane has two dimensions length and width, no depth. Fractal Dimension(cont.) A cube has three dimensions, length, width, and depth, extending to infinity in all three directions Fractals can have fractional (or fractal) dimension. A fractal might have dimension of 1.6 or 2.4. Fractal Dimension(cont.) A unit straight-line segment is divided into two equal length subparts. This gives two scaled copies of the original segment. A unit square is divided into four sub-squares. Scaling the length and width by 2 gives four copies of the original square. A unit cube is divided into eight sub-cubes. Scaling the length, width, and height by 2 gives eight copies of the original cube. Fractal Dimension(cont.) Relationship between the number of copies, scaling factor and the dimension. Figure Dimension No. of Copies Line 1 2 = 21 Square 2 4 = 22 Cube 3 8 = 23 Similarity with scaling factor s=1/2 d n = 2d Fractal Dimension(cont.) Sierpinski triangle. Scale the length of the sides of an equilateral triangle by 2. Scaling the sides gives us three copies, so 3 = 2d, where d is the dimension. Solving this equation we obtain the corresponding fractal dimension d=1.584. Figure Line Sierpinski's Triangle Square Cube Doubling Similarity Dimension 1 1.584 2 3 d No. of Copies 2 = 21 3 = 2d 4 = 22 8 = 23 n = 2d Fractal Dimension(cont.) Let s be the scaling factor. Relationship between the number of copies, the scaling factor and the dimension can be written as ns d 1 Solwing this expression for d, we have d ln n ln( 1 / s ) Fractal Dimension: Examples Generator Segment length Fractal dimension 1/√7 d=ln 3/ln(√7)=1.129 1/4 d=ln 8/ln 4=1.500 1/6 d=ln 18/ln 6=1.613 Creating an Image by Means of Iterated Function Systems Suppose that we take an initial image I0 , and put it through a special photocopier that produces a new image I1. I1 is not a simple copy of I0 ; rather, it is a superposition of several reduced versions of I0. We then take I1 and feed it back into the copier again, to produce image I2 ...etc. We investigate whether these images converge to some image. Multiple Reduction Copying Machine Multiple Reduction Copying Machine(cont.) There are multiple lens arrangements to create multiple copies of the original. Each lens arrangement reduces the size of the original. The copier operates in a feedback loop, with the output of one stage the input to the next. The initial input may be any image. Multiple Reduction Copying Machine(cont.) Sierpinski’s Triangle is a typical example http://www.arcytech.org/java/fractals/sierpinski.shtml Multiple Reduction Copying Machine: Sierpinski’s Triangle The Sierpinski’s triangle is a most well known and simplest example of Iterated Function Systems(IFS). It is comprised of three component functions(lenses), each of which shrinks the input image by one half and translates it to a new position. This contractive property guarantees convergence of the iterative process. Multiple Reduction Copying Machine: Sierpinski’s Triangle(cont.) Mathematically, each reducing lense is represented as a contractive affine transformation that acts to scale, rotate, shear and translate a copy of the input image. The three transformations that produce Sierpinski’s Triangle are: 1 2 W1 0 0 0 1 2 0 0 0 1 1 2 W 2 0 0 0 1 2 0 1 2 0 1 1 2 W3 0 0 0 1 2 0 1 4 1 2 1 Multiple Reduction Copying Machine: Sierpinski’s Triangle(cont.) Mathematically, each reducing lense is represented as a contractive affine transformation that acts to scale, rotate, shear and translate a copy of the input image. The three transformations that produce Sierpinski’s Triangle are: 1 2 W1 0 0 0 0 1 0 2 0 1 1 2 W 2 0 0 0 1 0 2 0 1 1 2 1 2 W 3 0 0 0 1 1 2 2 0 1 1 4 Fractal Tree The coefficiens of four transformation matrices Transform W1 W2 W3 W4 a 0.53 -0.31 -0.25 0.29 b -0.08 -0.42 -0.05 0.54 c d 0.08 -0.44 -0.07 -0.04 0.53 0.33 0.29 0.29 e f -0.88 -15.19 1.48 18.74 33.44 19.43 11.73 9.87 Multiple Reduction Copying Machine:Example Partitioned Iterated Function System The basic idea: Find self similarity between larger parts and smaller parts of the image. Partitioning the original image into blocks is a natural choice. Large partitions are called domain blocks, and the small partitions are range blocks. Partitioned Iterated Function System Fractal Image Compression Resim İçindeki Benzer Parçalar Range : Küçük bloklar Domain: Büyük bloklar Resmi Parçalarına Ayırmak Orjinal resim 4x4 Range Parçaları Orjinal 8x8 Domain parçaları ve bunların 4x4’e indirgenmiş halleri Parçaların Benzerliği ri a d i e i ri : i' th range d i : i' th domain Parçaların Benzerliği-3 Benzerini arayacağımız Range üsttedir. Domainler’in orijinal halleri ilk kolonda gösterilmiştir. Regresyon modeline göre düzeltilmiş domainler ise ikinci sütunda gösterilmiştir. Yandaki rakamlar residual mean square(rms) değerlerini göstermektedir. Rms değeri en küçük olan domain eldeki range ile eşleştirilir. Rangeleri Domainler Cinsinden İfade Etmek Benzer Range-Domainler bulunduktan sonra bunlar bir dosyada saklanarak resim bilgisini oluştururlar. Örnek resmimiz 320x200x8 = 512,000 bit (64,000 byte) içeriyor. Domain numaraları 0-999 arasında olduğu için 10 bitle ifade edilebilir. Parlaklık ve konrast tamsayıya çevrilip, 0-15 ve 0-31 aralığında kuantize edilirse, 4 ve 5 bitle ifade edilebilir. Dolayısıyla, 4000 Range’e karşılık gelen Domain bilgilerini dosyaya yazarsak : 4000*(Domain Numarası+Parlaklık+Kontrast) = 4000*(10+4+5) = 76,000 bit (9,500 byte) olmaktadır. 512/76 = 6.73:1, (512-76)/512 = %85 sıkıştırmak demektir, üstelik %85 sıkıştıran diğer algoritmalardan çok daha iyi bir kalitede ! Görüntü Kalitesi Decompression, siyah bir ekrandan başlanarak 8-10 iterasyonla gerçekleştirilir. Resmin kalitesi sonucun orjinale ne kadar yakın olduğuna yani herbir Range-Domain çiftinin ne kadar benzer olduk-larına bağlıdır. Decompression: Iteration-1 Decompression: Iteration-2 Decompression: Iteration-3 Decompression: Iteration-10 Aynı Resimden Daha Fazla Domain Elde Etmek : Domain Transformasyonları Range’e uygun Domaini ararken Domainleri olduğu gibi bırakmayıp transformasyon işlemlerine sokabiliriz. Orjinal, 90o, 180o ve 270o derece döndürülür. X eksenine göre yansımaları alınır. Elde edilen 8 ayrı Domainin negatifi alınarak, bir Domain-den hareketle 16 farklı Domain elde edilir.