I have the following image:
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 ?
I have the following image:
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 ?
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]]