1 / 20

Programming Assignment 4

This programming assignment focuses on improving skills with linked-list manipulation and using templates. The objective is to recognize different coins from an image using the connected components algorithm.

hellsworth
Download Presentation

Programming Assignment 4

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming Assignment 4 CS 308

  2. Recognize Coins (Regions) original image thresholded image labeled image dollar nickel quarters pennies dime $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() • ComputeComponents should return the following: • the labeled image • the number of components • a list of regions • Modify BFS or DFS (not the recursive version). int ComputeComponents(inputImage, outputImage, listOfRegions)

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

  8. int computeComponents(inputImage, outputImage, listOfRegions) (client function) 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 // findComponentDFS(inputImage, outputImage, i, j, label, region); // findComponentBFS(inputImage, outputImage, i, j, label,region); // INSERT region ONTO THE LIST of THE REGIONS } return connComp;

  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: (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. • Compute 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 (i.e., size) q_avg q_std do_avg do_std

  16. Recognition Step • Extract the coins (regions) and compute their sizes • Recognize the coins • Print the total amount Recognition (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) use Image Gallery 2 (1) pennies (2) nickels (3) dimes (4) quarters (5) dollars (6) done with training

  19. recognize.cpp • Reads the table of features from the file. • Given 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 • Traverse the listOfRegions • Find the nodes corresponding to quarters • Traverse 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 original image create new image

More Related