Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an imported and cropped image:

TestPicture = Import["filepath.jpg"];
TestPictureCropped = ImageCrop[TestPicture, Min[ImageDimensions[TestPicture]]];

How can I specify a coordinate in the image and return the color of the nearest pixel to the coordinate? Thanks for any help!

share|improve this question
up vote 11 down vote accepted

For example:

tp = ExampleData[{"TestImage", "Airplane"}];
Manipulate[Column@{tp, Extract[ImageData[tp], Round /@ p]}, 
          {{p, {1, 1}}, Locator}]

enter image description here

share|improve this answer
ImageValue is also another choice – HyperGroups May 8 '13 at 4:33
This answer is incorrect because it messes up different coordinate systems, as can be seen with tp = Image@IdentityMatrix[100]. PixelValue and ImageValue are the preferred way to accomplish this task. – Matthias Odisio May 8 '13 at 17:50
This gives the wrong values! The values in p are coordinates, so they are 0-based, start at the bottom-left corner and are stored in x/y order. Extract expects array indices, which are 1-based, start at the top-left corner and are in row/column (i.e. y/x) order. So the values you get are transposed, upside down and shifted by one pixel. – nikie May 9 '13 at 9:16
Way to go beli :D – Rojo May 12 '13 at 4:41
tp = ExampleData[{"TestImage", "Lena"}];
Manipulate[Column @ {tp, ImageValue[tp, p]}, {{p, {1, 1}}, Locator}]

a Manipulate for picking colors

share|improve this answer

As a side-note - you can quickly get color info from images using image assistant. Just click once on the image and in version 9 assistant will appear below:

enter image description here

share|improve this answer

Also worth noting is that there's a companion function to ImageValue, called PixelValue. The difference between the two is, as far as I can tell from the documentation, that ImageValue interpolates the color of a coordinate according to the colors of nearby pixels, whereas PixelValue finds the color of the pixel whose centre is nearest to the integer values of the coordinates. The difference is hard to spot on smooth photographs, but possible:

tp = ExampleData[{"TestImage", "Mandrill"}];
   ImageValue[tp, p],
     RGBColor[ImageValue[tp, p]],
     Rectangle[{0, 0}, {3, 1}]}],
   PixelValue[tp, p],
     RGBColor[PixelValue[tp, p]],
     Rectangle[{0, 0}, {3, 1}]}]
 {{p, {1, 1}}, Locator}


(Code adapted from this answer)

share|improve this answer
As you hinted, in addition to ImageValue interpolating neighboring pixel values, the coordinate systems of ImageValue an PixelValue are off by one half. See the 'Properties and Relations' section of – Matthias Odisio May 8 '13 at 17:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.