SlideShare a Scribd company logo
Legal Notices and Disclaimers
This presentation is for informational purposes only. INTEL MAKES NO WARRANTIES,
EXPRESS OR IMPLIED, IN THIS SUMMARY.
Intel technologies’ features and benefits depend on system configuration and may require
enabled hardware, software or service activation. Performance varies depending on system
configuration. Check with your system manufacturer or retailer or learn more at intel.com.
This sample source code is released under the Intel Sample Source Code License
Agreement.
Intel and the Intel logo are trademarks of Intel Corporation in the U.S. and/or other countries.
*Other names and brands may be claimed as the property of others.
Copyright © 2018, Intel Corporation. All rights reserved.
2
Contours
A contour is an assembled collection of edges that (hopefully) represent one object in
the image.
• Can be used to automatically segment the different objects present in an image.
Preprocessing for cv2.findContours
Can use canny edges
• Images created by cvCanny
Can use thresholded image where edges are boundaries between white and black
• Images created by cvThreshold or cvAdaptiveThreshold
Call cv2.findContours on result of Canny or thresholding.
Contour Hierarchy
Parent – Child Hierarchy
0
1
2
3
4
0
1
2
3
4
Contour Hierarchy
cvContour can represent data as a contour tree.
0 and 2 are the contours represented at the root, or parent,
nodes.
Other contours are represented as children of 0 or 2.
0
1
2
3
4
cvFindContours
Input needs to be 8-bit binary image.
Make a copy of the image before using cvFindContours
• The original image will be written over by
cvFindContours
OpenCV represents the contour hierarchy as an array:
[next, previous, first_child, parent]
0
1
2
3
4
Method Variable: Arguments to Find Contours
Method clarifies how the contour is being computed.
CV_CHAIN_CODE
 Output = sequence of vertices (Freeman chain code)
CV_CHAIN_APPROX_NONE
 All chain code points = contour points
CV_CHAIN_APPROX_SIMPLE
 Endpoints of horizontal, vertical, diagonal segments
CV_CHAIN_APPROX_TC89_L1
 Teh_Chin chain algorithm
CV_LINK_RUNS
 Links horizontal segments of 1s
 Limited to CV_RETR_LIST
Mode Variable
Mode clarifies what contours should be found and desired format for return
value.
Finds contours and uses horizontal and vertical links to link the found
contours.
Mode options:
CV_RETR_EXTERNAL
CV_RETR_LIST
CV_ RETR_CCOMP
CV_RETR_TREE
CV_RETR_LIST
All contours are put into a list
This list does not have parent – child
relationships
Uses horizontal links
All contours are on same level (no actual
hierarchy)
0
1
2
3
4
CV_RETR_EXTERNAL
Extreme outer contours
0
1
CV_RETR_CCOMP
All contours are used to
generate a 2-level hierarchy
• Top-level hierarchy = external
• Bottom-level = internal
• Horizontal and vertical linkers
0 1
2 3
4
CV_RETR_TREE
All contours are used to generate a
full hierarchy
0
1
2
3
4
Drawing Contours
Lets look at a new image and draw contours with cv2.drawContours
Original Edges Edges used to compute
contours
Hull Borders
Compute a convex hull
cv2.convexHull()
Hull Borders
Compute convexity defects
cv2.convexityDefects
Checks contours to see if it is convex.
Length and Area
Length
• cv2.ContourPerimeter
Returns length of a contour
You can summarize length and area as a bounding structure
• Boxes
• Circles
• Ellipses
Bounding Boxes
cv2.BoundingRect()
• Returns rectangle that bounds the contour
• Red box in image
cv2.MinAreaRec2()
• Returns smallest rectangular bound
• Green box in image
Note green box is rotated for best fit
Circles and Ellipses
cv2.MinEnclosingCirlce()
• Similar to cv2.BoundingRect() in that it bounds the contour, but not a best fit
• Needs radius as input
• Red circle in image
cv2.FitEllipse2()
• Allows us to get a best fit bound
• Green circle image
Geometric Toolkits/Checks
cv2.maxRect()
• Two input rectangles are used to compute a new rectangle
cv2.BoxPoints()
• Computers corner points of cvBox2D structure
cv2.PointPolygonTest()
• Test: is point in polygon?
Contour Statistics
𝐴𝑠𝑝𝑒𝑐𝑡 𝑅𝑎𝑡𝑖𝑜𝑛 =
𝑊𝑖𝑑𝑡ℎ
𝐻𝑒𝑖𝑔ℎ𝑡
𝐸𝑥𝑡𝑒𝑛𝑡 =
𝑂𝑏𝑗𝑒𝑐𝑡 𝐴𝑟𝑒𝑎
𝐵𝑜𝑢𝑛𝑑𝑖𝑛𝑔 𝑅𝑒𝑐𝑡𝑎𝑛𝑔𝑙𝑒 𝐴𝑟𝑒𝑎
𝑆𝑜𝑙𝑖𝑑𝑖𝑡𝑦 =
𝐶𝑜𝑛𝑡𝑜𝑢𝑟 𝐴𝑟𝑒𝑎
𝐶𝑜𝑛𝑣𝑒𝑥 𝐻𝑢𝑙𝑙 𝐴𝑟𝑒𝑎
𝐸𝑞𝑢𝑖𝑣𝑎𝑙𝑒𝑛𝑡 𝐷𝑖𝑎𝑚𝑒𝑡𝑒𝑟 =
4 𝑥 𝐶𝑜𝑛𝑡𝑜𝑢𝑟 𝐴𝑟𝑒𝑎
𝜋
𝑂𝑟𝑖𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛 𝐴𝑛𝑔𝑙𝑒 = 𝑐𝑣2. 𝑓𝑖𝑡𝐸𝑙𝑙𝑖𝑝𝑠𝑒(𝑐𝑛𝑡)
𝑥, 𝑦, 𝑤, ℎ = 𝑐𝑣2. 𝑏𝑜𝑢𝑛𝑑𝑖𝑛𝑔𝑅𝑒𝑐𝑡(𝑐𝑜𝑛𝑡)
𝑎𝑟𝑒𝑎 = 𝑐𝑣2. 𝑐𝑜𝑛𝑡𝑜𝑢𝑟𝐴𝑟𝑒𝑎(𝑐𝑜𝑛𝑡)
ℎ𝑢𝑙𝑙 = 𝑐𝑣2. 𝑐𝑜𝑛𝑣𝑒𝑥𝐻𝑢𝑙𝑙(𝑐𝑜𝑛𝑡)
ℎ𝑢𝑙𝑙_𝑎𝑟𝑒𝑎 = 𝑐𝑣2. 𝑐𝑜𝑛𝑡𝑜𝑢𝑟𝐴𝑟𝑒𝑎(ℎ𝑢𝑙𝑙)
Finding Extreme Points: Min/Max
Min/Max is computed with NumPy.
Extreme points of the cross are min/max left/right and up/down.
Foreground/Background Separation
Separate foreground from background
Send foreground on for further analysis
• Cars in security camera
• Skin within an image (reduces complexity of finding faces)
Superpixels
• Groups of pixels in same object/type of object
Methods: Image Pyramids
Collection of images where each subsequent image is a downsampling of
the previous.
Gaussian pyramid
 Used to downsample
 Removes even rows and columns
 Will give you higher resolution
