I have the following image:

enter image description here

As you can see the background is kind of white-ish. Now my question is: How can I remove this transperancy of the background image ?

  • $\begingroup$ What do you mean by "transparency"? The image seems to have no alpha channel... $\endgroup$ – J. M.'s ennui Nov 13 '17 at 12:38
  • $\begingroup$ @J.M. I would like to make the image background as "sharp" as the foreground. Basically I mean by "transparency" the fact that the background looks like one took the original slide and increased the transparency, then placed the speaker in front. $\endgroup$ – james Nov 13 '17 at 12:46

If a pixel is part of the transparent slide on white color all channels will have a high value. The code below checks which pixels have a channel whose value is less than tol and extents the set with some radius. The complement set to the found pixels are assumed to be the background.

tol = 0.6;
radius = 1;

(*background pixel positions*)
pos = Complement[Tuples[Range /@ ImageDimensions[im][[{2, 1}]]],
   Union @@ Outer[Plus, Tuples[Range[-radius, radius], 2], Position[
      Clip[Map[Min, ImageData[im], {2}], {tol, tol}, {0, 1}], 0.], 1]];

The smallest channel value indicates how transparent the background is.

r = Min@Extract[ImageData[im], pos];

Cancel transparency:

Image[MapAt[(# - {r, r, r})/(1 - r) &, ImageData[im], pos]]

  • $\begingroup$ Awesome answer ! Thanks a lot ! :) $\endgroup$ – james Nov 13 '17 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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