310 likes | 478 Views
CS 585 Computational Photography. Nathan Jacobs. Administrivia. project 1: due Tuesday before midnight. Overview. point processing morphological operations more useful Matlab functions. Point Processing.
E N D
CS 585 Computational Photography Nathan Jacobs
Administrivia • project 1: due Tuesday before midnight
Overview • point processing • morphological operations • more useful Matlab functions
Point Processing • The simplest kind of range transformations are these independent of position x,y: g(x,y) = h(f(x,y)) • Important: unlike convolution/correlation, no looping over nearby pixels • Important: every pixel for himself – spatial information completely lost! • can’t blur • can’t compute derivatives
Camera Block Diagram Szeliski
Image Histograms Which one is which? Cumulative Histograms
How do you do this in Matlab? • negative image • power-law transformation • contrast stretching • histogram equalization imOut = 1 - imIn imOut = interp1([0 .25 .75 1], [0 .1 .9 1], imIn, 'linear') imOut = histeq(imIn, hgram) (can also use histogram, cumulative histogram, and contrast stretching)
Limitations of Point Processing • Q: What happens if I reshuffle all pixels within the image? • A: It’s histogram won’t change. No point processing will be affected…
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 • Dilation : all shifts of B that have a non-empty overlap with A • Erosion : all shifts of B that are fully contained within 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 = ~~rgb2gray(im2double(imread('media/text.png'))); 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
Conclusion • point processing • morphological operations