-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ValueError: tile cannot extend outside image #4517
Comments
Without an image, this is difficult to debug. I mean, I can construct a script that runs the line you have provided, using one of our test images, and it runs without a problem. from PIL import Image
import numpy
x1, x2 = 20, 100
y1, y2 = 20, 100
im = Image.open('Tests/images/hopper.jpg')
A_img = numpy.asarray(im)
A_img = Image.fromarray(A_img[y1:y2, x1:x2, :]) |
I do find that Image.fromarray(A_img[50:50, 50:50, :]) Is that the case with your code? |
At the moment, the simplest explanation is that the dimensions that you're trying to crop are wrong. If they're zero, or negative, then I can replicate your error. If you're able to provide values for Closing, as without more information, there isn't much to do here. |
Going to necro this issue with some information. I also encountered this issue when cropping images with bounding boxes detected through AWS Rekognition. The error only happens when negative coordinates are passed to the cropped image. AWS Rekognition documentation actually has a note documenting the return values for the bounding box: https://docs.aws.amazon.com/rekognition/latest/APIReference/API_BoundingBox.html |
Hi. If you're using the same code in this issue, then I ask you to consider the following. The following works when from PIL import Image
import numpy
x1, x2 = 0, 1
y1, y2 = 0, 1
im = Image.open('Tests/images/hopper.jpg')
A_img = numpy.asarray(im)
a = A_img[y1:y2, x1:x2, :]
print(a)
A_img = Image.fromarray(a) printing
Pillow can load that array without a problem. If from PIL import Image
import numpy
x1, x2 = 1, 1
y1, y2 = 1, 1
im = Image.open('Tests/images/hopper.jpg')
A_img = numpy.asarray(im)
a = A_img[y1:y2, x1:x2, :]
print(a)
A_img = Image.fromarray(a) printing
If from PIL import Image
import numpy
x1, x2 = 2, 1
y1, y2 = 2, 1
im = Image.open('Tests/images/hopper.jpg')
A_img = numpy.asarray(im)
a = A_img[y1:y2, x1:x2, :]
print(a)
A_img = Image.fromarray(a) printing
So in those last two examples, Pillow is being passed an empty array. Unless you'd like Pillow to show a (0, 0) image, there's nothing to do, as Pillow isn't being given any image data. If you're not using the same code as this issue, then please create a new issue with a self-contained example. |
What did you do?
I am trying to crop an image
Sorry, I am not able to provide a source image
What did you expect to happen?
To get the properly cropped image without any bugs
What actually happened?
What are your OS, Python and Pillow versions?
The text was updated successfully, but these errors were encountered: