# How to remove constant background from an image?

I'm not sure how to remove the paper background from this logo with v9.

This is really not the same as this question, but I think similar methods apply.

Not as classy as @belisarius', but:

i1 = Import@"https://i.sstatic.net/LKZfw.png"
ColorReplace[i1, RGBColor@PixelValue[i1, {2, 2}], .02]


Edit:

Perhaps it would be better would be to use Vitaliy's method, illustrated in this excellent answer. In this version, the image has a white background, not transparent (hence the difference in color, I suppose):

data = ImageData[i1];
Image[data /. {x_, y_, z_} /;
EuclideanDistance[{x, y, z}, data[[2, 2]]] < .3 -> {1, 1, 1}]


The value of .3 is taken from looking at a ListPlot of the EuclideanDistance values.

• Hehe ... It's not a "classyness" problem. I don't have v9 :) Commented Jan 21, 2013 at 11:53

i1 = Import@"https://i.sstatic.net/LKZfw.png"
i2 = Image[ImageData[
ImageMultiply[Binarize[ColorSeparate[i1, "HSB"][[1]]], i1]] /. {0., 0., 0.} -> {1, 1, 1}]


Edit

If you want a fully saturated image, you could do something like

pmax = Position[ImageData[ColorSeparate[i1, "HSB"][[2]]], 1.][[1]]
Image@Replace[#, Except[{1., 1., 1.}] -> Extract[#, pmax], {2}] &@ ImageData[i2]


• Nice answer (although kind of brevity is the soul of wit ;) ). @M.R if you eventually want to turn the white background (what the verb "remove" implies; at least to me) to transparent please read this contribution of Szabolcs implementing a reverse blend. stackoverflow.com/questions/8041703/… Commented Jan 21, 2013 at 7:37

In version 10 there is now a RemoveBackground function, with more options and parameters than you could dream of. Without any help, it will do this:

i1 = Import@"https://i.sstatic.net/LKZfw.png";
RemoveBackground[i1]


but with some encouragement, in the form of a hint about the background's colour, or some marker positions to indicate the background, it can do even better:

RemoveBackground[i1, {"Background",  {RGBColor[0.9, 0.9, .7], .1}}]