SlideShare une entreprise Scribd logo
1  sur  53
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

Contenu connexe

Tendances

Contrast limited adaptive histogram equalization
Contrast limited adaptive histogram equalizationContrast limited adaptive histogram equalization
Contrast limited adaptive histogram equalization
Er. Nancy
 
Lecture9 camera calibration
Lecture9 camera calibrationLecture9 camera calibration
Lecture9 camera calibration
zukun
 
Feature Extraction
Feature ExtractionFeature Extraction
Feature Extraction
skylian
 

Tendances (20)

Object Detection & Tracking
Object Detection & TrackingObject Detection & Tracking
Object Detection & Tracking
 
Object detection with Tensorflow Api
Object detection with Tensorflow ApiObject detection with Tensorflow Api
Object detection with Tensorflow Api
 
Contrast limited adaptive histogram equalization
Contrast limited adaptive histogram equalizationContrast limited adaptive histogram equalization
Contrast limited adaptive histogram equalization
 
Multiple object detection
Multiple object detectionMultiple object detection
Multiple object detection
 
Image Processing with OpenCV
Image Processing with OpenCVImage Processing with OpenCV
Image Processing with OpenCV
 
Depth estimation do we need to throw old things away
Depth estimation do we need to throw old things awayDepth estimation do we need to throw old things away
Depth estimation do we need to throw old things away
 
Python media library
Python media libraryPython media library
Python media library
 
Computer vision - edge detection
Computer vision - edge detectionComputer vision - edge detection
Computer vision - edge detection
 
Dilation and erosion
Dilation and erosionDilation and erosion
Dilation and erosion
 
Cs231n 2017 lecture9 CNN Architecture
Cs231n 2017 lecture9 CNN ArchitectureCs231n 2017 lecture9 CNN Architecture
Cs231n 2017 lecture9 CNN Architecture
 
Image segmentation
Image segmentationImage segmentation
Image segmentation
 
Introduction to Computer Vision using OpenCV
Introduction to Computer Vision using OpenCVIntroduction to Computer Vision using OpenCV
Introduction to Computer Vision using OpenCV
 
Lecture9 camera calibration
Lecture9 camera calibrationLecture9 camera calibration
Lecture9 camera calibration
 
Tutorial on Object Detection (Faster R-CNN)
Tutorial on Object Detection (Faster R-CNN)Tutorial on Object Detection (Faster R-CNN)
Tutorial on Object Detection (Faster R-CNN)
 
Optics ordering points to identify the clustering structure
Optics ordering points to identify the clustering structureOptics ordering points to identify the clustering structure
Optics ordering points to identify the clustering structure
 
Image Acquisition
Image AcquisitionImage Acquisition
Image Acquisition
 
TensorFlow Object Detection API
TensorFlow Object Detection APITensorFlow Object Detection API
TensorFlow Object Detection API
 
Feature Extraction
Feature ExtractionFeature Extraction
Feature Extraction
 
Computer Vision
Computer VisionComputer Vision
Computer Vision
 
Epipolar geometry
Epipolar geometryEpipolar geometry
Epipolar geometry
 

Similaire à 05 contours seg_matching

EE660_Report_YaxinLiu_8448347171
EE660_Report_YaxinLiu_8448347171EE660_Report_YaxinLiu_8448347171
EE660_Report_YaxinLiu_8448347171
Yaxin Liu
 
various methods for image segmentation
various methods for image segmentationvarious methods for image segmentation
various methods for image segmentation
Raveesh Methi
 
Kulum alin-11 jan2014
Kulum alin-11 jan2014Kulum alin-11 jan2014
Kulum alin-11 jan2014
rolly purnomo
 

Similaire à 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
 

Plus de ankit_ppt

Plus de 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
 

Dernier

VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Christo Ananth
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Dernier (20)

The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 

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

Notes de l'éditeur

  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.