image to stained glass - university of...

12
Image to Stained Glass Course Project CS 534, Fall 2015 Xiuming Chen, Melissa Lakritz, Benjamin Chang

Upload: others

Post on 28-Aug-2021

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Image to Stained Glass - University of Wisconsin–Madisonpages.cs.wisc.edu/~dyer/cs534/hw/hw5/Project-Reports2015... · 2015. 12. 17. · Stained class, as beautiful as it was, also

Image to Stained Glass Course Project ­ CS 534, Fall 2015 

   

Xiuming Chen, Melissa Lakritz, Benjamin Chang                            

    

Page 2: Image to Stained Glass - University of Wisconsin–Madisonpages.cs.wisc.edu/~dyer/cs534/hw/hw5/Project-Reports2015... · 2015. 12. 17. · Stained class, as beautiful as it was, also

Introduction  The ability to perform visual transformations on images is readily available to almost any user                             with a smartphone, with applications ranging from giving your image the effect of being                           blended, morphed, cartoonified and made to look as though the image was taken hundreds of                             years ago. This inspired our topic, as we built a program to take any input image and the result                                     was the picture realistically transformed to look as if it was                     stained glass.  The term stained glass refers to the  combination of geometric, colored glass pieces bonded             together to create an image, historically most popular in the                   windows of churches, mosques and significant buildings.             Some of the most opulent and colorful pieces of stained glass                     artwork can cover over 60 feet of window space, which                   requires meticulous artistic design and engineering skills to               assemble to pieces properly so the final image is fluid. The                     look of stained glass is familiar to users as it represents some                       of the most colorful pieces of famous artwork, and if the user                       did not come across the origins of medieval glass work or                     it’s revival during the 20th and 21t centuries, they most                   likely have experimented with it as a child in art class. For                       these reasons, this nostalgic and visually pleasing technique               is sure to be a creative way for users to transform their                       images.  

   

Page 3: Image to Stained Glass - University of Wisconsin–Madisonpages.cs.wisc.edu/~dyer/cs534/hw/hw5/Project-Reports2015... · 2015. 12. 17. · Stained class, as beautiful as it was, also

Background  

If you were to visit a historically renowned cathedral or mosque, you will likely be                             bathed in the colorful, rainbow beams of sunlight passing through the windows. These beautiful                           rays of light capture the attention of any visitor, which eventually draws the attention to the large                                 stained glass windows in which the colorful lights are attributed to. Stained glass is the term                               used to describe pieces of colored glass joined together with some bond or clay to form a final                                   picture or design. In this case, stained glass images often have high historical relevance and also                               tend to be represented in buildings of religious               significance. 

The process of making colored glass was             invented during the ancient period, likely in Egypt.               However, stained class became a trademark during the               Middle Ages, with it being a significant form of art.                   Stained glass windows were a common and important               feature of churches built in the Gothic era, filling the                   interior with light and color that drew in worshipers                 with their opulence. 

Stained class, as beautiful as it was, also served an educational purpose. During the                           Middle Ages, the church was also the center of learning. There were few published books                             available for education, and even at that, not many students could read. The stained glass                             designs commonly depicted religious scenes and a sequence of stained glass windows could tell                           

stories from the Bible, which made their development               vitally important to visually teaching Christian beliefs to               the people. As the years went on, the windows were also                     used by wealthy leaders and merchants that paid to have                   stained glass created to glorify themselves as saints and                 kings. The methods the artisans and builders used to create                 stained glass windows are mostly still in practice today.                 The process would begin with an artist drawing an image                   on a large surface, the same size as the window, of the                       scene or subject. The artist would divide and number                 

each section of the image according to color. Then, following the outline and the numbered                             sections, the colored glass pieces were cut out of a hot iron and placed together with lead in                                   between each piece, until they bonded together in a tight fit. The lead served it’s purpose to hold                                   the glass together, but also becomes part of the final design to prevent two neighboring colors                               from appearing to overlap. Last, the final image was given a frame in order to complete the                                 

Page 4: Image to Stained Glass - University of Wisconsin–Madisonpages.cs.wisc.edu/~dyer/cs534/hw/hw5/Project-Reports2015... · 2015. 12. 17. · Stained class, as beautiful as it was, also

