Вы находитесь на странице: 1из 9

Matlab Project Andy Modell Engr 151

1A: Snoopys centroid Finding the centroid of Snoopy involved quite a bit of work. To begin with, I ran a line of code in order to set 0 any pixel that was not white and maximize any pixel that was. This left me with the Snoopy, some of the coke, and much noise. After running the erosion filter, I had a rather piss poor representation of Snoopy, but I found its centroid (labeled sc1). With this centroid in mind, I was able to run a function that set 0 all pixels that were more than 130 (value determined via trial and error) pixels away from my sc1. After doing this, I was able to get a pretty good representation of Snoopy with which to, once more, use the regionprops function to find the centroid. Using the below image, I was able to find: SC = Horizontal (y) : 143.3 Vertical (x) : 635.5

Figure 1: Threshold image used to identify the SC. Pixels used by matlab to generate the SC are white

1A2: The Blue Treat In order to find the location of the Blue Treat, I ran an algorithm to set max all pixels that had a high blue value and low other values. This eliminated most of the white points because they generally had high values of green and red too. After this, I ran the medfilt2 to get the image of my blue treat. For use in part three, I grabbed the centroid of the treat as: Blue Treat: x=516.6, y=916.27

Figure 2: The Blue Treat (blue)

1B: The CCB I isolated the CCB in the same way that I isolated the blue treat initially, by maximizing red points that contained little blue or green. Instead of using only a medfilt2 to get rid of all the noise however, I was forced to use six of them: >> coke=(medfilt2(medfilt2(medfilt2(medfilt2(medfilt2(medfilt2(redfilted(:,:,1)))))))); **redfilted is the image after using my initial red filter In order to make the best fit line, I had to first put the three layer image into a two layer. In order to accomplish this, I first ran a function that calculated the number of red pixels (count), created a count by 2 matrix, and added all of the red pixels locations to the matrix. With this matrix at hand, I was able to run the polyfit function to grab the coefficients that lead to the line: x=0.7838*y+133.56 Paired with a vector known as y, which contained points 1:1024, I was able to plot the line. Using the data courser feature of the imshow() window, I was able to determine the endpoints of the line being: Endpoints: {(319,383) , (768,736)}

Figure 3: The CCB (red) with its best fit line (green)

1C: Snoopys height Initially, I used the MajorAxisLength operator from the regionprops function to generate the twice the radius of Snoopy, but I realized that this measure would not account for the fact that his feet do not reach as far from the centroid as the tip of his nose. While I still used this radius for other calculations, I used the Data Courser and the distance formula (calculated in matlab of course) to get the height of Snoopy in pixels as h=237.6. While I did not have a can of Coke, I was able to measure a can of Vernors. I got the measure of 4.8 converted to 0.121m and used the Data Courser to get the height in pixels as 63.6. Multiplying the ratio of the can heights by the pixel height of Snoopy, I got: Height = 0.448 Meters

2: Configuration Space Generating the configuration space took me far longer than anticipated. Initially, I tried mathematically generating lines representing the borders of the CCB by modifying my best fit line from earlier, but white I was able to get two of the three sides by changing the constant value of the function with relation to half the can height, it was difficult for me to achieve a perfectly correct end of the CCB with the modified slope. Then, I tried making circles around the best fit line with radii equivalent to the radius of Snoopy added to half the height of the cans; this failed because it overextended too much over the top end of the CCB. Ultimately, I created a function that took my image of the red color in the CCB and created a circle using the algorithm for every single red point:
if ((y-j)^2+(x-i)^2)<(rs^2)

where rs is the radius of Snoopy, y and x are a red point and i and j are the current value in two loops that check points within a square that had edges rs above, below, left and right of the point (y,x).

Figure 4: Configuration Space, the SC (red), the Blue Treat (blue), locations where the SC cannot go (black), locations where the SC can go (white)

3. Path Planning

Figure 5: The Path (green) that Snoopy follows around the CCB to reach the blue treat, the configuration space (black/nonblack), and the visibility graph (gray colors) The path finding for Snoopy was done with a wavefront algorithm. The first step was to generate a visibility graph that showed each points distance from a goal (the blue treat) by the intensity of the color (darkest at the treat, brightest at the farthest point from the treat). For this simulation, I used the Von Neumon neighborhood, looking at points in the 4 cardinal directions around values. Because of the presence of the CCB, the farthest points are not those at the opposing edge of the field of view, but the points it would take longest to reach while walking around the CCB. In order to generate the visibility graph, I set the blue treat to 2 and looped through the entire visible space searching for all spots adjacent to value>1 points assigning values that increased with each iteration of a grand while loop (I looped through all pixels then increased the count). In order navigate Snoopy to the blue treat, I began at the SC and looked for any adjacent point with an intensity value lower than the current point, plotted the current point in green, then moved the current point (Snoopy) to the point with the lower intensity. This path makes sense because the nature of the visibility graph In the Von Neumon neighborhood is such that every point of a lower intensity is closer to the goal and the way it is generated allows for there to be only the possibility of moving in the most efficient manner. Because of the nature of the configuration space having 0 values where the SC cannot travel, this visibility graph wavefront method will always keep

Snoopy from breaching the CCB because he wont tread on values marked as black. Looking at Snoopys path, it is clear that the minimum distance to the CCB is that of Snoopys radius as he follows along the edge of the configuration spaces restricted zone. Ultimately, my algorithm has Snoopy reaching the blue treat in: Distance: 1554 pixels

Figure 6: Test case using the configuration space (left) and generating the visibility graph (right) In this test case (figure 6), all the same criteria are used as in the actual example, but a thin wall has been added preventing Snoopy from crossing. Because Snoopy residing in the points to the left of the wall cannot see the treat by any means, those points are left in the dark. When the code is run, Snoopy immediately realizes the inevitability of his situation, being unable to reach the treat do to some dastardly plan of the Red Barron, and is frozen in place; Snoopy makes no path here (hence the lack of path) and the value -1 is returned.

The other test case (Figure 7) demonstrates three significant aspects of the algorithm: using a different location for the SC (Snoopy), using a different test case for the goal (blue treat) and using a configuration space with different dimensions than that of the original image. Here, a thin black wall was placed between Snoopy (at the top) and the treat (at the bottom). To reach his goal, Snoopy simply had to navigate alongside the wall and reach his treat. The dimensions for this image were <1000x500x3>, SC was at (252,42) and the treat was at ( 236,930). The distance Snoopy had to travel in this case was: Distance = 1156 pixels

Figure 7: Additional test case 2

Вам также может понравиться