Laplacian pyramid
 Used to upsample
 Works with lower-resolution images and allows for faster computations
Gaussian Pyramid
Use cvPyrDown() with a 5x5 Guassian kernel
• Start with G0 (original image)
• Convolve G0 with Gaussian kernel
• Gi is ¼ size of G0 because we removed even-numbered rows and
columns from G0
• Repeat for all desired Gi+1
Laplacian Kernel
Use cvPyrUp()
Notice the relationship between Gausian and Laplacian
In OpenCV we see this as:
Lapi = Gausi – PyrUp(Gausi+1 )
Remember, we saw this in Week 3!
Methods to Segment an Image
cvPyrSegmentation ()
• Generates an image pyramid
• Associates pyramid layers to parent-child relationships
• Map pixels between Gi+1 and Gi
• Perform segmentation on lower-resolution images
• Note: Start image must be divisible by 2 for each layer of the pyramid
Mean Shift Clustering Over Color
pyrMeanShiftFiltering()
Peak of color-spatial distribution over space
Data dimensions are:
Spatial (x, y)
Color (blue, green, red)
Parameters are spatialRadius, colorRadius, max_level, and CvTermCriteria.
Watershed
Used to separate objects when you do not have a separate background image.
Input is a grayscale image or a smoothed color image.
Can cause oversegmentation or undersegmentation
• If you make too many basins or too few
Lines converted to peaks; uniform regions to catchment basins.
Watershed Method
Take the gradient of intensity image.
Marker points, or known areas of region of interest, are defined by user.
Basins get connected to marker points to create segments.
Watershed: Example
Step 1: Threshold a color image
Watershed: Example
Step 2: Remove noise with cv2.morphologyEx
Watershed: Example
Step 3: Sure background area with cv2.dilate()
Watershed: Example
Step 4: Find sure foreground area with cv2.distanceTransform() and cv2.threshold()
Watershed: Example
Step 5: Find unknown region with cv2.subtract()
Grabcut: Graph Cutting Techniques
Pixel-based energy function
Basic binary segmentation algorithm to identify object
Iteratively recalculates the region statistics (Gaussians) to perform segmentation
GrabCut Procedure
(1) Assign background and unknown
Unknown becomes potential foreground
(2) Create five probabilistic clusters (each) of foreground and background
(3) Assign every background pixel to a cluster of background
Do the same for foreground
(4) Compute cluster statistics for all clusters
GrabCut Procedure (continued)
(5) Create a graph where:
Pixels are linked to their neighbors and to two special nodes
 Nodes represent foreground and background
