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

Fashion e-commerce AutoSelect Subject and Crop

Community Beginner ,
Mar 02, 2020 Mar 02, 2020

Copy link to clipboard

Copied

Hi friends,

I'm looking for a script that detects a subject and crops the image.

 

Workflow

I get thousands of RAW files with a wide framing. Same camera all over the shooting, same pixel dimensions. Models move and change pose.

I develop on C1 and export PSD files.

Work on the PSD files and export JPEG for the client.

 

Script

Detect Model's height and crop leaving a few pixels above the head and bellow the feet.

Model should be centered on the image.

Keep aspect ratio 2:3.

 

Input files

https://www.dropbox.com/sh/gbufidhfqic1f4b/AADlTLSsfwDxTDBL-RcQHAxxa?dl=0

 

Script.jpg

 

 

 

 

 

 

Thanks in advance!

TOPICS
Actions and scripting

Views

4.5K

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

correct answers 1 Correct answer

Community Beginner , Mar 20, 2020 Mar 20, 2020

Thanks all for your help!

After reading all the proposals I came out with an action. Please take a look at it and let me know your comments.

The action runs auto-select, expands the selection 35px, creates a filled temp layer, transforms and uses the trim command.

 

To keep the 3:2 proportion I considered the model's height:

Width = 0.667 × Height

Once the model's height is "mapped" by the autoselect command I just copy the selection, rotate 90° and contract the width to 66.7%.
Then trim transparent pi

...

Votes

Translate

Translate
Adobe
LEGEND ,
Mar 02, 2020 Mar 02, 2020

Copy link to clipboard

Copied

C1?

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 Beginner ,
Mar 02, 2020 Mar 02, 2020

Copy link to clipboard

Copied

Capture One

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 ,
Mar 02, 2020 Mar 02, 2020

Copy link to clipboard

Copied

If you are using Adobe Experience Manager for your ecommerce site - it has this capability baked in called "Smart Crop". It uses AI to detect subjects and auto crop to an aspect ratio.

Unfortunately I'm not sure Photoshop has an AI functionality that will take the subject into consideration.

Any action would crop based on physical parameters risking cutting the subject off.

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
LEGEND ,
Mar 02, 2020 Mar 02, 2020

Copy link to clipboard

Copied

Look at Select->Select Subject which is designed for this kind of use. I don't know if it is scriptable or requires Action Manager code.

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 ,
Mar 02, 2020 Mar 02, 2020

Copy link to clipboard

Copied

The issue with Select subject is the crop is made directly on the selection, not at an aspect ratio.

It gets you part of the way there, and you could expand the selection to give breathing room to the crop, but I'm stumped how to take the end selection and convert the crop from "Selection" to Aspect Ratio.

You lose the selection as soon as you attempt to convert.

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
LEGEND ,
Mar 02, 2020 Mar 02, 2020

Copy link to clipboard

Copied

Selection->Expand, Image->Crop, Image->Canvas Size

That's how I would do it. Crop works with the bounding box. Or delete above and below the selection and then set the canvas size.

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
Contributor ,
Mar 03, 2020 Mar 03, 2020

Copy link to clipboard

Copied

You could save the selection bounds to a variable and parse them to create a rectangular selection with the margin you want. Feel free to copy the function below. 

 

 

// Grab the selection
var bnds = app.activeDocument.selection.bounds;
var someMargin = 50; 
// Use selection as parameters. To avoid headache, use the values (so without UnitType)
makeSelection(bnds[0].value,bnds[1].value,bnds[2].value,bnds[3].value, someMargin);

function makeSelection(lft,top,rgt,btm, margin){
  var w = rgt - lft + margin*2;
  var h = btm - top + margin*2;
  var wM = (rgt+lft)/2;
  var hM = (btm+top)/2;

  // If landscape, update top&bottom, if portrait update lft&rgt
  var lft = (w<h) ? (wM - h/2) : lft;
  var top = (w<h) ? top : (hM - w/2);
  var rgt = (w<h) ? (wM + h/2) : rgt;
  var btm = (w<h) ? btm : (hM + w/2);

  lft -= margin;
  top -= margin;
  rgt += margin;
  btm += margin;

  // Triggers a new selection, note the array of arrays if you want to play around with it
  app.activeDocument.selection.select([[lft,top], [rgt,top], [rgt,btm], [lft,btm] ]);
}

 

 

 

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 ,
Aug 22, 2021 Aug 22, 2021

