469,600 Members | 2,231 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,600 developers. It's quick & easy.

PIL question about crop method

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.
Apr 5 '06 #1
6 8311
John Salerno schrieb:
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
Apr 5 '06 #2
John Salerno wrote:
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

Apr 5 '06 #3
Diez B. Roggisch wrote:
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?
Apr 5 '06 #4
John Salerno wrote:
Diez B. Roggisch wrote:
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?


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)?
Apr 5 '06 #5
Yes


John Salerno wrote:
John Salerno wrote:
Diez B. Roggisch wrote:
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?


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)?


Apr 5 '06 #6
John Salerno wrote:
John Salerno wrote:

Diez B. Roggisch wrote:
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?


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
Apr 5 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Kevin Smith | last post: by
6 posts views Thread by isaacyho | last post: by
3 posts views Thread by ACaunter | last post: by
reply views Thread by brahimbb17 | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.