Skip to main content
Inspiring
October 18, 2018
Question

Auto Populate Curve Adjustment

  • October 18, 2018
  • 1 reply
  • 1065 views

I am not even sure if this is possible but here goes...

Using a script, I want to read each patch from a step wedge and then plot the points on an adjustment curve

This topic has been closed for replies.

1 reply

Legend
October 18, 2018

Try this script. The active layer must be a normal layer.

app.preferences.rulerUnits = Units.PIXELS;

var len = activeDocument.width.value;

activeDocument.colorSamplers.removeAll();

activeDocument.colorSamplers.add([1,1]);

var lum = 0;

var p = new Array();

p.push([0,0]);

var n = 0;

for (var i = 0; i < len; i+=10)

    {

    activeDocument.colorSamplers[0].move([i,0]);

    var color = activeDocument.colorSamplers[0].color;

    var lm = Math.round(0.299*color.rgb.red + 0.587*color.rgb.green + 0.114*color.rgb.blue);

    if (lm != lum)

        {

        lum = lm;

        if (lum >= 255) break;

        p.push([lum,lum]);

        ++n;

        if (n >= 14) break;

        }                       

    }

p.push([255,255]);

activeDocument.colorSamplers.removeAll();

add_curves(p);

function add_curves(c)

    {

    try {

        var d = new ActionDescriptor();

        var list = new ActionList();

        function set_chnl(name, m)

            {

            if (m == undefined || m == null) return;

            var d = new ActionDescriptor();

            var r = new ActionReference();

            r.putEnumerated(stringIDToTypeID("channel"), stringIDToTypeID("channel"), stringIDToTypeID(name));

            d.putReference(stringIDToTypeID("channel"), r);

            var lst = new ActionList();

            for (var i = 0; i < m.length; i++)

                {

                if (m == undefined) continue;   

                var d1 = new ActionDescriptor();

                d1.putDouble(stringIDToTypeID("horizontal"), m[0]);

                d1.putDouble(stringIDToTypeID("vertical"),   m[1]);

                lst.putObject(stringIDToTypeID("point"), d1);

                }

            d.putList(stringIDToTypeID("curve"), lst);

            list.putObject(stringIDToTypeID("curvesAdjustment"), d);

            }

        set_chnl("composite", c);

        d.putList(stringIDToTypeID("adjustment"), list);

        

        add_adjustmen_layer("curves", d);

        }

    catch (e) { throw(e); }

    }

function add_adjustmen_layer(type, data)

    {

    try {

        var d = new ActionDescriptor();

        var r = new ActionReference();

        r.putClass(stringIDToTypeID("adjustmentLayer"));

        d.putReference(stringIDToTypeID("null"), r);

        var d1 = new ActionDescriptor();

        d1.putObject(stringIDToTypeID("type"), stringIDToTypeID(type), data);

        d.putObject(stringIDToTypeID("using"), stringIDToTypeID("adjustmentLayer"), d1);

        executeAction(stringIDToTypeID("make"), d, DialogModes.NO);

        }

    catch (e) { throw(e); }

    }

IanBarberAuthor
Inspiring
October 19, 2018

Thank you for taking the time to share the script which I find very interesting,

After experimenting with the script, I find that if the step wedge is not linear, it throws an error on line 97: executeAction(stringIDToTypeID("make"), d, DialogModes.NO);

The Non Linear step Wedge I was testing had these K values.

86%

85%

83%

80%

75%

71%

64%

52%

39%

18%

1%

Any thoughts please.

Legend
October 19, 2018

What color space is your document?

Replace line

if (lm != lum)

with

if (lm >= lum+4)