Copy link to clipboard
Copied
Cropping a lot of images one by one. Need your help to speed up the process.
Final image should be :
Aspect ratio 3:4.
Keep the background color.(might change...but mostly in the 240-255 values)
Center the subject.
Crop above the nose.
Any help is appreciated !
#target photoshop
var lr = new AM('layer'),
doc = new AM('document');
lr.copyCurentToLayer()
lr.liquify()
lr.fade('difference')
lr.levels([0, 0.2, 8])
lr.makeSelectionFromChannel('blue')
if (doc.hasProperty('selection')) {
var selectionBounds = doc.descToO
...
Copy link to clipboard
Copied
var mesh= String.fromCharCode(0, 0, 0, 16, 0, 0, 0, 1, 0, 0, 0, 0, 0, 8, 102, 97, 99, 101, 77, 101, 115, 104, 0, 0, 0, 3, 0, 0, 0, 21, 102, 97, 99, 101, 68, 101, 115, 99, 114, 105, 112, 116, 111, 114, 86, 101, 114, 115, 105, 111, 110, 108, 111, 110, 103, 0, 0, 0, 2, 0, 0, 0, 15, 102, 97, 99, 101, 77, 101, 115, 104, 86, 101, 114, 115, 105, 111, 110, 108, 111, 110, 103, 0, 0, 0, 2, 0, 0, 0, 12, 102, 97, 99, 101, 73, 110, 102, 111, 76, 105, 115, 116, 86, 108, 76, 115, 0, 0, 0, 1, 79, 98, 106, 99, 0, 0, 0, 1, 0, 0, 0, 0, 0, 8, 102, 97, 99, 101, 73, 110, 102, 111, 0, 0, 0, 3, 0, 0, 0, 10, 102, 97, 99, 101, 67, 101, 110, 116, 101, 114, 79, 98, 106, 99, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 110, 117, 108, 108, 0, 0, 0, 2, 0, 0, 0, 0, 88, 32, 32, 32, 100, 111, 117, 98, 63, 222, 208, 81, 126, 75, 23, 229, 0, 0, 0, 0, 89, 32, 32, 32, 100, 111, 117, 98, 63, 214, 68, 141, 240, 18, 52, 86, 0, 0, 0, 13, 102, 101, 97, 116, 117, 114, 101, 86, 97, 108, 117, 101, 115, 79, 98, 106, 99, 0, 0, 0, 1, 0, 0, 0, 0, 0, 13, 102, 101, 97, 116, 117, 114, 101, 86, 97, 108, 117, 101, 115, 0, 0, 0, 5, 0, 0, 0, 5, 115, 109, 105, 108, 101, 100, 111, 117, 98, 63, 204, 40, 245, 192, 0, 0, 0, 0, 0, 0, 8, 117, 112, 112, 101, 114, 76, 105, 112, 100, 111, 117, 98, 191, 202, 225, 71, 160, 0, 0, 0, 0, 0, 0, 8, 108, 111, 119, 101, 114, 76, 105, 112, 100, 111, 117, 98, 63, 202, 225, 71, 160, 0, 0, 0, 0, 0, 0, 10, 109, 111, 117, 116, 104, 87, 105, 100, 116, 104, 100, 111, 117, 98, 63, 196, 122, 225, 64, 0, 0, 0, 0, 0, 0, 11, 109, 111, 117, 116, 104, 72, 101, 105, 103, 104, 116, 100, 111, 117, 98, 63, 204, 40, 245, 192, 0, 0, 0, 0, 0, 0, 20, 102, 101, 97, 116, 117, 114, 101, 68, 105, 115, 112, 108, 97, 99, 101, 109, 101, 110, 116, 115, 79, 98, 106, 99, 0, 0, 0, 1, 0, 0, 0, 0, 0, 20, 102, 101, 97, 116, 117, 114, 101, 68, 105, 115, 112, 108, 97, 99, 101, 109, 101, 110, 116, 115, 0, 0, 0, 0);
That detected this
var mouth = String.fromCharCode(0, 0, 0, 16, 0, 0, 0, 1, 0, 0, 0, 0, 0, 8, 102, 97, 99, 101, 77, 101, 115, 104, 0, 0, 0, 3, 0, 0, 0, 21, 102, 97, 99, 101, 68, 101, 115, 99, 114, 105, 112, 116, 111, 114, 86, 101, 114, 115, 105, 111, 110, 108, 111, 110, 103, 0, 0, 0, 2, 0, 0, 0, 15, 102, 97, 99, 101, 77, 101, 115, 104, 86, 101, 114, 115, 105, 111, 110, 108, 111, 110, 103, 0, 0, 0, 2, 0, 0, 0, 12, 102, 97, 99, 101, 73, 110, 102, 111, 76, 105, 115, 116, 86, 108, 76, 115, 0, 0, 0, 1, 79, 98, 106, 99, 0, 0, 0, 1, 0, 0, 0, 0, 0, 8, 102, 97, 99, 101, 73, 110, 102, 111, 0, 0, 0, 3, 0, 0, 0, 10, 102, 97, 99, 101, 67, 101, 110, 116, 101, 114, 79, 98, 106, 99, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 110, 117, 108, 108, 0, 0, 0, 2, 0, 0, 0, 0, 88, 32, 32, 32, 100, 111, 117, 98, 63, 223, 253, 143, 32, 0, 0, 0, 0, 0, 0, 0, 89, 32, 32, 32, 100, 111, 117, 98, 63, 195, 208, 61, 128, 0, 0, 0, 0, 0, 0, 13, 102, 101, 97, 116, 117, 114, 101, 86, 97, 108, 117, 101, 115, 79, 98, 106, 99, 0, 0, 0, 1, 0, 0, 0, 0, 0, 13, 102, 101, 97, 116, 117, 114, 101, 86, 97, 108, 117, 101, 115, 0, 0, 0, 1, 0, 0, 0, 5, 115, 109, 105, 108, 101, 100, 111, 117, 98, 63, 169, 153, 153, 160, 0, 0, 0, 0, 0, 0, 20, 102, 101, 97, 116, 117, 114, 101, 68, 105, 115, 112, 108, 97, 99, 101, 109, 101, 110, 116, 115, 79, 98, 106, 99, 0, 0, 0, 1, 0, 0, 0, 0, 0, 20, 102, 101, 97, 116, 117, 114, 101, 68, 105, 115, 112, 108, 97, 99, 101, 109, 101, 110, 116, 115, 0, 0, 0, 0);
detected this:
I think Images Size and the Scale of object in the image Have a big impact ot the sliders effects in Liquify
Copy link to clipboard
Copied
Copy link to clipboard
Copied
The mesh I posted selected most of the lips. I create mesh setting the smile slider + some small number, The image you posted is quite small like 500x700px when cropped to the image the selection the mesh made looks like this:
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I still travel and will not be at the computer soon.
Check the level parameters that are applied to the image after the fade is applied in the difference mode. in this thread I have used options that are more suitable for selecting objects with a large area. follow the script step by step and check how well they show the lips. for highlighting small objects I usually use equalize instead of levels.
Copy link to clipboard
Copied
I am surprised that these saved meshes work as well as the do, Images have different Sizes (Number of Pixels), different Aspect Ratios (Canvas Shape) and object scale for example Heads ( Portrait, Half Body, Full bode, Groups) The mesh require for each will different. I'm sure Liquify will user its AI to detect heads and then have a meshes for each face that cams be saved, that may work well similar Images.
Here I saved a mesh I created toe detect a nose on a square 2K x 2K 3/4+ body shot posted in a thread. So a 4MP image. Here I show what it select on the original square 3/4 body shot 4MP image then a 1MP portrait, 4mp, image, an 8mp Imags, and a 50MP image. I have also seen scriptner save different amount a days for mashes. When I use Jazz-y converter I have to strip most of the beginning mesh. Sometime Script listen records no mesh seem to leave it undefined for liquify to figure out. I do not understand how Liquify works here.
Copy link to clipboard
Copied
On you small test image this mesh did well. It does not work well on large images,
var test = String.fromCharCode(0, 0, 0, 16, 0, 0, 0, 1, 0, 0, 0, 0, 0, 8, 102, 97, 99, 101, 77, 101, 115, 104, 0, 0, 0, 3, 0, 0, 0, 21, 102, 97, 99, 101, 68, 101, 115, 99, 114, 105, 112, 116, 111, 114, 86, 101, 114, 115, 105, 111, 110, 108, 111, 110, 103, 0, 0, 0, 2, 0, 0, 0, 15, 102, 97, 99, 101, 77, 101, 115, 104, 86, 101, 114, 115, 105, 111, 110, 108, 111, 110, 103, 0, 0, 0, 2, 0, 0, 0, 12, 102, 97, 99, 101, 73, 110, 102, 111, 76, 105, 115, 116, 86, 108, 76, 115, 0, 0, 0, 1, 79, 98, 106, 99, 0, 0, 0, 1, 0, 0, 0, 0, 0, 8, 102, 97, 99, 101, 73, 110, 102, 111, 0, 0, 0, 3, 0, 0, 0, 10, 102, 97, 99, 101, 67, 101, 110, 116, 101, 114, 79, 98, 106, 99, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 110, 117, 108, 108, 0, 0, 0, 2, 0, 0, 0, 0, 88, 32, 32, 32, 100, 111, 117, 98, 63, 227, 246, 149, 248, 235, 241, 216, 0, 0, 0, 0, 89, 32, 32, 32, 100, 111, 117, 98, 63, 224, 149, 72, 155, 229, 78, 55, 0, 0, 0, 13, 102, 101, 97, 116, 117, 114, 101, 86, 97, 108, 117, 101, 115, 79, 98, 106, 99, 0, 0, 0, 1, 0, 0, 0, 0, 0, 13, 102, 101, 97, 116, 117, 114, 101, 86, 97, 108, 117, 101, 115, 0, 0, 0, 3, 0, 0, 0, 8, 117, 112, 112, 101, 114, 76, 105, 112, 100, 111, 117, 98, 63, 158, 184, 81, 224, 0, 0, 0, 0, 0, 0, 8, 108, 111, 119, 101, 114, 76, 105, 112, 100, 111, 117, 98, 191, 132, 122, 225, 64, 0, 0, 0, 0, 0, 0, 10, 109, 111, 117, 116, 104, 87, 105, 100, 116, 104, 100, 111, 117, 98, 63, 169, 153, 153, 160, 0, 0, 0, 0, 0, 0, 20, 102, 101, 97, 116, 117, 114, 101, 68, 105, 115, 112, 108, 97, 99, 101, 109, 101, 110, 116, 115, 79, 98, 106, 99, 0, 0, 0, 1, 0, 0, 0, 0, 0, 20, 102, 101, 97, 116, 117, 114, 101, 68, 105, 115, 112, 108, 97, 99, 101, 109, 101, 110, 116, 115, 0, 0, 0, 0);
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I do not believe it will be perfect with vastly different size images. The image you posted is a webs size image 336K pixels 472 px by 712 px. Here I scaled it up 10 X 34 MP 4720 Px be 7120 Px about a 16" by 20" 300ppi print image and I use the same mesh. neither was perfect. Too little selected on the web image too much selected on the Print Image. May be perfect on some in between size image. I have know idea how Adobe Face detection works and the seem to be more than one detection methods used by Adobe. Select Color range has Face detection Liquify has face detection, Neural Filters have face detection and these seem to work differently from what I see selected. Some faces are enevn missed.
Faces vary and perspective proportions vary etc.
Copy link to clipboard
Copied
@JJMack Can you send me perfect code of Mouth Detection ?
Copy link to clipboard
Copied
I do not have that mesh any more. It was only I test one I later pasted over it. Use Jazz-y converter and create your own. It may be perfect for a few images it still depends on how Liquify detect faces in images and faces vary in many aspects, Liquify also fails to detect some faces in Image. You should not expect perfect selection. I tend to try to get small selections I then add some area to in scripting code
Copy link to clipboard
Copied
var mesh = String.fromCharCode(0, 0, 0, 16, 0, 0, 0, 1, 0, 0, 0, 0, 0, 8, 102, 97, 99, 101, 77, 101, 115, 104, 0, 0, 0, 3, 0, 0, 0, 21, 102, 97, 99, 101, 68, 101, 115, 99, 114, 105, 112, 116, 111, 114, 86, 101, 114, 115, 105, 111, 110, 108, 111, 110, 103, 0, 0, 0, 2, 0, 0, 0, 15, 102, 97, 99, 101, 77, 101, 115, 104, 86, 101, 114, 115, 105, 111, 110, 108, 111, 110, 103, 0, 0, 0, 2, 0, 0, 0, 12, 102, 97, 99, 101, 73, 110, 102, 111, 76, 105, 115, 116, 86, 108, 76, 115, 0, 0, 0, 1, 79, 98, 106, 99, 0, 0, 0, 1, 0, 0, 0, 0, 0, 8, 102, 97, 99, 101, 73, 110, 102, 111, 0, 0, 0, 3, 0, 0, 0, 10, 102, 97, 99, 101, 67, 101, 110, 116, 101, 114, 79, 98, 106, 99, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 110, 117, 108, 108, 0, 0, 0, 2, 0, 0, 0, 0, 88, 32, 32, 32, 100, 111, 117, 98, 63, 222, 74, 3, 96, 0, 0, 0, 0, 0, 0, 0, 89, 32, 32, 32, 100, 111, 117, 98, 63, 212, 76, 98, 42, 170, 170, 171, 0, 0, 0, 13, 102, 101, 97, 116, 117, 114, 101, 86, 97, 108, 117, 101, 115, 79, 98, 106, 99, 0, 0, 0, 1, 0, 0, 0, 0, 0, 13, 102, 101, 97, 116, 117, 114, 101, 86, 97, 108, 117, 101, 115, 0, 0, 0, 1, 0, 0, 0, 5, 115, 109, 105, 108, 101, 100, 111, 117, 98, 191, 217, 153, 153, 160, 0, 0, 0, 0, 0, 0, 20, 102, 101, 97, 116, 117, 114, 101, 68, 105, 115, 112, 108, 97, 99, 101, 109, 101, 110, 116, 115, 79, 98, 106, 99, 0, 0, 0, 1, 0, 0, 0, 0, 0, 20, 102, 101, 97, 116, 117, 114, 101, 68, 105, 115, 112, 108, 97, 99, 101, 109, 101, 110, 116, 115, 0, 0, 0, 0);
Liquify only allows you to roughly estimate the area of the face element. This is due to the fact that even the smallest correction can introduce a large amount of noise into the nearest pixels.
Filtering out this noise and leaving only the necessary pixels is a rather creative task that needs to be solved and tested on a large array of images.
In this case, I slightly changed the levels parameters.
lr.levels([10, 0.2, 15])
However, this does not mean that this method will work for all images. Perhaps a gaussian blur should be added before levels to blend the pixels of minimal intensity with the background.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
You probably refer to script so in your hint there are missing some steps. I understand you duplicate the layer, make liquify for mouth width equal to 1, then calculations (source one: channel: Gray, blending: difference)? What's then to apply smooth to unexisting selection yet?
Copy link to clipboard
Copied
@r-bin, small distortion values on small images can make the difference indistinguishable from noise. Larger values give more noise, but at the same time higher brightness values in places of maximum difference. Since liqufy is essentially a black box, the result of which we can evaluate only indirectly, we always need to look for a balance of settings to solve a specific task.
Also, on complex layouts with a lot of design elements, for no apparent reason, applying difference after liquify sometimes produces large areas of noise in areas not related to the subject's face. That is, one way or another, it is better to provide for ways to remove it.
I prefer gaussian blur as it is a fairly simple function that produces results almost instantly on most computers.
Copy link to clipboard
Copied
I use smooth that 'kills' unwanted 'single' pixels selection, but it works slow with big value.
Copy link to clipboard
Copied
Jazzy
it works perfectly
thanks for your great contribution.
Copy link to clipboard
Copied
Loll, he got linked to the topic where it is 🙂
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thank you for posting your solution, it's very helpful!
I'm playing with the script but I'm not very into PS scripting, so maybe you guys can help me 🙂
Basically what I'm trying to do is pass a folder of images into the script, if the image has no face, leave it as is without errors, if the image has face in it, crop it above the nose - as shown by this solution - leaving the rest of the image as is, no subject centering, no left right or bottom crop.
Thank you in advance!
Matt
Copy link to clipboard
Copied
I have used lighroom for this and it works great - especially when there are alot of images
Copy link to clipboard
Copied
I confirm, once I installed it and it detects faces really good, at the time of working, so in backround.
Copy link to clipboard
Copied
How can I use LR to do this?
Copy link to clipboard
Copied
some have noticed that the selection changes based on the dpi of the photo.
Copy link to clipboard
Copied
@Adrian5FF9 (original topic poster)
Please mark one or multiple answers as correct so that others with the same/similar question know that an answer was found.