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!


4 Answers 4


For example:

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

enter image description here

  • 1
    $\begingroup$ ImageValue is also another choice $\endgroup$ Commented May 8, 2013 at 4:33
  • 1
    $\begingroup$ 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. $\endgroup$ Commented May 8, 2013 at 17:50
  • 2
    $\begingroup$ 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. $\endgroup$ Commented May 9, 2013 at 9:16
  • $\begingroup$ Way to go beli :D $\endgroup$
    – Rojo
    Commented May 12, 2013 at 4:41
tp = ExampleData[{"TestImage", "Lena"}];
Manipulate[Column @ {tp, ImageValue[tp, p]}, {{p, {1, 1}}, Locator}]

a Manipulate for picking colors


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


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)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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