Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming Assignment 4 CS 308. Recognize Coins (Regions) labeled image original imagethresholded image quarters nickel pennies dime dollar $1.67.

Similar presentations


Presentation on theme: "Programming Assignment 4 CS 308. Recognize Coins (Regions) labeled image original imagethresholded image quarters nickel pennies dime dollar $1.67."— Presentation transcript:

1 Programming Assignment 4 CS 308

2 Recognize Coins (Regions) labeled image original imagethresholded image quarters nickel pennies dime dollar $1.67

3 Project Objectives Improve your skills with manipulating linked-lists. Improve your skills with using templates. Learn about object recognition. Learn to document and describe your programs

4 How to choose a good threshold? a good threshold corresponds to the bottom of the valley

5 Extend Connected Components Algorithm Find the connected components in an image Assign a unique label to all the points in the same component. Store info about each component (region) in a linked-list

6 Modify computeComponents() int ComputeComponents(inputImage, outputImage, listOfRegions) ComputeComponents should return the following: –the labeled image –the number of components –a list of regions Modify BFS or DFS (not the recursive version).

7 listofRegions centroid: sorted by size (from the smallest to the largest region)

8 int computeComponents(inputImage, outputImage, listOfRegions) outputImage --> white connComp=0; for (i=0; i<N; i++) for(j=0; j<M; j++) if(inputImage[i][j] == 255 && outputImage[i][j]==255) { ++connComp; label = connComp; // new label // non-recursive functions region // findComponentDFS(inputImage, outputImage, i, j, label, region); region // findComponentBFS(inputImage, outputImage, i, j, label, region); // INSERT region ONTO THE LIST of THE REGIONS } return connComp; (client function)

9 findComponentDFS(inputImage, outputImage, i, j, label, region) Stack.MakeEmpty(); Stack.Push((i,j)); // initialize stack while(!Stack.IsEmpty()) { Stack.Pop((pi,pj)); // INSERT (pi,pj) ONTO the PixelType LIST of the current region outputImage[pi][pj] = label; for each neighbor (ni,nj) of (pi,pj) // push neighbors if(inputImage[ni][nj] == inputImage[pi][pj] && outputImage[ni][nj] == 255) { outputImage[ni][nj] = -1; // mark this pixel Stack.Push((ni,nj)); } // SET “size” and “centroid” for the current region }

10 void DeleteSmallComponents(listOfRegions, threshold) Eliminate small regions due to noise. Step through the list nodes and delete all the regions whose size is less than a threshold (e.g., 20-30 pixels). You do not have to visit all the nodes since the list will be sorted from the smallest to the largest region.

11 Object Recognition (1) Feature extraction/selection - e.g., size, perimeter, circularity - Reliable and robust feature extraction is very important (2) Training - Process sample images containing instances of the objects to be recognized - Collect evidence regarding the variation of the feature values per object class. - Derive rules for recognition based on the feature values. (3) Recognition - Extract regions (objects) and their features - Apply recognition rules.

12 An Example Recognize the characters a,b,c and d. Assume we have decided to use features f1, f2, f3. f1 f2 f3 Character 3 6 0 a -5 9 1 c 4 5 1 d 7 -4 -10 b 1 10 0 a 2 6 1 d 2 2 1 c -1 -3 -10 b Some rules: Some rules: (i) find closest match (ii) use individual features or combinations of features Take my Pattern Recognition class if you are interested in this !

13 Coin Recognition We will use the size of the coins for recognition. Enough information since the camera is assumed to be at a fixed position and orientation. Factors that might affect the size of the coins: –noise (yields holes in the regions) –distortions due to the imaging process

14 Training Step Process several instances of coins from each category. Image Gallery 2Compute the average size and standard deviation for each category (use Image Gallery 2)

15 Training Step(cont’d) p_avg p_std n_avg n_std di_avg di_std q_avg q_std do_avg do_std ( i.e., size)

16 Recognition Step Extract the coins (regions) and compute their sizes Recognize the coins Print the total amountRecognition Extract the coins (regions) and compute their sizes Recognize the coins Print the total amountRecognition (1) Find closet match (2) Accept match if error within some threshold (to avoid false positives) e.g., suppose closest match is for quarters: if |s-q_avg|<const*q_std accept else unknown coin $1.67

17 Recognition Step(cont’d)

18 train.cpp Creates the table of features. Prints the following menu. Stores the table in a file upon choosing option (6) (1) pennies (2) nickels (3) dimes (4) quarters (5) dollars (6) done with training use Image Gallery 2

19 recognize.cpp Reads the table of features from the file. Image Gallery 1Given an input image (e.g., Image Gallery 1) it extracts the regions and recognizes the coins. Assigns the ID value in the nodes of the listOfRegions. Prints the following menu: (1) display the pennies only (2) display the nickels only (3) display the dimes only (4) display the quarters only (5) display the dollars only (6) print the total amount (7) done with recognition

20 Example: display the quarters only listOfRegionsTraverse the listOfRegions Find the nodes corresponding to quarters listOfPixelsTraverse the listOfPixels for each quarter Draw the pixels of each pixel in a new image Copy the pixel values from the original gray-scale image create new image original image


Download ppt "Programming Assignment 4 CS 308. Recognize Coins (Regions) labeled image original imagethresholded image quarters nickel pennies dime dollar $1.67."

Similar presentations


Ads by Google