Copy link to clipboard

Copied

I programed a Photoshop Plug-in Script toe be recorded ins Actions to create  Aspect Ratio  selection and Paths the are retanglar or elliptial shape. It is in Crafting Action Package.  Its Dialog  is use recording the Action Step from menu File>Automate>Aspect Ratio Selection... looks like this and the seletion will be orianted lye the imags oriantation landscape or portrait to loose less image content.

Capture.jpg

JJMack

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 ,
Mar 02, 2020 Mar 02, 2020

Copy link to clipboard

Copied

The methods in the following topic thread can be easily modified for your task, it is almost the same:

 

Script help: Crop based on select subject

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 ,
Mar 08, 2020 Mar 08, 2020

Copy link to clipboard

Copied

I have adapted the action/helper scripts from the previously linked topic thread to crop to 2:3 aspect ratio. The action relies on three key functions:

 

1) Select menu > Subject

2) Helper script: Add Guides to Selection Bounds

3) Helper script: FitImageToGuides

 

atn.png

 

The action and helper scripts are all available for download here:

 

CropModelShots2to3.zip

 

Downloading and Installing Adobe Scripts

 

Mac OS Example:

/Applications/Adobe Photoshop CC 2018/Presets/Scripts

 

Win OS Example:

C:\Program Files\Adobe\Adobe Photoshop CC 2018\Presets\Scripts

 

Further information at the Adobe site:
Scripting

 

NOTE: If running, Adobe Photoshop must be quit and restarted for newly added scripts to become accessible.

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 ,
Mar 08, 2020 Mar 08, 2020

Copy link to clipboard

Copied

All provided scripts are excellent. I would personnaly use a simpler script (no coding) doing the following :

  1. Select a subject
  2. Enlarge the selection about 300 px (depend on the image) just to get further margins
  3. Duplicate the selection on a new layer (command+J)
  4. Mask the background
  5. Crop the image to transparent pixels
  6. Delete layer

Done

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 ,
Mar 08, 2020 Mar 08, 2020

Copy link to clipboard

Copied

didiermazier what am I missing in your post? How does this preserve the 2:3 aspect ratio in the cropped image, which is a key requirement of the OP? 

 

"Script
Detect Model's height and crop leaving a few pixels above the head and bellow the feet.
Model should be centered on the image.
Keep aspect ratio 2:3."

 

There is a reason for the scripting leveraged by the action in my previous post, my approach results in a 2:3 aspect ratio crop, with the model centred and a small amount of space above/below the subject. Just as the original posters images show:

 

2to3.jpg

 

 

 

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 ,
Mar 08, 2020 Mar 08, 2020

Copy link to clipboard

Copied

My bad!

In this case there is a much simpler way :

Use content aware scale (alt+shift+ctrl+c) and you are good to go

Capture d’écran 2020-03-08 à 16.20.15.png

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 ,
Mar 08, 2020 Mar 08, 2020

Copy link to clipboard

Copied

here is a video : crop

it is a little tricky with percentages and resolution but it works fast 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
Community Expert ,
Mar 08, 2020 Mar 08, 2020

Copy link to clipboard

Copied

Hi didiermazier I watched your video, however, I personally would not use or recommend that approach.

 

The content-aware scale method that you show took approx 52 seconds to run. It is all manual. Unless I am missing something, the image is destructively resampled.

 

The goal is to automate repetitive editing of 1000's of images.

 

My action/script based workflow takes around 8 seconds to run (on my computer, so YMMV faster or slower) and can be used in Batch/Image Processor/Image Processor Pro for unattended automation of many images. The result is a 2:3 crop without any resampling.

 

As the saying goes "to each their own".

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 ,
Mar 09, 2020 Mar 09, 2020

Copy link to clipboard

Copied

This video just show the base process.

Then of course you will record this as an action and apply to your 1000 pics as well with the batch processor.

The idea was just to find an alternative way using photoshop native features without coding.

But you are right the exec time is longer for each pic. Time to take a break for instance.

😉

It occures to me another stupid no coding solution :

