Shizam
Shizam

Reputation: 9672

How to apply an adjustment 'curve' to an image using an r,g,b,a matrix?

This will ultimately be used on the iPhone but its a general question that may be answerable in a language agnostic way

How would you apply an adjustment curve (like in Photoshop) to an image for saturation, contrast etc?

After looking over some c, java and actionscript libraries I figured out how to implement contrast, saturation, brightness adjustments linearly using a 5x5 matrix:

    1.0, 0.0, 0.0, 0.0, 0.0,
    0.0, 1.0, 0.0, 0.0, 0.0,
    0.0, 0.0, 1.0, 0.0, 0.0,
    0.0, 0.0, 0.0, 1.0, 0.0,
    0.0, 0.0, 0.0, 0.0, 1.0

Where I loop over each pixel and modify the r,g,b,a value of that pixel based on the above matrix but how would I translate a 5-point bezier curve from, say, a Photoshop curves interface to changing r,g,b,a for contrast, saturation etc. Looks like maybe something along the lines of :

valueWithCGAffineTransform

could be used?

EDIT: Upon further reflection the idea is, given a 5-point bezier curve on a 0-255 axis, how can you calculate the X value for any given Y value on the path? You can then use this information to transform r,g,b,a values for an image.

Upvotes: 4

Views: 502

Answers (1)

Shizam
Shizam

Reputation: 9672

And the answer is:

Bicubic spline interpolation

Turned out to have nothing to do w/matrices but bezier curves was close.

Upvotes: 3

Related Questions