# Understanding the coordinate system for ImageTake

I have a point in an image which I can locate by right clicking and using my mouse. Call this point $p = (100,100)$. I'd like to use ImageTake to grab an image, centered on this spot $p$ with $k = 10$ pixels above, below, to the right, and to the left of $p$. Unfortunately, it seems like ImageTake is switching coordinates on me somehow.

How might I accomplish this task?

-
Here is also a discussion about why the coordinate systems are this way mathematica.stackexchange.com/questions/27404/… –  bill s Jul 1 '13 at 4:51
@bills Mathematica's documentation also includes a tutorial on the topic. Check out the section "Coordinate Systems" from reference.wolfram.com/mathematica/tutorial/ImageProcessing.html. –  Matthias Odisio Jul 2 '13 at 22:37

For example, to get the eye of the mandrill example image:

image = ExampleData[{"TestImage", "Mandrill"}]
indices = {56, 176};
k = 50;
ImageTake[image, {indices[[1]] - k,
indices[[1]] + k}, {indices[[2]] - k, indices[[2]] + k}]

Indices were obtained by right clicking on the image and choosing "Get Indices".

Regarding how the coordinate system works, the difference between coordinates and indices are that the indice origin is in the top left corner, whereas the coordinate origin is in the bottom left corner.

Update

So in order to use coordinates, we can do this:

ImageTake[
image, {
ImageDimensions[image][[2]],
ImageDimensions[image][[2]]
} - {cor[[2]] + k, cor[[2]] - k}, {cor[[1]] - k,
cor[[1]] + k}]

This code manually transforms the coordinates into indices. But ImageTake says that if the row number is negative, it starts from the bottom. That's exactly how coordinates work, so we can simply do this:

ImageTake[image, -{cor[[2]] + k,
cor[[2]] - k}, {cor[[1]] - k, cor[[1]] + k}]
-
Is there an automatic command to pull the indices? –  B.H. Jul 1 '13 at 0:38
Given the coordinates? –  Pickett Jul 1 '13 at 0:39
Yes, if that's possible. –  B.H. Jul 1 '13 at 0:40
Say I gave you the coordinates {333,458}... could you get me the eye in the right orientation with a box of side length 2k+1? –  B.H. Jul 1 '13 at 0:41
Updated with code that works for coordinates. –  Pickett Jul 1 '13 at 0:54

Don't use ImageTake if your coordinates are (x;y) image coordinates and not (row;col) positions. ImageTrim[image, {{x,y}}, 10] works as expected.

You may want to check out the section "Coordinate Systems" from this tutorial.

-