2

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?

B.H.
  • 33
  • 2
  • Here is also a discussion about why the coordinate systems are this way http://mathematica.stackexchange.com/questions/27404/reverse-after-imagedata/27423#27423 – bill s Jul 01 '13 at 04:51
  • @bills Mathematica's documentation also includes a tutorial on the topic. Check out the section "Coordinate Systems" from http://reference.wolfram.com/mathematica/tutorial/ImageProcessing.html. – Matthias Odisio Jul 02 '13 at 22:37
  • @B.H. It is the stupid philosophy of mathematica!? – BetterEnglish Feb 24 '16 at 02:15

2 Answers2

2

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}]
C. E.
  • 70,533
  • 6
  • 140
  • 264
2

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.

Matthias Odisio
  • 1,246
  • 9
  • 11