Gimp的“Color to Alpha”颜色背后有什么算法?特征? [英] What algorithm is behind the Gimp's "Color to Alpha" feature?

查看:352
本文介绍了Gimp的“Color to Alpha”颜色背后有什么算法?特征?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于那些不熟悉Gimp的Color to Alpha功能的用户,下面是Gimp文档中的页面: Color to Alpha 。它做得非常好,我很想知道Gimp在颜色处理方面究竟做了些什么,无论颜色可能在哪个颜色空间中。感谢一堆提示。



编辑1:根据与关键颜色的相似性(您在颜色到Alpha对话框中选择的颜色)生成像素的透明度信息,就像某些人在删除其答案之前所建议的那样出于某种原因,听起来像是一个很好的见解,但我认为它比这更复杂。假设我们估计单位范围从0.0到1.0的颜色相似性,并且我们获得了一个像素,其颜色例如为0.4,类似于白色的颜色(例如您将在颜色至Alpha对话框),因此像素获得0.6的Alpha值,那么如何改变像素的实际颜色以补偿在Alpha像素为0.6的白色背景下显示所得像素时亮度/光度/饱和度的松散?编辑2:实际上是更新:与第一个编辑相关的子问题已在如何更改像素的alpha而不更改结果颜色? 但它可能不是完整的故事,因为Gimp的Color to Alpha功能的来源并非如此简单,似乎基于特定的算法而不是一个公式。

解决方案

你需要想出一个比较颜色相似性的机制。有各种各样的颜色空间可以做到这一点。 RGB通常不是这类事情的最佳选择。但是你可以使用HSV,YCbCr或其他一些亮度/色度空间。通常在这些空间中的一个距离会给你比RGB中的欧几里德距离更好的答案。一旦你有距离,你可以用最大距离除以得到一个百分比。如果你想知道GIMP是如何实现的,你可以查看源代码。例如,这是一个最近的代码更改到该插件。


For those who aren't familiar with the Gimp's "Color to Alpha" feature yet, here is the page on it from the Gimp's documentation: Color to Alpha. It does a really good job, and I wonder much how exactly Gimp does it in terms of color manipulation, whichever color space the colors might be in. Thanks a bunch for any hints.

EDIT 1: Generating transparency information for a pixel based on its similarity to the key color (the one you select in the "Color to Alpha" dialog), like some folk suggested before removing his answer for some reason, would sound like a good insight, but I suppose it's more intricate than that. Let's assume we estimate color similarity in the unit range from 0.0 to 1.0 and we've got a pixel whose color is, for example, 0.4 similar to, say, the color of white (like you would have selected white in the "Color to Alpha" dialog) and therefore the pixel gets an alpha value of 0.6, then how would you alter the pixel's actual color to compensate the loose of brightness/luminosity/saturation when the resulting pixel is displayed against a white background with the alpha of 0.6?

EDIT 2: Actually an update: The sub-question related to the first edit has been answered in How to change the alpha of a pixel without changing the resulting color? but it's probably not the full story because what is going on in the Gimp's source for the "Color to Alpha" feature is not that simple and seems to be based on a specific algorithm rather than a formula.

解决方案

You need to come up with a mechanism for comparing the similarity of colors. There are a variety of color spaces in which you can do this. RGB is often not the best for this sort of thing. But you could use HSV, YCbCr, or some other luma/chroma space. Often a distance in one of those spaces will give you a better answer than a Euclidean distance in RGB. Once you have a distance, you could divide that by the maximum distance to get a percentage. That percentage would be the inverse of the alpha you want to use, as one possibility.

If you want to know how the GIMP does it, you can look at the source. For example, here's one recent code change to that plug-in.

这篇关于Gimp的“Color to Alpha”颜色背后有什么算法?特征?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