Download presentation
Presentation is loading. Please wait.
Published byPierce Crawford Modified over 9 years ago
1
Programming Assignment 4 CS 308 Fall 2001
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
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
5
Modify computeComponents() int ComputeComponents(inputImage, outputImage, listOfRegions) CompueComponents should return the following: –the labeled image –the number of components –a list of regions Modify BFS and DFS only (not the recursive version).
6
listofRegions centroid: sorted by size (from the smallest to the largest region)
7
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)
8
findComponentBFS(inputImage, outputImage, i, j, label, region) Queue.MakeEmpty(); Queue.Enqueue((i,j)); // initialize queue while(!Queue.IsEmpty()) { Queue.Dequeue((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 Queue.Enqueue((ni,nj)); } // SET “size” and “centroid” for the current region }
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 selection/extraction - 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 feature 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 3Compute the average size and standard deviation for each category (use Image Gallery 3)
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 size
16
Recognition Step Extract the coins (regions) and compute their sizes Recognize the coins Print the total amount if |s-p_avg| penny else if |s-n_avg| nickel else if |s-di_avg| dime else if |s-q_avg| quarter else if |s-do_avg| dollar else unknown Rules (example) $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 3
19
recognize.cpp Reads the table of features from the file. Image Gallery 2Given an input image (use Image Gallery 2) 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 new image
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.