The weights of the links are related to neighbor similarity and class probability
GrabCut Procedure (continued)
(6) Apply a classic computer science graph theory algorithm min-cut to the
graph
The net result cuts the connections from each pixel to one of the two
special nodes.
In turn, this gives us a new assignment for foreground/background to the
pixels.
(7) Until convergence, we loop back to Step 4 and repeat
Classifications remain similar enough from one round to the next.
Contour Moments: Matching Contours
Compare statistical moments of contours:
In statistics, first moment is the mean, second moment is the variance, and so
on.
Moments are used to compare two contours (outlines) for similarity.
Another technique: Compute rough contour characteristic computed by
summation of all pixels over contour boundary:
p: x-order q: y-order
Normalized moments are better for comparing similar shapes of different sizes.
𝑚 𝑝,𝑞 =
𝑖=1
𝑛
𝐼 𝑥, 𝑦 𝑥 𝑝 𝑦 𝑞
Statistical Moments
In classical statistics, we use mean, variance, skew, and kurtosis.
cvMoments()
cvGetCentralMoment()
invariant with respect to translation
cvGetNormalizedMoment()
invariant with respect to scale
cvGetHuMoments()
invariant with respect to rotation
Normalized Moments
Central moments normalized with respect to a function intensity.
First need to calculate central moment:
Then you can calculate normalized moments:
𝜂 𝑝,𝑞 =
𝜇 𝑝,𝑞
𝑚00 𝑝 + 𝑞 /2 + 1
𝜇𝑝, 𝑞 =
𝑥,𝑦
𝐼 𝑥, 𝑦 𝑥 − 𝑥𝑎𝑣𝑔 𝑝 𝑦 − 𝑦𝑎𝑣𝑔 𝑞
Hu Invariant Moments
Linear combinations of centralized moments.
Use central moments to get invariant functions
• Invariant to scale, rotation, and reflection
cvGetHuMoments()
ℎ1 = 𝜂20 + 𝜂02
ℎ4 = (𝜂30+ 𝜂12)2 + (𝜂21 + 𝜂03)2
Template Matching Overview
Use cvMatchTemplate() to find one image within another.
Uses the actual image of matching object instead of a histogram
• This is called an image patch
Input image
• 8-bit, floating point plane, or color image
Output
• Single-channel byte or floating point image
Template Matching Methods
Squared difference
CV_TM_SQDIFF_NORMED
Correlation
CV_TM_CCORR_NORMED
Correlation coefficient
CV_TM_CCOEFF_NORMED
𝑅 𝑠𝑞𝑑𝑖𝑓𝑓 𝑥, 𝑦 =
𝑅 𝑠𝑞𝑑𝑖𝑓𝑓(𝑥, 𝑦)
𝑍(𝑥, 𝑦)
𝑅 𝑐𝑐𝑜𝑟𝑟 𝑥, 𝑦 =
𝑅 𝑐𝑐𝑜𝑟𝑟(𝑥, 𝑦)
𝑍(𝑥, 𝑦)
𝑅 𝑐𝑐𝑜𝑒𝑓𝑓 𝑥, 𝑦 =
𝑅 𝑐𝑐𝑜𝑒𝑓𝑓(𝑥, 𝑦)
𝑍(𝑥, 𝑦)
Histogram Backprojection
Uses a histogram model to match pixels (or patches of pixels) to approach object
recognition.
Histogram Backprojection
Better thought of as segmentation to foreground ROIs used for further
analysis.
If you have a histogram of the ROI, we can use that to find the object in
another image.
Use histogram from one image to match to histogram profile from another
image
Normalize to pixel number
Find matching object, or ROI
cvCalcBackProjectPatch()
Histogram Backprojection
Given a color, we want to know the probability of foreground/background.
Approximate probability that a particular color belongs to a particular object
You can also make a ratio histogram where you de-emphasize colors not in the ROI.
𝑝 𝑜𝑏𝑗𝑒𝑐𝑡 𝑐𝑜𝑙𝑜𝑟 =
𝑝 𝑐𝑜𝑙𝑜𝑟 𝑜𝑏𝑗𝑒𝑐𝑡 ∗ 𝑝(𝑜𝑏𝑗𝑒𝑐𝑡)
𝑝(𝑐𝑜𝑙𝑜𝑟)
~ 𝑝 𝑐𝑜𝑙𝑜𝑟 𝑜𝑏𝑗𝑒𝑐𝑡
Backprojection Method
1. Calculate ROI histogram
2. Normalize histogram
3. Apply cv2.calcBackProject
4. Convolve with circular disc
5. Duplicate threshold

More Related Content

What's hot

Clipping computer graphics
Clipping  computer graphicsClipping  computer graphics
Clipping computer graphics
ShaishavShah8
 
Sharpening using frequency Domain Filter
Sharpening using frequency Domain FilterSharpening using frequency Domain Filter
Sharpening using frequency Domain Filter
arulraj121
 
Chapter 9 morphological image processing
Chapter 9   morphological image processingChapter 9   morphological image processing
Chapter 9 morphological image processing
Ahmed Daoud
 
Image segmentation
Image segmentationImage segmentation
Image segmentation
Md Shabir Alam
 
Object detection technique using bounding box algorithm for
Object detection technique using bounding box algorithm forObject detection technique using bounding box algorithm for
Object detection technique using bounding box algorithm for
VESIT,Chembur,Mumbai
 
Active contour segmentation
Active contour segmentationActive contour segmentation
Active contour segmentation
Nishant Jain
 
Image Processing: Spatial filters
Image Processing: Spatial filtersImage Processing: Spatial filters
Image Processing: Spatial filters
A B Shinde
 
Clipping
ClippingClipping
Clipping
AMIT VIRAMGAMI
 
Image feature extraction
Image feature extractionImage feature extraction
Image feature extractionRushin Shah
 
Line Detection in Computer Vision
Line Detection in Computer VisionLine Detection in Computer Vision
Line Detection in Computer Vision
Parth Nandedkar
 
Lecture 2&3 Computer vision image formation ,filters&edge detection
Lecture 2&3 Computer vision image formation ,filters&edge detectionLecture 2&3 Computer vision image formation ,filters&edge detection
Lecture 2&3 Computer vision image formation ,filters&edge detection
cairo university
 
3D Display Method
3D Display Method3D Display Method
3D Display Method
Khaled Sany
 
Object tracking
Object trackingObject tracking
Object tracking
ahmadamin636
 
Understanding neural radiance fields
Understanding neural radiance fieldsUnderstanding neural radiance fields
Understanding neural radiance fields
Varun Bhaseen
 
Image compression
Image compressionImage compression
Image compression
Ale Johnsan
 
Digital Image Processing: Image Enhancement in the Frequency Domain
Digital Image Processing: Image Enhancement in the Frequency DomainDigital Image Processing: Image Enhancement in the Frequency Domain
Digital Image Processing: Image Enhancement in the Frequency Domain
Mostafa G. M. Mostafa
 
Image segmentation
Image segmentationImage segmentation
Image segmentationDeepak Kumar
 
Advance image processing
Advance image processingAdvance image processing
Advance image processing
AAKANKSHA JAIN
 
Edge detection of video using matlab code
Edge detection of video using matlab codeEdge detection of video using matlab code
Edge detection of video using matlab codeBhushan Deore
 
Matrix representation- CG.pptx
Matrix representation- CG.pptxMatrix representation- CG.pptx
Matrix representation- CG.pptx
RubaNagarajan
 

What's hot (20)

Clipping computer graphics
Clipping  computer graphicsClipping  computer graphics
Clipping computer graphics
 
Sharpening using frequency Domain Filter
Sharpening using frequency Domain FilterSharpening using frequency Domain Filter
Sharpening using frequency Domain Filter
 
Chapter 9 morphological image processing
Chapter 9   morphological image processingChapter 9   morphological image processing
Chapter 9 morphological image processing
 
