Objective: Introduction to DSP ECE-S352 Fall Quarter 2000 Matlab Project 1 This Matlab Project is an extension of the basic correlation theory presented in the course. It shows a practical application of correlation to image processing. In fact during the late 1970 and early 1980 a company called View Engineering sold a product that implemented this process. Image Representation (simple discussion) An image may be represented by an array of numbers. Each element of the array is called a pixel (picture element) and in general represents the intensity of light from a scene falling on a 2-dimensional sensor. Each pixel represents a discrete spatial location of the scene. The value of each pixel is obtained by integrating the intensity (charge) on the sensor for some given time. The data is read out, the charge is reset and the process may repeat. Images may be any size; one example is a 640 by 480 image. This corresponds to 640 pixels across and 480 pixels down and generally corresponds to the area of a CCD camera sensor. This particular image digitization scheme has square pixels since the area of the CCD sensor is 4 units horizontally and 3 units vertically (a 4 to 3 aspect ratio). Similar to the sampling of electronic signals, spatial sampling defines the ability to discern characteristics such as lines or edges in a digitized image. In image processing, the origin of a image is traditionally the top left corner (0,0) and the x axis increased going across while the why axis increased going down. This makes a right hand coordinate system with the z axis going into the plane of the paper. If the image is a binary image then a bit can represent each pixel (black = 0 and white = 1); if the image is a gray scale image then a word (8 bits) may be used to represent each pixel. For the gray scale image, a word represents values in the range [0, 255] with zero as black and 255 as white with gray values. Other gray scale representations are also possible. Hence images are represented as spatially sampled and intensity sampled signals. Binary Correlation Matlab Exercise page 1 of 5
Image Comparisons/Binary correlation In many image processing applications, it is desired to find a particular pattern in a larger image. One method of doing this to use a reference image which corresponds to the pattern in questions and find the best fit of the pattern in the larger image. Hence for each position in the test image, one would expect some type of "quality" measure defining how good of a match occurred (say from 0 to 100 %). Mathematically this may be represented as: where: O(x o,y o ) = G{T(x-x o, y-y o ), t(x,y)} t(x,y) = the image to be tested T(x,y) = the reference sub-image (smaller than t(x,y)) x o,y o = the spatial translation offset of the sub-image in the test image O(x o,y o ) = the response of the operation G{.} = the comparison operator There are many type of operators that can be used to perform the comparison such as "nearest neighbor classifier" or the Fisher Statistical Correlation Coefficient sometimes called Normalized Correlation. For our example and exercise we will use binary correlation. As expected both the image and template are binary in nature. The process is defined as follows: 1) A template is defined. For binary correlation it is usually part of the image (i.e. a sub-image) but may take any geometric form that is desired such as a square, rectangle, line or even a disjoint set of pixels that maintain a fixed spatial relationship to one another. In the View Engineering product one would demonstrate (or teach) the template by placing a box around the portion of the image that corresponded to the area of interest. 2) One pixel of the template is chosen as a reference point. 3) The template is then overlaid on the test image. The number (or fraction) of pixels in the template that match the test image over which it is placed are computed. Basically a count is made of the Binary Correlation Matlab Exercise page 2 of 5
pixels that match (either 1's or 0's) This is the sum of a complementary XOR function performed between the corresponding template and test image pixels. 4) The value computed above is placed in a resultant image, O(x o,y o ) at the location corresponding to the template's reference position. 5) The procedure is repeated until the template has been overlaid on each pixel location in the entire image. It may be necessary to "pad" the test image with rows or columns of zeros, that is provide more data in cases where the template extends beyond the image. Numerical Example: consider the following 3x3 template and the following 15x20 test image 01111000011010111111 11000110011111000000 11011011100010011110 10001000110000111111 00011001110111110000 01000110010011000110 00110110110000011011 11110101000101000000 00010100010011111101 01010000110011001111 11100111000111011110 00001011110100011101 10100001011101111101 01101110001011101100 01110000111110111101 If one selects the top left corner of the template as the reference, it is easily seen that the image runs out of data along the last two columns and two rows, hence two columns of zeros must be added to the right of the image Binary Correlation Matlab Exercise page 3 of 5
and two rows must be added to the bottom of the image so the reference point can be moved over the entire 15x20 image. The resulting output is given as the following 15x20 image 6 2 3 5 3 6 4 4 5 7 4 9 3 4 3 2 2 3 3 3 5 5 5 6 5 6 5 5 5 2 4 4 4 4 5 6 6 5 5 3 5 1 5 5 2 3 4 5 5 3 3 4 3 4 7 5 6 7 5 5 4 4 5 6 4 5 4 6 7 4 5 7 6 6 5 3 3 3 3 3 4 4 4 3 5 5 3 4 5 2 5 5 5 3 4 4 4 6 5 3 5 4 6 3 7 4 6 4 7 3 4 2 5 3 6 5 6 6 5 5 6 6 7 2 6 5 3 4 5 3 4 6 4 3 3 3 2 2 5 2 4 2 6 3 6 3 4 4 5 3 5 4 8 5 6 7 5 5 5 4 4 5 5 2 5 2 5 4 7 3 4 5 5 2 4 4 6 5 6 4 8 4 5 5 4 7 4 4 4 2 6 6 6 4 5 6 6 3 6 2 1 5 3 4 6 4 8 4 6 4 5 2 4 2 5 5 5 4 5 4 6 5 2 5 1 5 3 5 5 6 5 5 5 6 5 6 6 3 6 4 4 6 5 5 7 5 5 2 4 3 5 4 5 5 4 4 6 1 6 2 6 7 4 5 3 4 4 6 6 8 5 6 5 6 5 7 6 5 5 5 4 3 4 3 4 4 3 4 3 3 3 4 2 4 3 3 4 2 5 3 The corresponding surface plot shows the peak value of 9 corresponding to spatial location row 1 column 12. Two Matlab mfiles for this example are included on the web site. They are called binary_corr.m and main_bc.m Binary Correlation Matlab Exercise page 4 of 5
Student assignment: 1) Get the Matlab programs to run and duplicate the results of the example. This code had been designed to run on either the Student or Professional version. It should run on versions 4.3 and above. Make sure you understand how the template and image are overlayed. Look carefully at the reshape function. Use the rotate tool on the surface plot to set the axes similar to the example. 2) Modify the program to work with a larger template. Use the following 5x3 template Define how much padding you will need to generate the output matrix. Does this larger template give better discrimination (i.e. less larger numbers as compared to the 3x3 template)? Discuss why. 3) The process used for binary correlation can also be used to find features such as corners in an image. To illustrate this concept make a 10x10 image consisting of white pixels in the center 6x6 array surrounded with a black background (all zeros). Define the following templates Top left Top right Bottom left Bottom right Use binary correlation to find the four corners. Obviously you need to run each template separately and combine the results. Think of a way to identify this graphically. 4) Define a template that will find the left edge. Test you template on the image of part 3. Binary Correlation Matlab Exercise page 5 of 5