How to initialize the end size of image after affine transformation

213 Views Asked by At

How to initialize the end size of image after affine transformation. How can i calculate them?

from PIL import Image 
import math 
 
img = Image.open('image.png') 
img.convert('RGB') 
result = Image.new('RGB', (87, 87)) # and here I want to know the dimensions in advance, because now I have entered them myself
width, height = img.size 
a = 60 * (math.pi / 180) 
xmin = width 
xmax = 0 
ymin = height 
ymax = 0 
for i in range(0, width): 
    for j in range(0, height): 
        colors = img.getpixel((i, j)) 
        x = int(i * math.cos(a) + j * math.sin(a)) 
        y = -int(i * math.sin(a) - j * math.cos(a) - 54) 
        result.putpixel((x, y), colors) 
result.show()
```
1

There are 1 best solutions below

4
On BEST ANSWER

In short, we get only corner pixels transformed coordinates.

max_dim=tuple(max(
 (int(i * math.cos(a) + j * math.sin(a)),
 -int(i * math.sin(a) - j * math.cos(a) - 54))[k]
 for i in range(0, width, width-1)
    for j in range(0, height,height-1)
) for k in [0,1])
result = Image.new('RGB', max_dim)