Skip to content

How to control the image after transform to show all original content before transform? #8103

Closed Answered by radarhere
nissansz asked this question in Q&A
Discussion options

You must be logged in to vote
from PIL import Image
import numpy as np
image = Image.open("F23.png")
matrix = np.array([
  [1, 0.2, 0],
  [0, 1, 0],
  [0, 0, 1]
])
new_width = int(image.width * 1.5)
new_height = int(image.height * 1.5)
transformed_image = image.transform((new_width, new_height), Image.AFFINE, matrix.flatten())
transformed_image.save("output_image.jpg")

gives

You can use crop() to manually remove the black box.

But I think you're asking for a way to reverse the matrix operation? You can simply flip() the matrix.

from PIL import Image
import numpy as np
image = Image.open("F23.png")
matrix = np.array([
  [1, 0.2, 0],
  [0, 1, 0],
  [0, 0, 1]
])
new_width = int(image.width * 1.5)
new_height = int(image.h…

Replies: 1 comment 13 replies

Comment options

You must be logged in to vote
13 replies
@radarhere
Comment options

@nissansz
Comment options

@nissansz
Comment options

@nissansz
Comment options

@radarhere
Comment options

Answer selected by radarhere
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants