0

Processing large amounts of product images shot on white backdrops is very time consuming and seems like the perfect job for an app/script, but I cannot see anything available that can do this.

If I were able to create a photoshop script it would (presuming a bunch of layers as smart objects)

  1. Create a rectangular selection around the object in the image using a simple luminance threshold value to determine what is object and what is backdrop.

  2. Scale and centre the image so that this bounding box fills the canvas, with a user definable amount of padding.

The image dimensions need to remain constant for all images (or at least the aspect ratio)

(I don't want to 'straighten' anything)

I've attempted to make a start at this with extend script, but I can't see any way to achieve step 1.

Is anyone aware of an existing app or script that can achieve this?

1 Answer 1

1

I'm not sure you need a script. How about recording an action like this:

  • Convert your image to a Smart Object if it isn't already.

  • Add a Threshold Adjustment Layer and choose your wanted threshold.

  • Use Image > Trim and probably set Based On to Top Left Pixel Color to crop the image to the object.

  • Delete the adjustment layer.

  • To scale the image to the wanted dimensions first use File > Automate > Fit Image where you enter the wanted dimensions minus the padding to scale the image proportionally to fit inside the wanted dimensions. Then use Image > Canvas Size with those same dimensions to extend the canvas to the wanted dimensions.

  • Use Image > Canvas Size with Relative checked to add padding to the image.

The image needs to be a Smart Object. Otherwise Trim would delete the cropped pixels, and the added padding would have to be a solid color.

If you want to do some manipulations to the "mask" before cropping it might be easier to Copy Merged, Paste and then work destructively on the pasted image which you of course delete in the end.

For example, you might have some stray pixels below the threshold which will ruin the crop. These can be eliminated by using Filter > Blur > Gaussian Blur before using Threshold or by shrinking the black area afterwards using Filter > Other > Maximum.

8
  • Thanks, this is a good start, but how is 'scale your image' step to be performed now that 'trim' has created a canvas with arbitrary dimensions. 'Canvas Size' will generate inconsistent padding, Image size with specific dimensions will stretch it.
    – Kez
    Feb 7, 2021 at 0:48
  • OK, added method to scale image to a certain size.
    – Wolff
    Feb 7, 2021 at 1:18
  • Ok thats close, I dont know how I missed 'Automate > Fit' before. But how to have everything in a single document as layers (as in my presumption in OP) ? This is important as the auto process Is imperfect and needs manual helping and comparison to other layers. If I batch this as PSD and then 'Load files into Stack', it rasterises the smart objects which is no good. If I instead add 'Duplicate Layer' to the action and target a new document, all the layers will have the same name, so I can't export them out without forgetting what their original names were. Have I missed anything?
    – Kez
    Feb 7, 2021 at 11:37
  • Can't you just record the action and apply it to multiple files using File > Automate > Batch? Or if it's not too many files, assign a function key to the action, open all the files and apply the action for each individual file. (Remember to backup your files!)
    – Wolff
    Feb 7, 2021 at 11:43
  • Yes I'm doing batch, thats what I was referring to when I say the resulting files are imperfect. Loading each file as new seperate document after the batch and adjusting and resaving adds up to about as much time as doing it all manually in the first place. Even if there could be a way to get the resulting files post batch, all into a new document as layers - smart objects intact -- then this would be then still an advantage. But it seems there's no way.
    – Kez
    Feb 7, 2021 at 12:20

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.