I am trying to make some colors of the image transparent. Below are the images that I have.
Lets say that I want to remove the bold red color from the image and have it transparent. I am viewing my image as PDF, therefore the transparent color would be if the background would match with the pink on the side. I am using the code from Apple documentation which I slightly modified in the following way:
// inside 3rd loop
let hue = getHue(red: red, green: green, blue: blue)
let wantedHue = getHue(red: myPixel.redComponent, green: myPixel.greenComponent, blue: myPixel.blueComponent)
let isHueInRange = hue >= wantedHue - 0.1 && hue <= wantedHue + 0.1
let alpha:CGFloat = isHueInRange ? 0 : 1
Here is the result I get. As you can see, there is some color left and the background is not fully transparent. I made these modifications, because I need to be able to dynamically remove the background color of the image (my images won't have any humans or other complex objects in it. It will most likely be text and some rectangles. No color mixing. Just still colors.)
So what I do is finding the first pixel of the image and get its color. When I have the color I get its hue, but I manually set allowed range to be 0.2. I am assuming that the image won't contain any similar color to the one I have.
EDIT: The original color is: rgb(200, 39, 39) - hsv(200, 80.5, 78.4)
The residue color is: rgb(246, 215, 210) - hsv(352, 14.6, 96.5)
The image I have:
The image I get after applying the filter: