170 likes | 299 Views
CS 691 Computational Photography. Instructor: Gianfranco Doretto Morphological Operations. Morphological Operation. What if your images are binary masks? Binary image processing is a well-studied field, based on set theory, called Mathematical Morphology. Preliminaries. Preliminaries.
E N D
CS 691 Computational Photography Instructor: Gianfranco Doretto Morphological Operations
Morphological Operation • What if your images are binary masks? • Binary image processing is a well-studied field, based on set theory, called Mathematical Morphology
Dilation and Erosion • Two basic operations: • A is the image, B is the “structural element”, a mask akin to a kernel in convolution • Erosion : • all shifts of B such that B is fully contained within A • Dilation : • all shifts of B such that the center is contained by A =
Erosion Original image Eroded image
Erosion Eroded once Eroded twice
Opening and Closing • Opening : (erode, then dilate) • Closing : (dilate, then erode) • Prove to yourself that they are not the same thing. Play around with imdilate,imerodeand bwmorph in Matlab. • smoothes the contour of an object, breaks narrow isthmuses, and eliminates thin protrusions • smooth sections of contours but, as opposed to opening, it generally fuses narrow breaks and long thin gulfs, eliminates small holes, and fills gaps in the contour
Opening and Closing OPENING: The original image eroded twice and dilated twice (opened). Most noise is removed CLOSING: The original image dilated and then eroded. Most holes are filled.
Boundary Extraction Difference between image and erosion by a 3x3 mask of ones im = ~imread('http://petticoatsandpistols.com/wp-content/uploads/2009/02/silhouette11.bmp') imshow(xor(im, imerode(im, true(3))))
Connected Components im = imread('text.png'); imshow(im); cc = bwlabel(im); figure; imagesc(cc); regions = regionprops(im); [regions.Area];% show area of each conn. component
Some usefulMatlab functions • linspace: make linearly spaced samples • sub2ind, ind2sub: from 1D to ND indexing • bwdist: computes distance from positives in a binary image • regionprops: compute properties of connected components • find: find non-zeros, (can also find first k or find last k) • repmat: replicate a matrix • reshape: reshape a matrix • interp1: many types of interpolation • ndgrid: make array of indices of pixels • zeros, ones, rand, randn, blkdiag: matrix construction http://home.online.no/~pjacklam/matlab/doc/mtt/index.html
Slide Credits • This set of sides also contains contributions kindly made available by the following authors • Alexei Efros • Nathan Jacobs