How to remove overlapping red and green color regions, leaving only red ones?

enter image description here

  • $\begingroup$ ImageApply might be useful $\endgroup$
    – ssch
    Commented Oct 20, 2013 at 21:52

1 Answer 1


This removes the "overlapping" areas, assuming the green area doesn't have holes exactly where the red is, leaving the red areas only outside the green area:

img = Import["https://i.sstatic.net/hSBJW.png"]
{r, g, b, alpha} = ColorSeparate[img];
n = Image[0*ImageData[r]];
rnew = ImageMultiply[ColorNegate@Closing[Binarize[g], 4], r]
ColorCombine[{rnew, n, n}]

Mathematica graphics

This code simply removes the green:

rnew2 = ImageMultiply[ColorNegate@Binarize[g], r]
ColorCombine[{rnew2, n, n}]

Mathematica graphics


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.