Homework 3 -- Matting

Intro

This program was written in Matlab. To run the program, simply run the script run.m. A file selector will pop up, simply choose the image you want to separate out the foreground and background from. Then, a second selector will pop up, simply choose the trimap image, which must be the same size as the image you are segmenting. The program will run for a while and produce an alpha matte with the segmentation, and finally a 3rd file selector will pop up. Select an image you want to compose with. The segmented foreground will be composed with the image you select.

Method

I implemented the paper "A Bayesian Approach to Digital Matting" by Chuang et al. The code is commented, and at the top are parameters that can be changed such as the max number of iterations per pixel (10), the FG/BG thresholds (5%), and the amount alpha must change per iteration (.0001). Alpha is initially set to be the average of the neighboring alpha values (unknown neighbors are .5).

Results

When the program runs, the image to segment is shown with each of its components (FG, BG, unknown) based on the trimap. Then after about 20 seconds (with max iterations 10), an alpha matte is displayed. Finally the composed image is displayed. Below are the images. A visual artifact I observe is the alpha matte has a very faint outline of the background (checkered pattern). This is faintly noticable in the composed image on the head of the bear and the lower right side. However, the hair of the bear seems to be captured pretty well, and looks good.

trimap segmentation bookshelf Computed alpha matte composite image

Go to Main Menu