2

Let's say I have an image with a few colors. I would like to replace programmatically a specific existing color by a new one. (something simple, no need to support gradients, like I saw elsewhere).

E.g. I have an image showing a green circle and I want to display it as a red circle (every pixel initially defined with a given (R,G,B) is now displayed with a new (R,G,B).

Any idea of how to do that with the Apple ios SDK ? (or open source ...) And btw what would be the best image file format to make this easier (png, jpg ....) ?

Thanks !

Community
  • 1
  • 1
user1458153
  • 115
  • 1
  • 8

2 Answers2

0

You should be able to do this using Core Image filters. the Color Cube CI filter lets you map a source color range to destination colors. You should be able to define a source color range and map it to different colors.

That's one CI Filter I didn't figure out how to use however. If you do a search on "Color Cube" in the Xcode help system there is sample code that does a "chromakey" effect that knocks out green shades to transparent. You should be able to adapt that to your needs.

I have a project on Github called CIFilterTest that shows how to use Core Image filters to process images. It's written as a general-purpose system that lets you try a wide variety of filters that use a standard set of parameters (points, colors, 1 or 2 source images, and floating-point values.) I never did take the time to generate the 3D color mapping "cube" that the color cube filter needs as input, so it doesn't allow you to use that particular filter. You'll have to look at the color Cube sample code in the Xcode docs to generate inputs for the Color Cube filter, but my sample app should help a great deal with the basic setup for doing CI based image processing.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
  • thank you Duncan C, I dig into this and I'll report my results (may take some time since I'm not used to Image Processing ...) – user1458153 Jun 05 '15 at 21:36
  • See the link I just added to my answer for a sample project that should help you figure out how to use Core Image filters. – Duncan C Jun 06 '15 at 03:40
0

answered similar question here: Replace particular color of image in iOS in short: I would suggest using CoreImage filter.

Community
  • 1
  • 1
Eugene Braginets
  • 856
  • 6
  • 16