stable-diffusion-webui icon indicating copy to clipboard operation
stable-diffusion-webui copied to clipboard

Torso-autocrop

Open PhytoEpidemic opened this issue 3 years ago • 2 comments

I added a method of estimating where the torso of the subject may be based on the location of the face in the image.

It just finds the direction of the face relative to the center, then assumes the torso will be in the opposite direction. This works very well in most cases. An edge case would be if the person is at the edge of a very wide image and they are standing straight up.

torso_centroid = None
    if len(face_points) > 0 and settings.torso_points_weight > 0:
      torso_centroid = centroid(face_points)
      torso_centroid.weight = settings.torso_points_weight / weight_pref_total 
      face_x_distance = torso_centroid.x - im.width / 2
      face_y_distance = torso_centroid.y - im.height / 2
      face_direction = atan2(face_y_distance, face_x_distance)
      torso_centroid.x -= (settings.crop_width / 2) * cos(face_direction)
      torso_centroid.y -= (settings.crop_height / 2) * sin(face_direction)
      pois.append(torso_centroid)

I have tested this on: -windows 10 OS -chrome browser -NVIDA RTX A6000 48GB

Old: Screenshot 2023-02-14 174045 New: Removed the redundant "Focal point" before each variable. Screenshot 2023-02-14 171809 Examples: 00000-1-221 00001-1-291 00002-1-387 00003-1-5

PhytoEpidemic avatar Feb 15 '23 00:02 PhytoEpidemic

What about sideways tilted heads?

thomasaum avatar Feb 17 '23 16:02 thomasaum

What about sideways tilted heads?

The orientation of the head does not matter for this. The only thing taken into account is the position of the face and the image dimensions. As long as the face is successfully detected it should work great on sideways tilted heads. Since it is only an estimate, it's best to use it just to nudge the crop towards the torso so that the faces are not all at the center of the images.

Here are some more examples: 00000-1-1151 00001-1-1784 00006-1-2624 00004-1-2212 00011-1-813 00005-1-2543 00008-1-3234 00002-1-1788

PhytoEpidemic avatar Feb 20 '23 01:02 PhytoEpidemic

Plans for future is to let extensions add new types preprocessing for that tab, and when that happens I would prefer this would be an extension, but until then I don't want to add more of cropping to the main repo.

AUTOMATIC1111 avatar May 17 '23 21:05 AUTOMATIC1111