• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

PS CS6: Auto Detect Edges of Object (Subject) + Add Padding to All Edges + Crop at Padding?

New Here ,
Apr 20, 2018 Apr 20, 2018

Copy link to clipboard

Copied

  • I have the CS6.
  • I have a series of images from a Canon camera which are 5,184 x 3,456 or 3,456 x 5,184.
  • Each image has a single object in the center on a black or gray background.
  • Objects range from antique plates wicker baskets to coins and electronics.
  • There is some variation in color of the background due to surface irregularities and minor shadows.

  • I am currently manually placing the crop frame on the outer left, top, right, and bottom pixel of the object.
  • After cropping I use a action to add a 100 pixel padding around all edges of the crop.
  • I then save the image as psd incase I want to redo the crop at a future date.
  • PSD files are saved into my archive.
  • A 3rd party app batch copies the original psd. The copies are created as jpegs, resized, have their resolution changed for web display, and are watermarked. The copies are saved by appending "-w" to the original file name.

  • The main bottleneck time wise is manually placing the crop frame.
  • Are there any plugins, scripts, or other solutions that would allow PS to: (a) automatically detect the outer edges of the center object and (b) crop the image 100 pixels from the edges of the object in all directs?

Views

808

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Apr 20, 2018 Apr 20, 2018

Copy link to clipboard

Copied

AFAIK, there is no script to detect an object - at least with CS6. What might work, and only if your bg is fairly consistent in color and tone, and you have good separation between your bg and subject is to create a script that uses the magic wand to select a corner of the image, outside of the subject. This should select the bg. Then invert the selection, and get the bounds of the selection. Once you do that, you can add your 100px and crop from that.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 20, 2018 Apr 20, 2018

Copy link to clipboard

Copied

You can try this:

#target photoshop

var doc = activeDocument;

sampleCorner ();

invertSel ();

var sBounds = doc.selection.bounds;

cropImg (sBounds[1]-100, sBounds[0]-100, sBounds[3]+100, sBounds[2]+100)

function sampleCorner(){

    var idsetd = charIDToTypeID( "setd" );

        var desc62 = new ActionDescriptor();

        var idnull = charIDToTypeID( "null" );

            var ref8 = new ActionReference();

            var idChnl = charIDToTypeID( "Chnl" );

            var idfsel = charIDToTypeID( "fsel" );

            ref8.putProperty( idChnl, idfsel );

        desc62.putReference( idnull, ref8 );

        var idT = charIDToTypeID( "T   " );

            var desc63 = new ActionDescriptor();

            var idHrzn = charIDToTypeID( "Hrzn" );

            var idPxl = charIDToTypeID( "#Pxl" );

            desc63.putUnitDouble( idHrzn, idPxl, 3.000000 );

            var idVrtc = charIDToTypeID( "Vrtc" );

            var idPxl = charIDToTypeID( "#Pxl" );

            desc63.putUnitDouble( idVrtc, idPxl, 3.000000 );

        var idPnt = charIDToTypeID( "Pnt " );

        desc62.putObject( idT, idPnt, desc63 );

        var idTlrn = charIDToTypeID( "Tlrn" );

        desc62.putInteger( idTlrn, 60 );

        var idAntA = charIDToTypeID( "AntA" );

        desc62.putBoolean( idAntA, true );

    executeAction( idsetd, desc62, DialogModes.NO );    

     }

function invertSel(){

     var idInvs = charIDToTypeID( "Invs" );

        executeAction( idInvs, undefined, DialogModes.NO );

     }

function cropImg(topS, leftS, bottomS, rightS){

     var idCrop = charIDToTypeID( "Crop" );

        var desc78 = new ActionDescriptor();

        var idT = charIDToTypeID( "T   " );

            var desc79 = new ActionDescriptor();

            var idTop = charIDToTypeID( "Top " );

            var idPxl = charIDToTypeID( "#Pxl" );

            desc79.putUnitDouble( idTop, idPxl, topS );

            var idLeft = charIDToTypeID( "Left" );

            var idPxl = charIDToTypeID( "#Pxl" );

            desc79.putUnitDouble( idLeft, idPxl, leftS );

            var idBtom = charIDToTypeID( "Btom" );

            var idPxl = charIDToTypeID( "#Pxl" );

            desc79.putUnitDouble( idBtom, idPxl, bottomS );

            var idRght = charIDToTypeID( "Rght" );

            var idPxl = charIDToTypeID( "#Pxl" );

            desc79.putUnitDouble( idRght, idPxl, rightS );

        var idRctn = charIDToTypeID( "Rctn" );

        desc78.putObject( idT, idRctn, desc79 );

        var idAngl = charIDToTypeID( "Angl" );

        var idAng = charIDToTypeID( "#Ang" );

        desc78.putUnitDouble( idAngl, idAng, 0.000000 );

        var idDlt = charIDToTypeID( "Dlt " );

        desc78.putBoolean( idDlt, false );

        var idcropAspectRatioModeKey = stringIDToTypeID( "cropAspectRatioModeKey" );

        var idcropAspectRatioModeClass = stringIDToTypeID( "cropAspectRatioModeClass" );

        var idpureAspectRatio = stringIDToTypeID( "pureAspectRatio" );

        desc78.putEnumerated( idcropAspectRatioModeKey, idcropAspectRatioModeClass, idpureAspectRatio );

        var idCnsP = charIDToTypeID( "CnsP" );

        desc78.putBoolean( idCnsP, false );

    executeAction( idCrop, desc78, DialogModes.NO );    

     }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 21, 2018 Apr 21, 2018

Copy link to clipboard

Copied

Thank you for the reply!

The script produces a small square of the background which may be due to my backgrounds. I tried a image of a object on a crude green screen (neon green poster board) to create a very high contract between the object and background but that resulted in a small green square after running the script

I previous created a App in Realbasic (Real Studio, Xojo) to do something similar several years ago. I had a series of small jpeg images of black text strings on a white background. I only wanted the images to big as the actual visible text and not include any white space around the edges. This program scanned each pixel in the image and kept track of the top most, bottom most, farthest left, and farthest right pixel that was not pure white. These four properties were then used as the crop marks.

Moving to a background other than a single rgb value is going to be a a lot more difficult as one would need to create a acceptable color range for the background color.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 22, 2018 Apr 22, 2018

Copy link to clipboard

Copied

LATEST

Yea, you need to have a pretty uniform bg for that script to work you could try upping the tolerance for the magic wand to 100, in line 29, but it's already at 60, which is pretty high.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines