简体   繁体   English

iOS白点/白平衡调整示例/建议

[英]iOS White point/white balance adjustment examples/suggestions

I am trying to change the white point/white balance programmatically. 我试图以编程方式更改白点/白平衡。 This is what I want to accomplish: 这就是我想要完成的事情:
- Choose a (random) pixel from the image - 从图像中选择(随机)像素
- Get color of that pixel - 获取该像素的颜色
- Transform the image so that all pixels of that color will be transformed to white and all other colors shifted to match - 变换图像,使该颜色的所有像素都变换为白色,并移动所有其他颜色以匹配

I have accomplished the first two steps but the third step is not really working out. 我已经完成了前两个步骤,但第三步并没有真正解决。

At first I thought that, as per Apples documentation CIWhitePointAdjust should be the thing to accomplish exactly that but, although it does change the image it is not doing what I would like/expect it to do. 起初我认为,根据Apples的文档, CIWhitePointAdjust应该是完全可以完成的事情,但是,尽管它确实改变了图像,但它没有做我想要/希望它做的事情。

Then it seemed that CIColorMatrix should be something that would help me to shift the colors but I was (and still am) at a loss of what to input to it with those pesky vectors. 然后似乎CIColorMatrix应该能够帮助我改变颜色,但是我(现在仍然)却厌倦了用那些讨厌的向量输入它的东西。 I have tried almost everything (same RGB values on all vectors, corresponding values (R for R, etc.) on each vector, 1 - corresponding value, 1 + corresponding value, 1/corresponding value. RGB values and different (1 - x, 1 + x, 1 / x). 我已经尝试了几乎所有的东西(所有矢量上的相同RGB值,每个矢量上的相应值(R代表R等),1 - 对应值,1 +对应值,1 /对应值.RGB值和不同(1 - x) ,1 + x,1 / x)。

I have also come across CITemperatureAndTint that, as per Apples documentation should also help, but I have not yet figured out how to convert from RGB to temperature and tint. 我也遇到过CITemperatureAndTint ,根据Apples文档也应该有所帮助,但我还没有想出如何从RGB转换为温度和色调。 I have seen algorithms and formulas about converting from RGB to Temperatur, but nothing regarding tint. 我已经看到了关于从RGB转换到Temperatur的算法和公式,但没有关于色调的内容。 I will continue experimenting with this a little though. 我会继续尝试这一点。

Any help much appreciated! 任何帮助非常感谢!

After a lot of experimenting and mathematics I finally got my app to work almost the way I want. 经过大量的实验和数学,我终于让我的应用程序几乎按照我想要的方式工作。
If anyone else will find themselves facing a similar problem then here is what I did. 如果其他人发现自己面临类似的问题,那么这就是我所做的。
I ended up using CITemperatureAndTint filter supplying a color in Kelvins calculated from the selected pixels RGB value and user suppliable tint value. 我最终使用CITemperatureAndTint过滤器,根据选定的像素RGB值和用户可提供的色调值计算Kelvins中的颜色。
To get to Kelvins I: 去凯尔文斯我:
- firstly converted RGB to XYZ using the D65 illuminant (ie Daylight). - 首先使用D65光源(即日光)将RGB转换为XYZ。
- then converted from XYZ to Yxy. - 然后从XYZ转换为Yxy。 Both of these conversions were made using the algorithms found from EasyRGB . 这两次转换都是使用EasyRGB中的算法进行的
- I then calculated Kelvins from Yxy using the McCamry's formula I found in a paper here . -我然后使用McCamry公式我在一份文件中发现计算开尔文从Yxy表在这里

These steps got the image in the ballpark but not quite there, so I added a UISlider for the user to supply the tint value ranging from -100 to 100. 这些步骤得到了球场中的图像,但并不完全存在,所以我添加了一个UISlider供用户提供从-100到100的色调值。

With selecting a point that should be white and choosing values from the positive side of the tint scale (all the images I on my phone tend to be more yellow) an image can now be converted to (more) neutral colors. 通过选择应该是白色的点并从色调比例的正面选择值(我手机上的所有图像往往更黄),现在可以将图像转换为(更多)中性色。 Yey! Yey!

I supplyed the calculated temperature and user chosen tint as inputNeutral vector values. 我提供了计算温度和用户选择的色调作为inputNeutral矢量值。
6500 (D65 daylight) and 0 as inputTargetNeutral vector values to CITTemperatureAndTint filter. 6500( inputTargetNeutral )和0作为inputTargetNeutral向量值到CITTemperatureAndTint过滤器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM