Skip to main content
AG_Ps_100
Inspiring
May 23, 2018
Question

Script to Straighten-and-crop to shapes

  • May 23, 2018
  • 1 reply
  • 1312 views

Hello everyone,

I edit carpet NEF files of carpets (adjust to the correct colors, remove the background, straighten the carpet, and add watermark)

I want to better automate my straightening of the carpet. I use Camera Raw's upright option but the features there work just sometimes:

since i get 7-9 pictures of each carpet from a photographer not every carpet is the same, let's say that angle from above of the carpet as a rectangle, i want to automate probably by a script the process of Straightening-and-cropping.

I saw like 5 scripts to auto crop but none of them served me well.

I would probably need a script that works inside photoshop (work on opened tabs and not on a folder) via a script or action. sometimes straightening the carpet requires Free Transform > Distort and sometimes Free Transform > Warp and sometimes even both.

example to distort:

Before:

take the top right corner and move it a bit right, and take the bottom right and move it a bit left:

After:

Example to Wrap Tool:

i wish i could define a shape like rectangle in this situation that the carpet will try to mimic and have the same structure, using both wrap and distort

does anyone can think of an idea where i can start?

This topic has been closed for replies.

1 reply

JJMack
Community Expert
Community Expert
May 23, 2018

If you know nothing about scripting Photoshop heir a programmer that does. Also work with the photographer to capture image that will work well with your automated process.

JJMack
AG_Ps_100
AG_Ps_100Author
Inspiring
May 25, 2018

i'm actually pretty decent at scripting, just stuck, i improved my process and got to this point where all that is left to do is the auto wrap around the canvas (rather than around a shape) which is an easier task!

the canvas is trimmed.

so the layer edges is exactly on the canvas as can be seen in the picture.

my problem is that the picture inside the layer is not straight

JJMack
Community Expert
Community Expert
May 25, 2018

feels like you've found a good idea.

so assuming we have a rectangle that doesn't need warp at all (needs only distort) like the following examples we can do something like choosing 4 points, run the script, it we'll do the rest.

I found a great tool called Perspective Warp, i feel like automating that tool somehow might also be my answer.


You wrote you were good at scripting. So you need to design a Photoshop Process that will locate those points.  That is the hard part how to automate locating those four points. Coding the script is the second part of it. The first is to design a process of Photoshop steps that can be automated to locate those points.

You may need to work with the photographer to include markers that can be selected easily.  Devise a way.  I would not expect Photoshop Select Subject to select the rug where covering the selection to a path would create a path with only four points. Or Selecting the white background and inverting the selection and convert to a path. The Path would be more like this,

Using the Selection bounds and the paths points you should be able to find some logic to identify the four points.  Use your knowledge about Photoshop operation.  Its a gray matter thing. Perhaps the change in direction between point  close to 90 degrees

Its your job...

JJMack