Search code examples
imagematlabimage-processingedge-detection

Background Extraction in MATLAB


I am working on a project in MATLAB which will extract background from an image, like if this is an image

Sample Image

it should give me locations/coordinates of background(blue part) or person's image, so far I have calculated

1) edges using canny

2) connected component

is there any detailed work, algorithm or paper on it ? so I can do it.

Edit

Problem I am facing is if I detect edges, it gives me binary image, so if I assume that all pixels who have value 0 (black color), is my background then how would I differentiate that I(r,c) is the part of person or part of background ?


Solution

  • Note that this is just one way to do it, but it should work.

    Assuming you can make a matrix with the following values:

    1 if it is (in the range of) your background color
    0 otherwise
    

    And assuming the background is only 'outside' the person (though it may still work if there is just a bit of hair around the background), then a simple way to check if something is the background would be to

    1. observe the neighborhood of each pixel in the matrix
    2. if the average value is high enough (say over 0.2) then assume it is a background pixel, otherwise assume it is a non-background pixel.
    3. Store the result in your new matrix and you have all the locations of background pixels

    So far it is quite straightforward and does not even use the fact that you already calculated the edges. Now with those edges you can make the following improvement:

    If a pixel is far enough 'inside' the edges (simpler: close enough to the center of them), do not consider it a candidate for background. This should help in case someone has big blue eyes.