Site hosted by Angelfire.com: Build your free website today!

DETECTING US-COINS IN AN IMAGE

by

INGO WIEMER, PREETHI PILLAIPAKKAM

VIRGINIA POLYTECHNIC INSTITUTE AND STATE UNIVERSITY



TABLE OF CONTENTS


INTRODUCTION



coins1.tif

The goal of computer vision is to make useful decisions about real physical objects and scenes based on sensed images.

In our project we aimed at making the computer detect US currency and classify them.

Shown above is an example of how our program works. It works with a scanned input image of coins in tiff format and generates an output image that has each coin labeled in the center with its value.

We worked on 4 different images and in each case the program gave correct results. The program could not detect few coin’s which were occluded very heavily. Otherwise the program works well for all other cases.

The other inputs and outputs are portrayed below. The source code was written in C language and could be run on any C compiler after including the library tiffio.h. The files required are provided in this website. After this the project report is also included which gives the details of the techniques used to detect and classify the coins.



coins2.tif



coins3.tif



coins4.tif


PROBLEM STATEMENT

The problem is to classify US-coins in an image. This will be done using an image of coins produced by a scanner. To complicate the problem we want to detect coins partially occluded.


GENERAL APPROACH

To get an image with fixed and known sizes of the coins we use a scanner to produce an image with 225dpi. The program reads this image. After a Canny edge detection algorithm is applied the program performs a Hough transform. Then the values in the Hough space being below a threshold will be deleted and the remaining values in the Hough space will be connected if they lie near to each other. Thus these connected values are assigned to one coin. The connected components are counted to get the value of the detected coins.


PROGRAM

The program uses input images in TIFF-format. These are read using the functions provided by the library libtiff.lib. At the start of the program the user is prompted to input the file name of the input image. This is to be done without “.tif”.

After reading the input image the algorithm starts with a Canny edge detection function. First in this function a Gaussian mask is applied to the input image. To speed up this calculation we separated the Gaussian mask into its horizontal and vertical components. These components are applied to the image in succession and the result is stored in a temporary image. Then magnitude and direction of the edges are computed using the Roberts operator. The result is stored in an array containing variables for the magnitude and direction. The direction is coded using two variables one for the row (.dr) and one for the column (.dc). Both variables may be set to –1, 0 or 1. Thus 8 different directions can be coded. Next the magnitude image is scaled to values from 0 to 255. To suppress non-maximum values the magnitude values are compared with the values in the direction of the edge calculated before. The current value will be set to 0, if a larger or equal value is found. The result is stored in a temporary image. Edges are detected using two threshold values (100 and 40). If a pixel has a value larger than the higher threshold then the corresponding pixel in the output image is set to 255. The neighbors of such a pixel are set to 255, if their value is larger than the lower threshold. The output of the Canny edge detection function is an edge image and will be used for the following computations.

The next step is a Hough transformation. We are using a 3D array for the Hough space. Two dimensions are for the rows and columns coordinates of the center of the circles. The third coordinate is for the diameters. Because of having 4 different diameters the respective dimension has 4 values. Thus our Hough space has a size of rows x columns x 4. The algorithm scans the image. For every edge pixel in the image a circle is drawn in the Hough space for every diameter value. Then a threshold is applied to the Hough space. The values less or equal to the threshold value are set to 0, all the other pixels remain untouched.

Now there are some groups of values larger than 0 in the Hough space. Each group stands for a possible coin in the original image. To determine which pixels belong together we use the function regions_connect. In this function a square is placed over each value larger than 0 in a second Hough space. Thus we get connected regions.

Using a recursive labeling algorithm the program labels each region and computes the centroid of these regions. Besides it calculates the sum of the values belonging to this region. This sum is placed at the centroid in the original Hough space and all the other values in this region are set to 0. Thus the values in the Hough space are concentrated to the centroids of the regions.

Next the concentrated values of the centroids in each diameter layer are compared to the values lying in a quadratic region around these centroids in the other layers. All values but the largest are set to 0. Thus we suppress possible coins that would be lying over each another. The coins with the highest possibility will remain in the Hough space.

The final step is to count the coins and generate an output image. For every value not equal to 0 a coin is detected and a value depending of the diameter layer in which this value lies is added to the overall sum. In the function generate_output_image the output image is generated. Thus the input image is copied to the output image. Then for every value in the Hough space not equal to 0 a number is written to the centroid of the respective region. This number represents the value of the detected coin. In the main program the output image is written to the output file.


TESTING

We tested our program using different images.



Figure 1 : Input image "coins1.tiff"



Figure 2 : Output image belonging to "coins1.tiff"

In the output image can be seen that all coins were detected correctly. Even the two cents in the lower left corner are labeled with the correct value. Thus our program can deal with occlusion. It counted $1.42.



Figure 3 : Input image "coins2.tiff"



Figure 4 : Output image belonging to "coins2.tiff"

In the second image the program could not find the cent in the center occluded by two dimes and one cent. Furthermore during the scanning one cent slipped behind the right quarter. Thus it could not be detected ether. The problems in detecting these two cents become obvious in the output image of the Canny edge detector.





Figure 5 : Output image of the Canny edge detector for "coins2.tiff"

There is not enough of an arc at the positions of the two cents. Thus there are no pixels left in the Hough space after the thresholding. We could lower the threshold for the Hough space, but that would increase noise and nonexistent coins would be detected. The program finds $1.40.

The other two test images also show good results.



Figure 6 : Input image "coins3.tiff"



Figure 7 : Output image belonging to "coins3.tiff"

For input image "coins3.tif" the program detects all coins and counts $1.38.



Figure 8 : Input image "coins4.tiff"



Figure 9 : Output image belonging to "coins4.tiff"

The last image is very easy. Thus our program has no problem in finding all coins. The detected value is $0.56.


CONCLUSION

We developed a program to detect US-coins in a scanned image. It even works if some of the coins are occluded. However for too much occluded coins the algorithm has problems in finding them. The source code of the program follows to this paper.