Post on 22-Dec-2015
transcript
Recognize Coins (Regions)
labeled image
original image thresholded image
quartersnickel
penniesdime
dollar
$1.67
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
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
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).
listofRegions
,i ix y
cntr cntrN Nx y centroid:
sorted by size(from the smallestto the largest region)
int computeComponents(inputImage, outputImage, listOfRegions)
outputImage --> whiteconnComp=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, regionregion); // findComponentBFS(inputImage, outputImage, i, j, label, regionregion); // INSERT region ONTO THE LIST of THE REGIONS// INSERT region ONTO THE LIST of THE REGIONS }return connComp;
(client function)
findComponentDFS(inputImage, outputImage, i, j, label, region)
Stack.MakeEmpty();
Stack.Push((i,j)); // initialize stackwhile(!Stack.IsEmpty()) { Stack.Pop((pi,pj)); // INSERT (pi,pj) ONTO the PixelType LIST of the current region// 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// SET “size” and “centroid” for the current region }
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.
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.
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 Recognitionclass if you are interestedin this !
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
Training Step
• Process several instances of coins from each category.
• Compute the average size and standard deviation for each category (use Image Gallery 2Image Gallery 2)
1
1
_N
iNi
x avg x
211
1
_ ( _ )N
iNi
x std x x avg
Recognition Step
• Extract the coins (regions) and compute their sizes
• Recognize the coins
• Print the total amount Recognition
• 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
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 2use Image Gallery 2
recognize.cpp
• Reads the table of features from the file.• Given an input image (e.g., Image Gallery 1Image 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
Example: display the quarters only• Traverse the listOfRegionslistOfRegions
• Find the nodes corresponding to quarters
• Traverse the listOfPixelslistOfPixels for each quarter
• Draw the pixels of each pixel in a new image
• Copy the pixel values from the original gray-scale image
createnew image
original image