17

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

enter image description here

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

M.R.
  • 31,425
  • 8
  • 90
  • 281

3 Answers3

16

Not as classy as @belisarius', but:

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

logo

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}]

logo2

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

cormullion
  • 24,243
  • 4
  • 64
  • 133
15

It's actually easier than your linked question, since your ROI is monochromatic!

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

Mathematica graphics

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]

Mathematica graphics

Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
  • 1
    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. http://stackoverflow.com/questions/8041703/remove-white-background-from-an-image-and-make-it-transparent – Stefan Jan 21 '13 at 07:37
7

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.stack.imgur.com/LKZfw.png";
RemoveBackground[i1]

simple remove background

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}}]

better remove background

cormullion
  • 24,243
  • 4
  • 64
  • 133