If your computer is strong enough open these images with  Camera Rawthen select all of them and apply the 2:3 croping to all of them in just one step

Capture d’écran 2020-03-09 à 09.45.14.png

Then instead of opening them, just save and set up the new folder

Capture d’écran 2020-03-09 à 09.54.00.png

And you are done

 

 

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 ,
Mar 09, 2020 Mar 09, 2020

Copy link to clipboard

Copied

I swear this is my last post on this thread!

There is a definitively simpler way to achieve the 2:3 crop with PS native features

Here is a video showing the process (and action recording): CROP 2

  1. same selection + enlarge + place on a new layer + mask background + crop transparent
  2. But then crop only Up and Bottom, not Left and Right
  3. Then crop with crop tool set up to 2:3 and that's it
  4. Delete layer and save to a new destination folder

Easy to record, easy to batch process the 1000 pics

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
LEGEND ,
Mar 09, 2020 Mar 09, 2020

Copy link to clipboard

Copied

Video is unavailable.

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 ,
Mar 09, 2020 Mar 09, 2020

Copy link to clipboard

Copied

 

"I swear this is my last post on this thread!"

 

I don't want this to be your last post on this thread, please don't take my constructive criticism the wrong way either... There is a reason that I suggested the approach that I did.

 

Unfortunately the 2:3 ratio crop tool recorded in an action will record absolute pixel values and not the relative values entered into the toolbar:

 

crop-absolute-not-relative.png

 

I did try your second video, the action screenshot is above, so unless I misunderstood, the method resulted in uneven/incorrect crops... But they were 2:3 ratio! I tried Batch, Image Processor and Image Processor Pro all using the same action.

 

I'm with you, I wish that there was an easy way without scripting to do this using only native methods.

 

P.S. I missed your earlier ACR suggestion, and while a nice idea, each image is too variable – the subject is not in the same size/position each time and the result is inconsistent, even among the 5 sample images provided, let alone thousands.

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 ,
Mar 10, 2020 Mar 10, 2020

Copy link to clipboard

Copied

I swear I will never swear!

Your critism is welcome because it makes me go further. We all are here to find solutions. 

In fact when checking what I proposed I found evident problems that I did not take in count at first time :

  • Models are not all the same size.
  • Phototshop action recording set up selections and cropping to fixed positions (top, left…) and not center and ratio.

I will work on a better action using doc size and the align for the crop frame.

Again I am not competing. All solutions are good to take!

Best

Didier

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 ,
Mar 10, 2020 Mar 10, 2020

Copy link to clipboard

Copied

Exactly Didier!

 

When the only tool you have is a hammer, even a screw looks like a nail.

 

I too hope to learn something, there is a good reason for my action/helper script combo, but I could be missing something too. It would not be the first time that I have over thought something!

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 ,
Mar 10, 2020 Mar 10, 2020

Copy link to clipboard

Copied

Hey I think I finally found a way to get all pics same size and 2:3 what ever the model height is…

Once the Select/enlarge/crop is done  the  trick is setting image size for the height and then setting canvas width.

Here is the video : CROP 3

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 ,
Mar 10, 2020 Mar 10, 2020

Copy link to clipboard

Copied

Hi didiermazier - OK, that works as far as it goes, however, it is resampling the images as a hack work-around to get to the 2:3 aspect ratio.  Now if you can come up with a method that does not resample, then that would be something! This is why I relied on scripting where necessary.

 

maurom15189996 did not specify that the images should be resampled/resized, however, if that is acceptable then the job is done.

 

My action cropped without resampling/resizing, which is why I had to use helper scripts to do the things that Photoshop can't do with native tools and recorded steps.

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 ,
Mar 11, 2020 Mar 11, 2020

Copy link to clipboard

Copied

You are right and there is another issue with this lasr solution :

you have first to check max height of the smaller girl in order to find the propee measure for the resizing.

this is why I choose 3000 px to be sur that I would not alter the pics enlarging them.

relatîg to resampling you are facing two choices : resampling or get a variable margin up and down.

when you resample all models have the same height no matter mother nature… same size same margin.

and lasr since the pics are Jpeg I suppose their destination is Web. In this case 3000 px is way to much…

was interesting thread !

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