CSSE463: Image Recognition Day 3
Announcements/reminders:
Lab 0 should have been turned in last night.
Tomorrow: Lab 1 (posted): on color images. Bring laptop.
Today:
Introduce Fruit Finder, due next Friday.
Lots of Helpful hints in Matlab.
Connected components and morphology
Next week: Edge features
Questions?
Assignment 1: Counting Fruit
How many apples? Bananas? Oranges?
Goals
Crash-course in using and applying Matlab
For this reason, I will direct you to some
useful functions, but will not give details of
all of them
Practice writing a conference-paper style
report
Could use style similar to ICME sunset paper
See posted rubric for expectations
Fruit-finding technique
Observe
What is a banana‟s “yellow” (numerically)?
Tomorrow in lab, we‟ll see techniques
Model
Can you differentiate between yellow and orange? Orange and
red? (Decisions)
Note: this isn‟t using a classifier yet; just our best guess at hand-
tuned boundaries
Classify pixels using your model
“Clean up” the results
Discuss today
Write up your results in a nice report
Region processing
Binary image analysis
Today, we‟ll only consider binary images
composed of foreground and background
regions
Example: apple and non-apple
Use find to create a mask of which pixels belong to
each
Demo
Functions in Matlab
Contents of foo.m:
function retVal = foo(x,y,…)
…
retVal = x+y;
Can return multiple values of any type:
[mask, count, threshold] = foo(img)
Matlab How-to
Lots of “Random” tidbits that I used in my
solution…
Neighborhoods
Do we consider diagonals or not?
4-neighborhood of pixel p:
Consists of pixels from the 4 primary compass
directions from p.
8-neighborhood of pixel p:
Adds 4 pixels from the 4 secondary compass
directions from p.
Connected Components
Goal: to label groups of connected pixels.
4-connectivity vs. 8-connectivity matters
Matlab help: search for connected
components, and use bwlabel function
Demo
Morphological operations
Morphology = form and structure (shape)
For binary images
Done via a structuring element (usually a
rectangle or circle)
Basic operations:
Dilation, erosion, closing, opening
Erosion
Shrinks a region
Removes all pixels on the boundary
Mathematical def
Matlab: imerode(bw, structureElt)
structureElt (for 8 neighborhood) found by:
= strel(„square‟, 3); % for erosion using
structureElt
3x3 neighborhood
structureElt (for 4 neighborhood) found by:
structureElt = strel([0 1 0; 1 1 1; 0 1 0]);
Dilation
Enlarges a region
Adds all background pixels adjacent to the
boundary of the foreground region.
Matlab: imdilate(bw, structureElt)
Closing and Opening
Closing (imclose)
Fills internal holes in a region
Eliminates inlets on the boundary
Dilate, then erode
Opening (imopen)
Removes small regions
Eliminates peninsulas on the boundary
erode, then dilate
To make dilation more aggressive,
Dilate n times, then erode n times.
Or, use a larger structuring element
Example: compare dilating twice using a 3x3 square with
dilating once using a 5x5 square.