Stable Diffusion and Aspect Ratios

Stable Diffusion and Aspect Ratios

Jul 26, 2024

Stable Diffusion and Aspect Ratios

One task that arises in AI image generation is the selection of the image size or the selection of the aspect ratio of the image which should be created. There are some restrictions regarding the selectable height and width in Stable Diffusion.

Below I present how height and width can be suitably selected to achieve the desired aspect ratio.

Selectable values for width and height

Possible values for width and height which can be used with Stable Diffusion are:

  • 128

  • 192

  • 256

  • 320

  • 384

  • 448

  • 512 *

  • 576

  • 640

  • 704

  • 768 *

  • 832

  • 896

  • 960

  • 1024 *

  • 1152

  • 1280

  • 1536

  • 1792

  • 2048

  • 2304

  • 4096

The values marked with the star should be the preferred values. All of the above listed values are divisible by 64 (32, 16, 8, 4, 2).

A general rule states that no values smaller than 512 pixels should be used for height and width. Another general rule states that the smallest combination of height and width should always be used. Larger resolutions are then achieved by upscaling.

Aspect Ratios

Using the values of the last section following aspect ratios can be get by the following combinations:

No specific Orientation

  • 1:1 → 512 x 512 pixel

Orientation Landscape

  • 2:1 → 1024 x 512 pixel → (Factor 2) *

  • 3:2 → 768 x 512 pixel → (Factor 1.5)

  • 4:3 → 768 x 576 pixel → (Factor 1.33)

  • 5:3 → 960 x 576 pixel → (Factor 1.67) *

  • 5:4 → 640 x 512 pixel → (Factor 1.25) *

  • 6:5 → 768 x 640 pixel → (Factor 1.2) *

  • 7:5 → 896 x 640 pixel → (Factor 1.4) *

  • 14:9 → 896 x 576 pixel → (Factor 1.56) *

  • 15:9 → 960 x 576 pixel → (Factor 1.56) *

  • 16:9 → 1024 x 576 pixel → (Factor 1.78)

  • 16:10 → 1024 x 640 pixel → (Factor 1.6) *

Orientation Portrait

  • 1:2 → 512 x 1024 pixel → (Factor 0.5) *

  • 2:3 → 512 x 768 pixel → (Factor 0.67)

  • 3:4 → 576 x 768 pixel → (Factor 0.75)

  • 3:5 → 576 x 960 pixel → (Factor 0.6) *

  • 4:5 → 512 x 640 pixel → (Factor 0.8) *

  • 5:6 → 640 x 768 pixel → (Factor 0.834) *

  • 5:7 → 640 x 896 pixel → (Factor 0.714285714) *

  • 9:14 → 576 x 896 pixel → (Factor 0.642857143) *

  • 9:15 → 576 x 960 pixel → (Factor 1.56) *

  • 9:16 → 576 x 1024 pixel → (Factor 0.5625)

  • 10:16 → 640 x 1024 pixel → (Factor 0.625) *

The aspect ratios marked with the star are the more uncommon aspect ratios in use.

Keep all the time in mind that the image size is influencing the overall quality and the informations in it of the resulting AI generated image.

Uncommon aspect ratios

Other uncommon aspect ratios are:

  • 1.85:1 ⇔ 1:1.85

  • 1.91:1 ⇔ 1:1.91

  • 2.32:1 ⇔ 1:2.32

  • 2.40:1 ⇔ 1:2.40

  • 4:1 ⇔ 1:4

  • 12:1 ⇔ 1:12

  • 19:16 ⇔ 16:19

On Github [1] you can find a small script called `sd_aspect_ratio.bash`, which calculates a valid resolution from a given aspect ratio.


Have a nice day! See you back soon!


Reference

[1] sd_aspect_ratio.bash

Enjoy this post?

Buy zentrocdot a coffee

More from zentrocdot