Page 200 - The Definitive Guide to Building Java Robots
P. 200

Preston_5564C06.fm  Page 181  Friday, September 23, 2005  5:13 AM



                                                                                   CHAPTER 6  ■  VISION  181


                        6.2 Basic Image Processing

                        There are many types of image processing. I would like to classify the processing into three
                        types: pixel processing, area processing, and convolution and combination processing.
                            Pixel processing is the process of moving through an image pixel by pixel, getting a color
                        value, and doing something with it. Many times, you’ll need to remember values and place
                        them in storage arrays. For example, take Figure 6-8. There are nine pixels. If I move from left
                        to right and top to bottom, PixelProcessing would look at each of the color components and do
                        something with them. So, if I wanted to turn them to grey, the pixel at (1,0) would have an RGB
                        value of (255 + 0 + 0) / 3 = 85, and the resultant color would be (85,85,85).


































                        Figure 6-8. A pixel-by-pixel image

                            The second type is convolution. This is the process of moving through an image pixel by
                        pixel, and then doing something with it in relation to its surrounding pixels. This is done via an
                        operator called a kernel. A kernel is a matrix of numbers that specify how to change the value
                        of a single pixel as a function of its surrounding pixels. You can think of a kernel as a template
                        that fits over each pixel and then changes it based on the values inside it. A sample matrix for
                        smoothing an image would be
                        {1/9, 1/9, 1/9,
                        1/9, 1/9, 1/9,
                        1/9, 1/9, 1/9}
                            The calculation process moves like this. Let’s start at the fifth (or center) pixel. Multiply the
                        pixel at its top left by 1/9, then move to the pixel to the right of that, which is above the center
   195   196   197   198   199   200   201   202   203   204   205