Image segmentation
Image segmentationImage segmentation
Image segmentation
 
Object detection technique using bounding box algorithm for
Object detection technique using bounding box algorithm forObject detection technique using bounding box algorithm for
Object detection technique using bounding box algorithm for
 
Active contour segmentation
Active contour segmentationActive contour segmentation
Active contour segmentation
 
Image Processing: Spatial filters
Image Processing: Spatial filtersImage Processing: Spatial filters
Image Processing: Spatial filters
 
Clipping
ClippingClipping
Clipping
 
Image feature extraction
Image feature extractionImage feature extraction
Image feature extraction
 
Line Detection in Computer Vision
Line Detection in Computer VisionLine Detection in Computer Vision
Line Detection in Computer Vision
 
Lecture 2&3 Computer vision image formation ,filters&edge detection
Lecture 2&3 Computer vision image formation ,filters&edge detectionLecture 2&3 Computer vision image formation ,filters&edge detection
Lecture 2&3 Computer vision image formation ,filters&edge detection
 
3D Display Method
3D Display Method3D Display Method
3D Display Method
 
Object tracking
Object trackingObject tracking
Object tracking
 
Understanding neural radiance fields
Understanding neural radiance fieldsUnderstanding neural radiance fields
Understanding neural radiance fields
 
Image compression
Image compressionImage compression
Image compression
 
Digital Image Processing: Image Enhancement in the Frequency Domain
Digital Image Processing: Image Enhancement in the Frequency DomainDigital Image Processing: Image Enhancement in the Frequency Domain
Digital Image Processing: Image Enhancement in the Frequency Domain
 
Image segmentation
Image segmentationImage segmentation
Image segmentation
 
Advance image processing
Advance image processingAdvance image processing
Advance image processing
 
Edge detection of video using matlab code
Edge detection of video using matlab codeEdge detection of video using matlab code
Edge detection of video using matlab code
 
Matrix representation- CG.pptx
Matrix representation- CG.pptxMatrix representation- CG.pptx
Matrix representation- CG.pptx
 

Similar to 05 contours seg_matching

Efficient anomaly detection via matrix sketching
Efficient anomaly detection via matrix sketchingEfficient anomaly detection via matrix sketching
Efficient anomaly detection via matrix sketching
Hsing-chuan Hsieh
 
Module-3_SVM_Kernel_KNN.pptx
Module-3_SVM_Kernel_KNN.pptxModule-3_SVM_Kernel_KNN.pptx
Module-3_SVM_Kernel_KNN.pptx
VaishaliBagewadikar
 
3D Reconstruction from Multiple uncalibrated 2D Images of an Object
3D Reconstruction from Multiple uncalibrated 2D Images of an Object3D Reconstruction from Multiple uncalibrated 2D Images of an Object
3D Reconstruction from Multiple uncalibrated 2D Images of an Object
Ankur Tyagi
 
EE660_Report_YaxinLiu_8448347171
EE660_Report_YaxinLiu_8448347171EE660_Report_YaxinLiu_8448347171
EE660_Report_YaxinLiu_8448347171Yaxin Liu
 
Templateless Marked Element Recognition Using Computer Vision
Templateless Marked Element Recognition Using Computer VisionTemplateless Marked Element Recognition Using Computer Vision
Templateless Marked Element Recognition Using Computer Vision
shivam chaurasia
 
CS345-Algorithms-II-Lecture-1-CS345-2016.pdf
CS345-Algorithms-II-Lecture-1-CS345-2016.pdfCS345-Algorithms-II-Lecture-1-CS345-2016.pdf
CS345-Algorithms-II-Lecture-1-CS345-2016.pdf
OpenWorld6
 
various methods for image segmentation
various methods for image segmentationvarious methods for image segmentation
various methods for image segmentationRaveesh Methi
 
Support Vector Machines ( SVM )
Support Vector Machines ( SVM ) Support Vector Machines ( SVM )
Support Vector Machines ( SVM )
Mohammad Junaid Khan
 
svm-proyekt.pptx
svm-proyekt.pptxsvm-proyekt.pptx
svm-proyekt.pptx
ElinEliyev
 
06 image features
06 image features06 image features
06 image features
ankit_ppt
 
Parallel Computing 2007: Bring your own parallel application
Parallel Computing 2007: Bring your own parallel applicationParallel Computing 2007: Bring your own parallel application
Parallel Computing 2007: Bring your own parallel application
Geoffrey Fox
 
02 image processing
02 image processing02 image processing
02 image processing
ankit_ppt
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
Ankit Kumar
 
Structure and Motion - 3D Reconstruction of Cameras and Structure
Structure and Motion - 3D Reconstruction of Cameras and StructureStructure and Motion - 3D Reconstruction of Cameras and Structure
Structure and Motion - 3D Reconstruction of Cameras and Structure
Giovanni Murru
 
svm.pptx
svm.pptxsvm.pptx
Two marks with answers ME6501 CAD
Two marks with answers ME6501 CADTwo marks with answers ME6501 CAD
Two marks with answers ME6501 CAD
Priscilla CPG
 
426 Lecture5: AR Registration
426 Lecture5: AR Registration426 Lecture5: AR Registration
426 Lecture5: AR Registration
Mark Billinghurst
 
Kulum alin-11 jan2014
Kulum alin-11 jan2014Kulum alin-11 jan2014
Kulum alin-11 jan2014rolly purnomo
 
Variational Autoencoders For Image Generation
Variational Autoencoders For Image GenerationVariational Autoencoders For Image Generation
Variational Autoencoders For Image Generation
Jason Anderson
 

Similar to 05 contours seg_matching (20)

Efficient anomaly detection via matrix sketching
Efficient anomaly detection via matrix sketchingEfficient anomaly detection via matrix sketching
Efficient anomaly detection via matrix sketching
 
