Replace particular color of image in iOS

混江龙づ霸主 提交于 2019-12-01 02:27:08

问题


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.

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.


回答1:


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




回答2:


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:

  • Color Transfer Between Images
  • Real-Time Color Blending of Rendered and Captured Video

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).



来源:https://stackoverflow.com/questions/14582121/replace-particular-color-of-image-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!