iOS White point/white balance adjustment examples/suggestions
Asked Answered
H

1

4

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.

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

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. I have seen algorithms and formulas about converting from RGB to Temperatur, but nothing regarding tint. I will continue experimenting with this a little though.

Any help much appreciated!

Howardhowarth answered 10/4, 2013 at 12:15 Comment(4)
White point adjustments aren't something you can explain in some lines. I wrote a whole chapter in my Bachelor's thesis about this. Of course you might not need all the background info. I just tried CIWhitePointAdjust and I can't imagine what this would be used for. Can you tell what the exact use case would be in your application?Porkpie
I am trying to build a simple photo editor. I would like to pick a photo taken with the device in low-lit situation (for instance of a white plate of food in a restaurant) that has wrong colors (the white plate will usually be yellow) and transform the photo so that the plate will be white and other colors will be changed accordingly.Howardhowarth
I think you would need to look into chromatic adaptation. There's a bit of math needed but all formulas are available. www.brucelindbloom.com is your best friend here. As a fair warning: this is not trivial!Porkpie
Thanks, my reasearch has already gotten me this far. Already visited Bruce Lindblooms site and looked into the math.Howardhowarth
H
6

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.
To get to Kelvins I:
- firstly converted RGB to XYZ using the D65 illuminant (ie Daylight).
- then converted from XYZ to Yxy. Both of these conversions were made using the algorithms found from EasyRGB.
- I then calculated Kelvins from Yxy using the McCamry's formula I found in a paper here.

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.

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!

I supplyed the calculated temperature and user chosen tint as inputNeutral vector values.
6500 (D65 daylight) and 0 as inputTargetNeutral vector values to CITTemperatureAndTint filter.

Howardhowarth answered 12/4, 2013 at 13:11 Comment(2)
Hey, I'm trying to see if this will work for me, but your link to the Kelvin conversion is broken. It's a Google Doc that looks like it's no longer available. I also couldn't figure out from the Apple docs how to control the tint, as you describe. Would you be able to post some (or all) of your code?Neille
This DSP answer gives an abbreviated calculation that's pretty useful.Neille

© 2022 - 2024 — McMap. All rights reserved.