颜色叠加算法
我正在寻找一种算法来在现有图片上叠加颜色。类似于以下应用程序(墙壁画家): http:// itunes.apple.com/us/app/wall-painter/id396799182?mt=8
我想要类似的功能,这样我就可以在现有图片中绘制墙壁并将其更改为不同的颜色。
我可以在 yuv 或 rgb 模式下工作。
I'm looking for an algorithm to overlay a color on top of existing picture. Something similar to the following app (wall painter): http://itunes.apple.com/us/app/wall-painter/id396799182?mt=8
I want a similar functionality so I can paint walls in an existing picture and change them to a different color.
I can work both in yuv or rgb mode.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要成功绘制图片中的墙壁,您必须执行两个步骤:
在图片中找到墙壁的边界(选择图像中要着色的部分)
将所需的颜色应用到所选区域
第一步是困难的部分。它类似于 Photoshop 的魔棒工具的作用。事实上,搜索魔杖算法会发现一些好文章,例如带有 Objective-C 代码的文章。
第二步要容易得多,可以使用 CGContextSetBlendMode 和 CGContextDrawImage 来实现。
To successfully paint the walls in a picture, you have to do two steps:
Find the boundary of the wall within the picture (select the part of the image to be colored)
Apply the desired color to the selected area
The first step is the hard part. It similar to what Photoshop's magic wand tool would do. And indeed a search for magic wand algorithm turns up a few good articles such as this article with Objective-C code.
The second step is much easier and can be achieve with
CGContextSetBlendMode
andCGContextDrawImage
.您可以尝试使用 kCGBlendModeColor 绘制到图形上下文中。从文档中:
尝试其他混合模式也可能有效。有关详细信息,请参阅文档(搜索“kCGBlendMode”)。
You could try drawing into a graphics context with
kCGBlendModeColor
. From the documentation:Experimenting with other blend modes might also do the trick. See the documentation for details (search for "kCGBlendMode").
RGB 和 YUV 颜色模型不太适合以这种方式改变颜色。我认为最好的颜色模型是 HLS。
链接:RGB 到 HLS 和 HLS 到 RGB转换源码
您可以在照片编辑应用程序中评估这三个组件的效果,例如GIMP 的 Photoshop。
The RGB and YUV color models are not really great for changing colors in this way. I think the best color model for this is HLS.
Link: RGB to HLS and HLS to RGB conversion source code
You can evaluate the effect of these three components in a photo editing app, like Photoshop of The GIMP.