Module-3_SVM_Kernel_KNN.pptx
Module-3_SVM_Kernel_KNN.pptxModule-3_SVM_Kernel_KNN.pptx
Module-3_SVM_Kernel_KNN.pptx
 
3D Reconstruction from Multiple uncalibrated 2D Images of an Object
3D Reconstruction from Multiple uncalibrated 2D Images of an Object3D Reconstruction from Multiple uncalibrated 2D Images of an Object
3D Reconstruction from Multiple uncalibrated 2D Images of an Object
 
EE660_Report_YaxinLiu_8448347171
EE660_Report_YaxinLiu_8448347171EE660_Report_YaxinLiu_8448347171
EE660_Report_YaxinLiu_8448347171
 
Templateless Marked Element Recognition Using Computer Vision
Templateless Marked Element Recognition Using Computer VisionTemplateless Marked Element Recognition Using Computer Vision
Templateless Marked Element Recognition Using Computer Vision
 
CS345-Algorithms-II-Lecture-1-CS345-2016.pdf
CS345-Algorithms-II-Lecture-1-CS345-2016.pdfCS345-Algorithms-II-Lecture-1-CS345-2016.pdf
CS345-Algorithms-II-Lecture-1-CS345-2016.pdf
 
various methods for image segmentation
various methods for image segmentationvarious methods for image segmentation
various methods for image segmentation
 
Support Vector Machines ( SVM )
Support Vector Machines ( SVM ) Support Vector Machines ( SVM )
Support Vector Machines ( SVM )
 
svm-proyekt.pptx
svm-proyekt.pptxsvm-proyekt.pptx
svm-proyekt.pptx
 
06 image features
06 image features06 image features
06 image features
 
Parallel Computing 2007: Bring your own parallel application
Parallel Computing 2007: Bring your own parallel applicationParallel Computing 2007: Bring your own parallel application
Parallel Computing 2007: Bring your own parallel application
 
02 image processing
02 image processing02 image processing
02 image processing
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
Structure and Motion - 3D Reconstruction of Cameras and Structure
Structure and Motion - 3D Reconstruction of Cameras and StructureStructure and Motion - 3D Reconstruction of Cameras and Structure
Structure and Motion - 3D Reconstruction of Cameras and Structure
 
svm.pptx
svm.pptxsvm.pptx
svm.pptx
 
Two marks with answers ME6501 CAD
Two marks with answers ME6501 CADTwo marks with answers ME6501 CAD
Two marks with answers ME6501 CAD
 
Report
ReportReport
Report
 
426 Lecture5: AR Registration
426 Lecture5: AR Registration426 Lecture5: AR Registration
426 Lecture5: AR Registration
 
Kulum alin-11 jan2014
Kulum alin-11 jan2014Kulum alin-11 jan2014
Kulum alin-11 jan2014
 
Variational Autoencoders For Image Generation
Variational Autoencoders For Image GenerationVariational Autoencoders For Image Generation
Variational Autoencoders For Image Generation
 

More from ankit_ppt

Deep learning summary
Deep learning summaryDeep learning summary
Deep learning summary
ankit_ppt
 
08 neural networks
08 neural networks08 neural networks
08 neural networks
ankit_ppt
 
07 learning
07 learning07 learning
07 learning
ankit_ppt
 
04 image transformations_ii
04 image transformations_ii04 image transformations_ii
04 image transformations_ii
ankit_ppt
 
03 image transformations_i
03 image transformations_i03 image transformations_i
03 image transformations_i
ankit_ppt
 
01 foundations
01 foundations01 foundations
01 foundations
ankit_ppt
 
Word2 vec
Word2 vecWord2 vec
Word2 vec
ankit_ppt
 
Text similarity measures
Text similarity measuresText similarity measures
Text similarity measures
ankit_ppt
 
Text generation and_advanced_topics
Text generation and_advanced_topicsText generation and_advanced_topics
Text generation and_advanced_topics
ankit_ppt
 
Nlp toolkits and_preprocessing_techniques
Nlp toolkits and_preprocessing_techniquesNlp toolkits and_preprocessing_techniques
Nlp toolkits and_preprocessing_techniques
ankit_ppt
 
Matrix decomposition and_applications_to_nlp
Matrix decomposition and_applications_to_nlpMatrix decomposition and_applications_to_nlp
Matrix decomposition and_applications_to_nlp
ankit_ppt
 
Machine learning and_nlp
Machine learning and_nlpMachine learning and_nlp
Machine learning and_nlp
ankit_ppt
 
Latent dirichlet allocation_and_topic_modeling
Latent dirichlet allocation_and_topic_modelingLatent dirichlet allocation_and_topic_modeling
Latent dirichlet allocation_and_topic_modeling
ankit_ppt
 
Intro to nlp
Intro to nlpIntro to nlp
Intro to nlp
ankit_ppt
 
Ot regularization and_gradient_descent
Ot regularization and_gradient_descentOt regularization and_gradient_descent
Ot regularization and_gradient_descent
ankit_ppt
 
Ml10 dimensionality reduction-and_advanced_topics
Ml10 dimensionality reduction-and_advanced_topicsMl10 dimensionality reduction-and_advanced_topics
Ml10 dimensionality reduction-and_advanced_topics
ankit_ppt
 
Ml9 introduction to-unsupervised_learning_and_clustering_methods
Ml9 introduction to-unsupervised_learning_and_clustering_methodsMl9 introduction to-unsupervised_learning_and_clustering_methods
Ml9 introduction to-unsupervised_learning_and_clustering_methods
ankit_ppt
 
Ml8 boosting and-stacking
Ml8 boosting and-stackingMl8 boosting and-stacking
Ml8 boosting and-stacking
ankit_ppt
 
Ml7 bagging
Ml7 baggingMl7 bagging
Ml7 bagging
ankit_ppt
 
Ml6 decision trees
Ml6 decision treesMl6 decision trees
Ml6 decision trees
ankit_ppt
 

More from ankit_ppt (20)

