Reputation: 23
I work with a design team and they want me to implement a photo filter in our iOS app. They've provided me with two files that look pretty much like this image, each with a different variety of colors.
I've been informed that apparently I should be able to open them in Photoshop, compare the differences in the colors, and then apply those differences to filter images in the app. Honestly, I've got no idea where to begin even. I've opened them in photoshop but am not sure what to look for. I know how to apply filters with CIFilter
, I just don't know what kind of filtering to apply.
Anyone out there at least able to point me in the right direction?
Upvotes: 2
Views: 1690
Reputation: 26395
What they've given you is a 3D Look-up table or LUT. You don't need to involve Photoshop at all in this process other than to examine the LUTs.
It looks like your LUTs are 25x25x40. Each square is 25x25 and there are 8x5=40 squares in your picture. (Actually there are 8x4 = 32 squares and partial squares above and below that. That's kind of weird.) Each 25x25 square has a constant blue value, and the red value varies with the x coordinate and the green varies with the y coordinate.
To use the LUT, you take your (r, g, b) value for each pixel in the input image and look up the new value in the LUT.
So if you have an (R, G, B) value of, say, (128, 52, 215) (assuming 8-bits per channel, so values between 0-255), then you'd need to scale those to be in the ranges of your LUT.
To do that, calculate:
Red: 128 / 255 = x / 25
Green: 52 / 255 = x / 25
Blue: 215 / 255 = x / 40
So you get:
Red = 13
Green = 5
Blue = 34
Now you use those as coordinates in the LUT. You need the square where blue is 34/40ths. That's tricky in your setup since it's not a single long row. Normally, you'd just multiply tile width by number of the tile you want to get the start pixel, but we can't do that here. I recommend reformatting your LUT to work in this way. If you did, you could just multiply 34 * 25 * sizeof(RGB). Once there, you can treat that tile as an image in itself, and look up (x,y) = (13,5). (Which you can do by using 5 * bytesPerRow + 13 * bytesPerPixel.)
You now have the color from the LUT.
There is a CoreImage filter called CIColorCube
that allows you to do something similar, but I've not used it myself.
Upvotes: 6