1Blending and Compositing15-463: Rendering and Image ProcessingAlexei EfrosTodayImage CompositingAlpha BlendingFeatheringPyramid BlendingGradient BlendingSeam FindingReading:Szeliski Tutorial, Section 6For specific algorithms:• Burt & Adelson• Ask me for further references2Blending the mosaicAn example of image compositing:the art (and sometime science) of combining images together…Image Compositing3Compositing Procedure1. Extract Sprites (e.g using Intelligent Scissors in Photoshop)Composite by David Dewey2. Blend them into the composite (in the right order)Just replacing pixels rarely worksProblems: boundries & transparency (shadows)Binary mask4Two Problems:Semi-transparent objectsPixels too largeSolution: alpha channelAdd one more channel:• Image(R,G,B,alpha)Encodes transparency (or pixel coverage):• Alpha = 1: opaque object (complete coverage)• Alpha = 0: transparent object (no coverage)• 0<Alpha<1: semi-transparent (partial coverage)Example: alpha = 0.3Partial coverage or semi-transparency5Alpha BlendingalphamaskIcomp= αIfg+ (1-α)IbgshadowMultiple Alpha BlendingSo far we assumed that one image (background) is opaque. If blending semi-transparent sprites (the “A over B” operation):Icomp= αaIa+ (1-αa)αbIbαcomp= αa+ (1-αa)αbNote: sometimes alpha is premultiplied: im(αR,αG,αB,α):Icomp= Ia+ (1-αa)Ib(same for alpha!)6Alpha Hacking…No physical interpretation, but it smoothes the seamsFeathering0101+=Encoding as transparencyIblend= αIleft+ (1-α)Iright7Setting alpha: simple averagingAlpha = .5 in overlap regionSetting alpha: center seamAlpha = logical(dtrans1>dtrans2)Distancetransform8Setting alpha: blurred seamAlpha = blurredDistancetransformSetting alpha: center weightingAlpha = dtrans1 / (dtrans1+dtrans2)DistancetransformGhost!9Affect of Window Size01leftright01Affect of Window Size010110Good Window Size01“Optimal” Window: smooth but not ghostedWhat is the Optimal Window?To avoid seams• window = size of largest prominent featureTo avoid ghosting• window <= 2*size of smallest prominent featureNatural to cast this in the Fourier domain• largest frequency <= 2*size of smallest frequency• image frequency content should occupy one “octave” (power of two)FFT11What if the Frequency Spread is WideIdea (Burt and Adelson)• Compute Fleft= FFT(Ileft), Fright= FFT(Iright)• Decompose Fourier image into octaves (bands)– Fleft= Fleft1+ Fleft2+ …• Feather corresponding octaves Fleftiwith Frighti– Can compute inverse FFT and feather in spatial domain• Sum feathered octave images in frequency domainBetter implemented in spatial domainFFTOctaves in the Spatial DomainBandpass ImagesLowpass Images12Pyramid Blending010101Left pyramid Right pyramidblendPyramid Blending13laplacianlevel4laplacianlevel2laplacianlevel0left pyramid right pyramid blended pyramidLaplacian Pyramid: BlendingGeneral Approach:1. Build Laplacian pyramids LA and LB from images A and B2. Build a Gaussian pyramid GR from selected region R3. Form a combined pyramid LS from LA and LB using nodes of GR as weights:• LS(i,j) = GR(I,j,)*LA(I,j) + (1-GR(I,j))*LB(I,j)4. Collapse the LS pyramid to get the final blended image14Blending RegionsSeason Blending (St. Petersburg)15Season Blending (St. Petersburg)Simplification: Two-band BlendingBrown & Lowe, 2003• Only use two bands: high freq. and low freq.• Blends low freq. smoothly• Blend high freq. with no smoothing: use binary alpha16Low frequency (λ > 2 pixels)High frequency (λ < 2 pixels)2-band BlendingLinear Blending172-band BlendingGradient DomainIn Pyramid Blending, we decomposed our image into 2ndderivatives (Laplacian) and a low-res imageLet us now look at 1stderivatives (gradients):• No need for low-res image – captures everything (up to a constant)• Idea: – Differentiate– Blend– Reintegrate18Gradient Domain blending (1D)TwosignalsRegularblendingBlendingderivativesbrightdarkGradient Domain Blending (2D)Trickier in 2D:• Take partial derivatives dx and dy (the gradient field)• Fidle around with them (smooth, blend, feather, etc)• Reintegrate– But now integral(dx) might not equal integral(dy)• Find the most agreeable solution– Equivalent to solving Poisson equation– Can use FFT, deconvolution, multigrid solvers, etc.19Perez et al., 2003Perez et al, 2003Limitations:• Can’t do contrast reversal (gray on black -> gray on white)• Colored backgrounds “bleed through”• Images need to be very well alignedediting20Mosaic results: Levin et al, 2004Don’t blend, CUT!So far we only tried to blend between two images. What about finding an optimal seam?Moving objects become ghosts21Davis, 1998Segment the mosaic• Single source image per segment• Avoid artifacts along boundries– Dijkstra’s algorithmInput textureB1 B2Random placement of blocks blockB1B2Neighboring blocksconstrained by overlapB1 B2Minimal errorboundary cutEfros & Freeman, 200122min. error boundaryMinimal error boundaryoverlapping blocks vertical boundary__==22overlap errorGraphcutsWhat if we want similar “cut-where-things-agree” idea, but for closed regions?• Dynamic programming can’t handle loops23Graph cuts (simple example à la Boykov&Jolly, ICCV’01)n-linkssta cuthard constrainthard constraintMinimum cost cut can be computed in polynomial time(max-flow/min-cut algorithms)Kwatra et al, 2003Actually, for this example, DP will work just as well…24Lazy Snapping (today’s speaker)Interactive segmentation using graphcutsPutting it all togetherCompositing images/mosaics• Have a clever blending function– Feathering– Center-weighted– blend different frequencies differently– Gradient based blending• Choose the right pixels from each image– Dynamic programming – optimal seams– Graph-cutsNow, let’s put it all together:• Interactive Digital Photomontage, 2004
View Full Document