Apply filters to Channels via AM

Discussion of Photoshop Scripting, Photoshop Actions and Photoshop Automation in General

Moderators: Tom, Kukurykus

undavide

Apply filters to Channels via AM

Post by undavide »

Hello,
I was digging old code of mine where I have lots of channels filtering (blur, high-pass, etc).
What the old myself did was something along these lines:

Code: Select allfunction selectChannel(myChannel) {
    app.activeDocument.activeChannels = [app.activeDocument.channels.getByName(myChannel)];
    app.activeDocument.channels.getByName(myChannel).visible = false;
 }

var alpha1 = app.activeDocument.channels[0].duplicate();
alpha1.name = "first";
var alpha2 = app.activeDocument.channels[0].duplicate();
alpha2.name = "second";

selectChannel("first");
app.activeDocument.activeLayer.applyMedianNoise(5);

Basically, I did select channels (hiding them), then using activeLayer as a base for the filtering.
I wonder whether ActionManager code could be faster - I mean referencing the Channel there, as the target for the filter.
Straight AM for selecting, then applying is:

Code: Select allvar idslct = charIDToTypeID( "slct" );
    var desc486 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref251 = new ActionReference();
        var idChnl = charIDToTypeID( "Chnl" );
        ref251.putName( idChnl, "first" );
    desc486.putReference( idnull, ref251 );
executeAction( idslct, desc486, DialogModes.NO );

var idMdn = charIDToTypeID( "Mdn " );
    var desc487 = new ActionDescriptor();
    var idRds = charIDToTypeID( "Rds " );
    var idPxl = charIDToTypeID( "#Pxl" );
    desc487.putUnitDouble( idRds, idPxl, 5.000000 );
executeAction( idMdn, desc487, DialogModes.NO );

I've tried a merge, unsuccessfully (the code below applies the Median to the active layer, in my case to the composite, and not to the "first" channel as I'd like it to do):

Code: Select allvar idMdn = charIDToTypeID( "Mdn " );
    var desc486 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
        var ref251 = new ActionReference();
        var idChnl = charIDToTypeID( "Chnl" );
        ref251.putName( idChnl, "first" );
    desc486.putReference( idnull, ref251 );
        var idRds = charIDToTypeID( "Rds " );
        var idPxl = charIDToTypeID( "#Pxl" );
    desc486.putUnitDouble( idRds, idPxl, 5.000000 );
executeAction( idMdn, desc486, DialogModes.NO );

Thanks in advance for your help!
Davide
Mike Hale

Apply filters to Channels via AM

Post by Mike Hale »

You can not combine those two actions. The filter does not accept a target argument( no action reference ). When you combine them like you did the part that selects the channel is ignored and the filter is applied to whatever is active. One way to confirm that is try running it on a document that doesn't have a channel named 'first'. When they are two commands the part that selects the channel throws an error. When combined there isn't an error( because it never tries to select the non-existent channel ).

You will need to run as two separate commands.
undavide

Apply filters to Channels via AM

Post by undavide »

Thanks for the confirmation Mike, so the old myself apparently knew what he did.
Since I've to re-write part of the code now, I'm willing to optimize it for speed - not here (when I select the Channel, it does compute the Histogram too, am I right? which should slow down a bit the operation)

Davide
Mike Hale

Apply filters to Channels via AM

Post by Mike Hale »

The DOM channel object does have a histogram property so yes, if that property is the reason working with DOM layer object is slower than working with them using Action Manger then using Action Manager for channels would be faster.

But I can't recall writing a script where performance was an issue because it use the DOM for working with channels so I don't know if it would be worth rewriting something that works now to possibly save a few milliseconds.