Deep learning summary
Deep learning summaryDeep learning summary
Deep learning summary
 
08 neural networks
08 neural networks08 neural networks
08 neural networks
 
07 learning
07 learning07 learning
07 learning
 
04 image transformations_ii
04 image transformations_ii04 image transformations_ii
04 image transformations_ii
 
03 image transformations_i
03 image transformations_i03 image transformations_i
03 image transformations_i
 
01 foundations
01 foundations01 foundations
01 foundations
 
Word2 vec
Word2 vecWord2 vec
Word2 vec
 
Text similarity measures
Text similarity measuresText similarity measures
Text similarity measures
 
Text generation and_advanced_topics
Text generation and_advanced_topicsText generation and_advanced_topics
Text generation and_advanced_topics
 
Nlp toolkits and_preprocessing_techniques
Nlp toolkits and_preprocessing_techniquesNlp toolkits and_preprocessing_techniques
Nlp toolkits and_preprocessing_techniques
 
Matrix decomposition and_applications_to_nlp
Matrix decomposition and_applications_to_nlpMatrix decomposition and_applications_to_nlp
Matrix decomposition and_applications_to_nlp
 
Machine learning and_nlp
Machine learning and_nlpMachine learning and_nlp
Machine learning and_nlp
 
Latent dirichlet allocation_and_topic_modeling
Latent dirichlet allocation_and_topic_modelingLatent dirichlet allocation_and_topic_modeling
Latent dirichlet allocation_and_topic_modeling
 
Intro to nlp
Intro to nlpIntro to nlp
Intro to nlp
 
Ot regularization and_gradient_descent
Ot regularization and_gradient_descentOt regularization and_gradient_descent
Ot regularization and_gradient_descent
 
Ml10 dimensionality reduction-and_advanced_topics
Ml10 dimensionality reduction-and_advanced_topicsMl10 dimensionality reduction-and_advanced_topics
Ml10 dimensionality reduction-and_advanced_topics
 
Ml9 introduction to-unsupervised_learning_and_clustering_methods
Ml9 introduction to-unsupervised_learning_and_clustering_methodsMl9 introduction to-unsupervised_learning_and_clustering_methods
Ml9 introduction to-unsupervised_learning_and_clustering_methods
 
Ml8 boosting and-stacking
Ml8 boosting and-stackingMl8 boosting and-stacking
Ml8 boosting and-stacking
 
Ml7 bagging
Ml7 baggingMl7 bagging
Ml7 bagging
 
Ml6 decision trees
Ml6 decision treesMl6 decision trees
Ml6 decision trees
 

Recently uploaded

COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
Kamal Acharya
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
Kamal Acharya
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
ankuprajapati0525
 
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
DuvanRamosGarzon1
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 

Recently uploaded (20)

COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
 
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 

