PIL question about crop method

J

John Salerno

I might be way off target even looking into this method for what I need
to do, but I'm still a little confused about the description of it:

crop
im.crop(box) => image

Returns a rectangular region from the current image. The box is a
4-tuple defining the left, upper, right, and lower pixel coordinate.

I'm probably just being a little dense again, but how exactly do you
write the tuple? Wouldn't a coordinates parameter be a tuple of tuples?
It sounds like here you only need four numbers, but I don't understand
what 'left, upper, right, and lower pixel coordinate' means. It doesn't
seem like it's asking for a set of coordinates for each corner of the
box, or for a set at all. How do four separate numbers make up coordinates?

Thanks.
 
D

Diez B. Roggisch

John said:
I might be way off target even looking into this method for what I need
to do, but I'm still a little confused about the description of it:

crop
im.crop(box) => image

Returns a rectangular region from the current image. The box is a
4-tuple defining the left, upper, right, and lower pixel coordinate.

I'm probably just being a little dense again, but how exactly do you
write the tuple? Wouldn't a coordinates parameter be a tuple of tuples?
It sounds like here you only need four numbers, but I don't understand
what 'left, upper, right, and lower pixel coordinate' means. It doesn't
seem like it's asking for a set of coordinates for each corner of the
box, or for a set at all. How do four separate numbers make up coordinates?

You can think of a rect as two coordinates - e.g. (10, 20), (30, 100)

Alternatively you can see it as boundary lines, in the order left, top,
right, bottom.

(10, 20, 30, 100)

The latter is what you need.

Diez
 
G

Gary Herron

John said:
I might be way off target even looking into this method for what I need
to do, but I'm still a little confused about the description of it:

crop
im.crop(box) => image

Returns a rectangular region from the current image. The box is a
4-tuple defining the left, upper, right, and lower pixel coordinate.

I'm probably just being a little dense again, but how exactly do you
write the tuple? Wouldn't a coordinates parameter be a tuple of tuples?
It sounds like here you only need four numbers, but I don't understand
what 'left, upper, right, and lower pixel coordinate' means. It doesn't
seem like it's asking for a set of coordinates for each corner of the
box, or for a set at all. How do four separate numbers make up coordinates?

Thanks.
If you want the cropped rectangle to go from 100 to 200 in x and 300 to
400 in y, then those four values need to be placed in a tuple in the
specified order:
box=(100,300,200,400)

Gary Herron
 
J

John Salerno

Diez said:
Alternatively you can see it as boundary lines, in the order left, top,
right, bottom.

(10, 20, 30, 100)

So in the above, from where are the numbers being counted? 10 is ten
pixels from the left border of the image? 20 is twenty pixels from the
top border? But is 30 thirty pixels from the left or the right border of
the image? And is 100 one hundred pixels from the top or bottom?
 
J

John Salerno

John said:
So in the above, from where are the numbers being counted? 10 is ten
pixels from the left border of the image? 20 is twenty pixels from the
top border? But is 30 thirty pixels from the left or the right border of
the image? And is 100 one hundred pixels from the top or bottom?

I came up with this, is it correct:

(a,b) (c,b)
-----------------
| |
| |
-----------------
(a,d) (c,d)


So the tuple would be (a, b, c, d)?
 
P

Philippe Martin

Yes




John said:
I came up with this, is it correct:

(a,b) (c,b)
-----------------
| |
| |
-----------------
(a,d) (c,d)


So the tuple would be (a, b, c, d)?
 
G

Gary Herron

John said:
John Salerno wrote:



I came up with this, is it correct:

(a,b) (c,b)
-----------------
| |
| |
-----------------
(a,d) (c,d)


So the tuple would be (a, b, c, d)?
That look right.

But why be so cautious? Try it and see if it works. (I believe it will
-- but if not -- try again.)

Gary Herron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top