Replace particular color of image in iOS

2019-02-17 22:05发布

I want to replace the particular color of an image with other user selected color. While replacing color of image, I want to maintain the gradient effect of that original color. for example see the attached images. image1.png
image2.png

I have tried to do so with CoreGraphics & I got success to replace color. But the replacing color do not maintain the gradient effect of the original color in the image.

Can someone help me on this? Is the CoreGraphics is right way to do this? Thanks in advance.

2条回答
做个烂人
2楼-- · 2019-02-17 22:35

After some struggling almost with the same problem (but with NSImage), made a category for replacing colors in NSImage which uses ColorCube CIFilter.

https://github.com/braginets/NSImage-replace-color

inspired by this code for UIImage (also uses CIColorCube): https://github.com/vhbit/ColorCubeSample

查看更多
做自己的国王
3楼-- · 2019-02-17 22:44

I do a lot of color transfer/blend/replacement/swapping between images in my projects and have found the following publications very useful, both by Erik Reinhard:

Unfortunately I can't post any source code (or images) right now because the results are being submitted to an upcoming conference, but I have implemented variations of the above algorithms with very pleasing results. I'm sure with some tweaks (and a bit of patience) you might be able to get what you're after!

EDIT:

Furthermore, the real challenge will lie in separating the different picture elements (e.g. isolating the wall). This is not unlike Photoshop's magic wand tool which obviously requires a lot of processing power and complex algorithms (and is still not perfect).

查看更多
登录 后发表回答