05 contours seg_matching

  • 1.
  • 2. Legal Notices and Disclaimers This presentation is for informational purposes only. INTEL MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY. Intel technologies’ features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. Check with your system manufacturer or retailer or learn more at intel.com. This sample source code is released under the Intel Sample Source Code License Agreement. Intel and the Intel logo are trademarks of Intel Corporation in the U.S. and/or other countries. *Other names and brands may be claimed as the property of others. Copyright © 2018, Intel Corporation. All rights reserved. 2
  • 3.
  • 4. Contours A contour is an assembled collection of edges that (hopefully) represent one object in the image. • Can be used to automatically segment the different objects present in an image.
  • 5. Preprocessing for cv2.findContours Can use canny edges • Images created by cvCanny Can use thresholded image where edges are boundaries between white and black • Images created by cvThreshold or cvAdaptiveThreshold Call cv2.findContours on result of Canny or thresholding.
  • 6. Contour Hierarchy Parent – Child Hierarchy 0 1 2 3 4 0 1 2 3 4
  • 7. Contour Hierarchy cvContour can represent data as a contour tree. 0 and 2 are the contours represented at the root, or parent, nodes. Other contours are represented as children of 0 or 2. 0 1 2 3 4
  • 8. cvFindContours Input needs to be 8-bit binary image. Make a copy of the image before using cvFindContours • The original image will be written over by cvFindContours OpenCV represents the contour hierarchy as an array: [next, previous, first_child, parent] 0 1 2 3 4
  • 9. Method Variable: Arguments to Find Contours Method clarifies how the contour is being computed. CV_CHAIN_CODE  Output = sequence of vertices (Freeman chain code) CV_CHAIN_APPROX_NONE  All chain code points = contour points CV_CHAIN_APPROX_SIMPLE  Endpoints of horizontal, vertical, diagonal segments CV_CHAIN_APPROX_TC89_L1  Teh_Chin chain algorithm CV_LINK_RUNS  Links horizontal segments of 1s  Limited to CV_RETR_LIST
  • 10. Mode Variable Mode clarifies what contours should be found and desired format for return value. Finds contours and uses horizontal and vertical links to link the found contours. Mode options: CV_RETR_EXTERNAL CV_RETR_LIST CV_ RETR_CCOMP CV_RETR_TREE
  • 11. CV_RETR_LIST All contours are put into a list This list does not have parent – child relationships Uses horizontal links All contours are on same level (no actual hierarchy) 0 1 2 3 4
  • 13. CV_RETR_CCOMP All contours are used to generate a 2-level hierarchy • Top-level hierarchy = external • Bottom-level = internal • Horizontal and vertical linkers 0 1 2 3 4
  • 14. CV_RETR_TREE All contours are used to generate a full hierarchy 0 1 2 3 4
  • 15. Drawing Contours Lets look at a new image and draw contours with cv2.drawContours Original Edges Edges used to compute contours
  • 16. Hull Borders Compute a convex hull cv2.convexHull()
  • 17. Hull Borders Compute convexity defects cv2.convexityDefects Checks contours to see if it is convex.
  • 18. Length and Area Length • cv2.ContourPerimeter Returns length of a contour You can summarize length and area as a bounding structure • Boxes • Circles • Ellipses
  • 19. Bounding Boxes cv2.BoundingRect() • Returns rectangle that bounds the contour • Red box in image cv2.MinAreaRec2() • Returns smallest rectangular bound • Green box in image Note green box is rotated for best fit
  • 20. Circles and Ellipses cv2.MinEnclosingCirlce() • Similar to cv2.BoundingRect() in that it bounds the contour, but not a best fit • Needs radius as input • Red circle in image cv2.FitEllipse2() • Allows us to get a best fit bound • Green circle image
  • 21. Geometric Toolkits/Checks cv2.maxRect() • Two input rectangles are used to compute a new rectangle cv2.BoxPoints() • Computers corner points of cvBox2D structure cv2.PointPolygonTest() • Test: is point in polygon?
  • 22. Contour Statistics 𝐴𝑠𝑝𝑒𝑐𝑡 𝑅𝑎𝑡𝑖𝑜𝑛 = 𝑊𝑖𝑑𝑡ℎ 𝐻𝑒𝑖𝑔ℎ𝑡 𝐸𝑥𝑡𝑒𝑛𝑡 = 𝑂𝑏𝑗𝑒𝑐𝑡 𝐴𝑟𝑒𝑎 𝐵𝑜𝑢𝑛𝑑𝑖𝑛𝑔 𝑅𝑒𝑐𝑡𝑎𝑛𝑔𝑙𝑒 𝐴𝑟𝑒𝑎 𝑆𝑜𝑙𝑖𝑑𝑖𝑡𝑦 = 𝐶𝑜𝑛𝑡𝑜𝑢𝑟 𝐴𝑟𝑒𝑎 𝐶𝑜𝑛𝑣𝑒𝑥 𝐻𝑢𝑙𝑙 𝐴𝑟𝑒𝑎 𝐸𝑞𝑢𝑖𝑣𝑎𝑙𝑒𝑛𝑡 𝐷𝑖𝑎𝑚𝑒𝑡𝑒𝑟 = 4 𝑥 𝐶𝑜𝑛𝑡𝑜𝑢𝑟 𝐴𝑟𝑒𝑎 𝜋 𝑂𝑟𝑖𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛 𝐴𝑛𝑔𝑙𝑒 = 𝑐𝑣2. 𝑓𝑖𝑡𝐸𝑙𝑙𝑖𝑝𝑠𝑒(𝑐𝑛𝑡) 𝑥, 𝑦, 𝑤, ℎ = 𝑐𝑣2. 𝑏𝑜𝑢𝑛𝑑𝑖𝑛𝑔𝑅𝑒𝑐𝑡(𝑐𝑜𝑛𝑡) 𝑎𝑟𝑒𝑎 = 𝑐𝑣2. 𝑐𝑜𝑛𝑡𝑜𝑢𝑟𝐴𝑟𝑒𝑎(𝑐𝑜𝑛𝑡) ℎ𝑢𝑙𝑙 = 𝑐𝑣2. 𝑐𝑜𝑛𝑣𝑒𝑥𝐻𝑢𝑙𝑙(𝑐𝑜𝑛𝑡) ℎ𝑢𝑙𝑙_𝑎𝑟𝑒𝑎 = 𝑐𝑣2. 𝑐𝑜𝑛𝑡𝑜𝑢𝑟𝐴𝑟𝑒𝑎(ℎ𝑢𝑙𝑙)
  • 23. Finding Extreme Points: Min/Max Min/Max is computed with NumPy. Extreme points of the cross are min/max left/right and up/down.
  • 24.
  • 25. Foreground/Background Separation Separate foreground from background Send foreground on for further analysis • Cars in security camera • Skin within an image (reduces complexity of finding faces) Superpixels • Groups of pixels in same object/type of object
  • 26. Methods: Image Pyramids Collection of images where each subsequent image is a downsampling of the previous. Gaussian pyramid  Used to downsample  Removes even rows and columns  Will give you higher resolution Laplacian pyramid  Used to upsample  Works with lower-resolution images and allows for faster computations
  • 27. Gaussian Pyramid Use cvPyrDown() with a 5x5 Guassian kernel • Start with G0 (original image) • Convolve G0 with Gaussian kernel • Gi is ¼ size of G0 because we removed even-numbered rows and columns from G0 • Repeat for all desired Gi+1
  • 28. Laplacian Kernel Use cvPyrUp() Notice the relationship between Gausian and Laplacian In OpenCV we see this as: Lapi = Gausi – PyrUp(Gausi+1 ) Remember, we saw this in Week 3!
  • 29. Methods to Segment an Image cvPyrSegmentation () • Generates an image pyramid • Associates pyramid layers to parent-child relationships • Map pixels between Gi+1 and Gi • Perform segmentation on lower-resolution images • Note: Start image must be divisible by 2 for each layer of the pyramid
  • 30. Mean Shift Clustering Over Color pyrMeanShiftFiltering() Peak of color-spatial distribution over space Data dimensions are: Spatial (x, y) Color (blue, green, red) Parameters are spatialRadius, colorRadius, max_level, and CvTermCriteria.
  • 31. Watershed Used to separate objects when you do not have a separate background image. Input is a grayscale image or a smoothed color image. Can cause oversegmentation or undersegmentation • If you make too many basins or too few Lines converted to peaks; uniform regions to catchment basins.
  • 32. Watershed Method Take the gradient of intensity image. Marker points, or known areas of region of interest, are defined by user. Basins get connected to marker points to create segments.
  • 33. Watershed: Example Step 1: Threshold a color image
  • 34. Watershed: Example Step 2: Remove noise with cv2.morphologyEx
  • 35. Watershed: Example Step 3: Sure background area with cv2.dilate()
  • 36. Watershed: Example Step 4: Find sure foreground area with cv2.distanceTransform() and cv2.threshold()
  • 37. Watershed: Example Step 5: Find unknown region with cv2.subtract()
  • 38. Grabcut: Graph Cutting Techniques Pixel-based energy function Basic binary segmentation algorithm to identify object Iteratively recalculates the region statistics (Gaussians) to perform segmentation
  • 39. GrabCut Procedure (1) Assign background and unknown Unknown becomes potential foreground (2) Create five probabilistic clusters (each) of foreground and background (3) Assign every background pixel to a cluster of background Do the same for foreground (4) Compute cluster statistics for all clusters
  • 40. GrabCut Procedure (continued) (5) Create a graph where: Pixels are linked to their neighbors and to two special nodes  Nodes represent foreground and background The weights of the links are related to neighbor similarity and class probability
  • 41. GrabCut Procedure (continued) (6) Apply a classic computer science graph theory algorithm min-cut to the graph The net result cuts the connections from each pixel to one of the two special nodes. In turn, this gives us a new assignment for foreground/background to the pixels. (7) Until convergence, we loop back to Step 4 and repeat Classifications remain similar enough from one round to the next.
  • 42.
  • 43. Contour Moments: Matching Contours Compare statistical moments of contours: In statistics, first moment is the mean, second moment is the variance, and so on. Moments are used to compare two contours (outlines) for similarity. Another technique: Compute rough contour characteristic computed by summation of all pixels over contour boundary: p: x-order q: y-order Normalized moments are better for comparing similar shapes of different sizes. 𝑚 𝑝,𝑞 = 𝑖=1 𝑛 𝐼 𝑥, 𝑦 𝑥 𝑝 𝑦 𝑞
  • 44. Statistical Moments In classical statistics, we use mean, variance, skew, and kurtosis. cvMoments() cvGetCentralMoment() invariant with respect to translation cvGetNormalizedMoment() invariant with respect to scale cvGetHuMoments() invariant with respect to rotation
  • 45. Normalized Moments Central moments normalized with respect to a function intensity. First need to calculate central moment: Then you can calculate normalized moments: 𝜂 𝑝,𝑞 = 𝜇 𝑝,𝑞 𝑚00 𝑝 + 𝑞 /2 + 1 𝜇𝑝, 𝑞 = 𝑥,𝑦 𝐼 𝑥, 𝑦 𝑥 − 𝑥𝑎𝑣𝑔 𝑝 𝑦 − 𝑦𝑎𝑣𝑔 𝑞
  • 46. Hu Invariant Moments Linear combinations of centralized moments. Use central moments to get invariant functions • Invariant to scale, rotation, and reflection cvGetHuMoments() ℎ1 = 𝜂20 + 𝜂02 ℎ4 = (𝜂30+ 𝜂12)2 + (𝜂21 + 𝜂03)2
  • 47.
  • 48. Template Matching Overview Use cvMatchTemplate() to find one image within another. Uses the actual image of matching object instead of a histogram • This is called an image patch Input image • 8-bit, floating point plane, or color image Output • Single-channel byte or floating point image
  • 49. Template Matching Methods Squared difference CV_TM_SQDIFF_NORMED Correlation CV_TM_CCORR_NORMED Correlation coefficient CV_TM_CCOEFF_NORMED 𝑅 𝑠𝑞𝑑𝑖𝑓𝑓 𝑥, 𝑦 = 𝑅 𝑠𝑞𝑑𝑖𝑓𝑓(𝑥, 𝑦) 𝑍(𝑥, 𝑦) 𝑅 𝑐𝑐𝑜𝑟𝑟 𝑥, 𝑦 = 𝑅 𝑐𝑐𝑜𝑟𝑟(𝑥, 𝑦) 𝑍(𝑥, 𝑦) 𝑅 𝑐𝑐𝑜𝑒𝑓𝑓 𝑥, 𝑦 = 𝑅 𝑐𝑐𝑜𝑒𝑓𝑓(𝑥, 𝑦) 𝑍(𝑥, 𝑦)
  • 50. Histogram Backprojection Uses a histogram model to match pixels (or patches of pixels) to approach object recognition.
  • 51. Histogram Backprojection Better thought of as segmentation to foreground ROIs used for further analysis. If you have a histogram of the ROI, we can use that to find the object in another image. Use histogram from one image to match to histogram profile from another image Normalize to pixel number Find matching object, or ROI cvCalcBackProjectPatch()
  • 52. Histogram Backprojection Given a color, we want to know the probability of foreground/background. Approximate probability that a particular color belongs to a particular object You can also make a ratio histogram where you de-emphasize colors not in the ROI. 𝑝 𝑜𝑏𝑗𝑒𝑐𝑡 𝑐𝑜𝑙𝑜𝑟 = 𝑝 𝑐𝑜𝑙𝑜𝑟 𝑜𝑏𝑗𝑒𝑐𝑡 ∗ 𝑝(𝑜𝑏𝑗𝑒𝑐𝑡) 𝑝(𝑐𝑜𝑙𝑜𝑟) ~ 𝑝 𝑐𝑜𝑙𝑜𝑟 𝑜𝑏𝑗𝑒𝑐𝑡
  • 53. Backprojection Method 1. Calculate ROI histogram 2. Normalize histogram 3. Apply cv2.calcBackProject 4. Convolve with circular disc 5. Duplicate threshold

Editor's Notes

  1. Recall: White is the object and black is the background.
  2. Quick test for students: What would happen if there were a box around everything?
  3. We have only drawn the contour for the last lightning bolt.
  4. NOTE: Green points are the defects. Defects are points furthest from the outer contour. For example, the top-right green is furthest from the top-right red contour.
  5. Calculated using NumPy, not built-ins.
  6. Image url?
  7. Probabilistic clusters are components of a Gaussian mixture model. The class node probabilities can be set to 100% FG/BG, which guarantees the pixel keeping its association with that class after min-cutting.
  8. NOTE: Equality is from Bayes’ Theorem. Approximation is made by assuming p(o)/p(c) is a constant, which, if we normalize probabilities, can be dropped.