I have a height map (a grayscale image, with black as the lowest and white as the highest areas), and I’m trying to isolate everything above or below a certain threshold. My goal is to be able to take any height map, and return a new UIImage where everything below a certain height (i.e. darker than a given color) is copied, but anything above (i.e. lighter) is simply transparent.
Now I’m very new to this, so if there’s a better way to go about this I’d love to hear it, but my first instinct is to create a new UIImage with the same frame, and then draw into it based on the lightness of a given area in the original. Something like…
threshold variable could be
0.2 or whatever, and then you could set
YES if you want everything higher (i.e. lighter) than the threshold, or
NO if you want everything lower (i.e. darker).
The thing is, I’ve never done image processing or drawing before, so I don’t know how to set up that method. I have a vague sense that it will involve
UIGraphicsBeginImageContext and such, but I haven’t been able to find any questions or tutorials that use it based on the lightness of another image.
How would I go about making a method like that? Or is there some pre-existing system for handling height maps in iOS, that makes this all a lot easier than I’m treating it?