image and some of the largest products             requiring iron bars to hold them up on the                 church walls. The stained glass murals were treasured by             the people, as mentioned before because of             their unique beauty, color, and education           purpose. When war plagued Europe in the             1930’s, the stained glass windows were taken             apart piece by piece in order to be preserved.                 As an attestment to their beauty, after the war                 the windows were carefully put back           together.  In our application of this process, the             approach involves taking an image, and           partitioning it into smaller pieces that make             up the glass tiles. The tiles are colored in a                   way that averages the color of the region of                 the source image that it is replicating. When               viewed from a reasonable distance, the           human eye naturally perceives the final           image by merging the different colored glass             together into a representation of what the             input picture is. On their own, each of the                 pieces of colored glass appears to be only a                 shape with little significance, but placed           together it forms a scene that can actually               communicate a story. To impose our own creative approach to this standard implementation, we wanted our stained                           glass to take on different characteristics that made the final product even more interesting.                           Imagine if all the stained glass pieces were the same geometric shape rather than being tailored                               to a similar shape to that of the original image. This would mean that the glass pieces before                                   being composed together would have very little power of communicating, but great artistic                         appeal when placed together.       

Page 5: Image to Stained Glass - University of Wisconsin–Madisonpages.cs.wisc.edu/~dyer/cs534/hw/hw5/Project-Reports2015... · 2015. 12. 17. · Stained class, as beautiful as it was, also

Problem Statement  Program Steps and Objective:  Our program is given an input image and goes through a series of steps and computations to                                 create an output image that matches our proposed stained glass style. At a high­level, we have                               designed our program to follow this outline: 

● Take any specified image as input to the program ● Create a matrix of certain weights to obtain randomly selected points (pixels) on the                           

image ○ Pixels inside the image will be assigned lower weights than those on the borders                           

of the image so they are less likely to be selected in the next step ● Using the generated points, select a specified amount of them randomly over the height                           

and width of the image by comparing the point to the specified threshold ● Use the Delaunay triangulation algorithm (the most widely used triangulation algorithm                     

in scientific computing) to create triangulation pattern out of the points that ensures the                           circumcircle of each triangle contains no other points in its interior 

● Find the area (the specified pixels) that lie within the borders of the triangles and obtain                               their RGB value to be used for coloring 

○ Average all of the RGB values found within each triangle and fill the inside of the                               triangle that color 

● Output the final stained glass stylized image  Problems Faced:   As we wrote the program, we had to solve and overcome two problems during development of                               our stained glass algorithm implementation, here are the problems and the steps we took to                             successfully work through them as a team: 

1. Since we were using an existing Matlab function in order to create triangles from our                             generated points, the first major problem we faced was understanding the process and                         implementation of the Delaunay triangulation. We began by reading all the provided                       documentation on MathWorks to build fundamental knowledge, including its syntax,                   description and visualization of the function. Then, we searched online to reference how                         it was used in other programs similar to ours and looked at sites such as StackOverflow to                                 see examples. We were able to find some code snippets of its use, even though they were                                 not exact to our implementation, it helped us see where we could reference code and                             make adjustments to fit our program. 

Page 6: Image to Stained Glass - University of Wisconsin–Madisonpages.cs.wisc.edu/~dyer/cs534/hw/hw5/Project-Reports2015... · 2015. 12. 17. · Stained class, as beautiful as it was, also

2. Since the Delaunay triangulation only creates the visual borders to each triangle, the                         second problem we faced was distinguishing which pixels lie within the borders of each                           triangle in order to obtain their RGB values to fill the color of the triangles created. 

 

Method  

First, we analyzed the significant traits of stained glass to help guide our method in our                               we would approach implementing a program whose results were aesthetically pleasing and                       historically accurate. We discussed that glass pieces are most resemblant to triangles, therefore                         we would go about dividing our images into some group of small triangles and then fill the                                 triangles with a color that represents the best average of the pixel’s color contained in the interior                                 of those triangles. Then, working backwards, we deconstructed the triangles into a set of three                             points, or vertices. This way, we could approach the problem as designating a set of vertices, as                                 simple as a group of pixels, on the image. We would then have to begin our implementation by                                   generating points (pixels) on the image that correlates to the size of the image and how abstract                                 we want the final result to be.   

We visualized our final resulting image as creating these triangular glass pieces on the                           original image to represent the pieces of glass and be colored in a way that represents the                                 original, average color of that area. The resulting image would then be closely resembling an                             artist's rendition of stained glass by way of putting accurately sized triangle pieces together to                             form a larger, image that can be recognized as a variation of the original object or scene.   

Implementation  

Our implementation can take any user­specified input image and will output the image to                           artistically resemble a stained glass piece. 

Our program takes in the input image through the image read function. First, we find the dimensions of the image to create an empty matrix. Next, our program is to generate points of interest. We focus on three variables to set the                                 

border density, inner density, and corner pixels of the image. This is important because we want                               to ensure that our final image more evenly distributed points throughout the image. In order to                               do this we select an equal amount of pixels on the border of the image, in the interior, and make                                       sure the corner pixels are always chosen. This is because if not enough border or corner points                                 are selected, parts of the image will get cut off during the triangulation due to not being inside                                   the points of interest.   

