I've done something like this as part of the answer linked here - may have time to adapt it for your question in a few minutes...
–
JensJul 2 '12 at 3:18

The simplest answer is DeleteBorderComponents - see my updated answer. Still, combining it with an alpha channel gives more flexibility, so I defined a new function deleteBorder for that purpose.
–
JensJul 2 '12 at 18:51

@Jens Interesting, since as far as I can tell DeleteBorderComponents claims to only work for binary images (and matrices.)
–
Brett ChampionJul 2 '12 at 19:35

Yes indeed - maybe it works for your image because of the black lines bounding the inside. Anyway, it does work for your case, but I think the deleteBorder function I defined is of much more general utility.
–
JensJul 2 '12 at 22:08

4 Answers
4

OK, I have an answer based on an alpha channel but it required more morphological manipulations first.

The good thing is that it should work for other shapes, and requires only the final product newimage. However, to make it work reliably, I needed to increase the image size to avoid some boundary lines bleeding into each other.

Now I combined my approaches from above (which relies on SelectComponents) with the border color selection from this earlier answer (using Binarize with a custom test function) to make a function deleteBorder that can remove a homogeneous border background from an arbitrary imageim:

deleteBorder replaces Black by a transparent region. This actually makes the black lines between the circles transparent too, and we can now still choose an arbitrary background color (Blue), or superimpose the result onto a different image.

You can use the image processing tools to do this. In short, you use FillingTransform to fill the inner parts and create a mask and then use ImageApply to set the pixels in the region given by mask to your desired colour.

The function ComponentMeasurements has the option "BorderComponents" which when set to False will ignore components that are connected to the border. You could use this to filter for the internal components only. For example

Mathematica is a registered trademark of Wolfram Research, Inc. While the mark is used herein with the limited permission of Wolfram Research, Stack Exchange and this site disclaim all affiliation therewith.