0

I need to be able to auto select humans in a big number of images. I know their coordinates, width and height, but would ideally prefer to have a more humanoid selection, and it seems to work great via normal object selection via the interface. Now I am wondering if I can do it with Photoshop scripting? Any clues appreciated!

To clarify I'm talking about the Object Selection Tool introduced recently here.

Thanks everyone!

4
  • This will require tons of backend code and quite possibly a few machine learning/AI algorithms. Very difficult to do frontend, but not impossible. Your best luck is to search for some sort of API that does it for you and returns a result. Jan 7, 2021 at 4:02
  • ah I mean just to trigger the object selection tool? I already have the humans selected out, albeit in a rectangular bounding box. So I was wondering if I can just trigger the object selection tool using the same coordinates? Jan 7, 2021 at 4:50
  • Sorry, I'm not able to help with this one - I just don't have enough experience here. Jan 7, 2021 at 4:51
  • no problem! I still appreciate your comments. Thank you so much! Jan 7, 2021 at 4:52

1 Answer 1

0

I managed to get this working. In case anyone is interested:

Assuming the coordinates of the bounding box (top, left, bottom, right) are found.

var idset = stringIDToTypeID( "set" );
var desc4 = new ActionDescriptor();
var idnull = stringIDToTypeID( "null" );

var ref3 = new ActionReference();
var idchannel = stringIDToTypeID( "channel" );
var idselection = stringIDToTypeID( "selection" );
ref3.putProperty( idchannel, idselection );
desc4.putReference( idnull, ref3 );

var idto = stringIDToTypeID( "to" );
    var desc5 = new ActionDescriptor();
    var idtop = stringIDToTypeID( "top" );
    var idpixelsUnit = stringIDToTypeID( "pixelsUnit" );
    desc5.putUnitDouble( idtop, idpixelsUnit, top );
    var idleft = stringIDToTypeID( "left" );
    var idpixelsUnit = stringIDToTypeID( "pixelsUnit" );
    desc5.putUnitDouble( idleft, idpixelsUnit, left );
    var idbottom = stringIDToTypeID( "bottom" );
    var idpixelsUnit = stringIDToTypeID( "pixelsUnit" );
    desc5.putUnitDouble( idbottom, idpixelsUnit, bottom );
    var idright = stringIDToTypeID( "right" );
    var idpixelsUnit = stringIDToTypeID( "pixelsUnit" );
    desc5.putUnitDouble( idright, idpixelsUnit, right );
    
var idrectangle = stringIDToTypeID( "rectangle" );
desc4.putObject( idto, idrectangle, desc5 );
var iddeepSelect = stringIDToTypeID( "deepSelect" );
desc4.putBoolean( iddeepSelect, true );
var idobjectSelectionMode = stringIDToTypeID( "objectSelectionMode" );
desc4.putInteger( idobjectSelectionMode, 0 );
var idmagicLassoAutoEnhance = stringIDToTypeID( "magicLassoAutoEnhance" );
desc4.putBoolean( idmagicLassoAutoEnhance, true );
var idsmartSubtract = stringIDToTypeID( "smartSubtract" );
desc4.putBoolean( idsmartSubtract, true );
executeAction( idset, desc4, DialogModes.NO );

These codes can be obtained via the ScriptingListener (available here)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.