We set the border and inner pixels equal to a constant of 1000 and the corner pixels to                                   2000 (the ensure they are always selected). We iteratively go through and multiply each index                             

Page 7: Image to Stained Glass - University of Wisconsin–Madisonpages.cs.wisc.edu/~dyer/cs534/hw/hw5/Project-Reports2015... · 2015. 12. 17. · Stained class, as beautiful as it was, also

by a value that is randomly generated on each pass. Now that we have our weighted matrix                                 calculated, we iteratively compare each value to specified threshold (999). After some                       experimentation, we found this worked the best with a threshold that is lower than the interior                               pixel constant (1000). If the weighted matrix value is greater than the threshold, it is chosen as a                                   point. From the points that are selected, we obtain the x and y coordinates to pass into our                                   Delaunay triangulation function.   

The delaunay triangulation function “creates a Delaunay triangulation of a set of points in                           2­D or 3­D space. A 2­D Delaunay triangulation ensures that the circumcircle associated with                           each triangle contains no other point in its interior.” From the delaunay triangulation, we extract                             the vertices of each individual triangle as a set of three points and create a mask so we can obtain                                       the pixels that lie within each triangle. From each pixel obtained from the mask, we add their                                 RGB value to a running sum to compute the average color within the triangle region of interest.                                 This process is then used for the remainder of the triangles generated by the Delaunay                             triangulation algorithm. After all triangles’ colors have been computed, the result is a stylized                           stained glass image.    

Results  Preliminary Results  Bad Results: Corner pixels are not selected in the weighted matrix: 

  

Page 8: Image to Stained Glass - University of Wisconsin–Madisonpages.cs.wisc.edu/~dyer/cs534/hw/hw5/Project-Reports2015... · 2015. 12. 17. · Stained class, as beautiful as it was, also

Interior pixel constant is higher than the threshold: 

 As the interior, border and corner constants increase, less points are chosen: 

      

Page 9: Image to Stained Glass - University of Wisconsin–Madisonpages.cs.wisc.edu/~dyer/cs534/hw/hw5/Project-Reports2015... · 2015. 12. 17. · Stained class, as beautiful as it was, also

Good Results: 

        

Page 10: Image to Stained Glass - University of Wisconsin–Madisonpages.cs.wisc.edu/~dyer/cs534/hw/hw5/Project-Reports2015... · 2015. 12. 17. · Stained class, as beautiful as it was, also

Final Results:  

 

      

 

Page 11: Image to Stained Glass - University of Wisconsin–Madisonpages.cs.wisc.edu/~dyer/cs534/hw/hw5/Project-Reports2015... · 2015. 12. 17. · Stained class, as beautiful as it was, also

  

   

Page 12: Image to Stained Glass - University of Wisconsin–Madisonpages.cs.wisc.edu/~dyer/cs534/hw/hw5/Project-Reports2015... · 2015. 12. 17. · Stained class, as beautiful as it was, also

Conclusion  Overall, we are extremely pleased with the results of our stained glass program. We found that                               the quality of the results are the best on pictures from a distance and wide­angle images. The                                 results were most interesting applied to images with many contrasting colors. We think this is a                               really cool effect that can make its way into popular image editing apps and filters. We have not                                   seen any other filter like ours out there, and think it is a fun, creative and artistically interesting                                   way to modify images and create a cool result.  

Project Summary  

● We wrote approximately 150 lines of code, which was all written by our group ● We used the Delaunay triangulation which was provided by Matlab ● Inspiration for our program from the below references ● Main contributions from each team member: 

○ We all contributed in discussing the topic and high­level pseudocode ○ Benjamin Chang: Code writing, paper information, presentation ○ Xiuming Chen: Brainstormed project ideas, coding, presentation ○ Melissa Lakritz: Project ideation and design, code process, presentation, final                   

project paper, website  Website: https://stainedglassproject.wordpress.com/  

References  [1] Gross, Richard. “History of Stained Glass”. http://stainedglass.org/?page_id=169 [2] The MathWorks, Inc. “Delaunay”. http://www.mathworks.com/help/matlab/ref/delaunay.html [3] The MathWorks, Inc. “Delaunay Triangulation”. http://www.mathworks.com/help/matlab/math/delaunay­triangulation.html [4] The MathWorks, Inc. “Delaunay triangulation in 2­D and 3­D”. http://www.mathworks.com/help/matlab/ref/delaunaytriangulation­class.html [5] http://img3.etsystatic.com/il_fullxfull.273213763.jpg [6] http://johnberryphotography.com/blog/wp­content/uploads/2013/12/8­2368­0037.jpg