0

How Can we use PixelValue with pixel indices?

phdstudent
  • 423
  • 3
  • 12
  • Can you be more specific than just a one liner that repeats the title? Specifically, how is this not addressed by the documentation for PixelValue? – rm -rf Jan 07 '14 at 22:03
  • You can define a new function that uses indices instead of pixel coordinates: getPixelValue[img_, {x_, y_}] := PixelValue[img, {First@ImageDimensions[img] - y, x}] – C. E. Jan 07 '14 at 22:12
  • 1
    @Anon, I think that getPixelValue[img_, {x_, y_}] := PixelValue[img, {First@ImageDimensions[img] - y, x}] is not correct and you have to correct like this getPixelValue[img_, {x_, y_}] := PixelValue[img, {x , ImageDimensions[img][[2]]-y}] – phdstudent Jan 07 '14 at 22:29
  • @phdstudent Yes, you are right. – C. E. Jan 07 '14 at 22:40
  • @rm-rf, my question was not a duplicate one. In your link, they talked about ImageTake[]. – phdstudent Jan 07 '14 at 23:19
  • @phdstudent It seems that your problem is just with the coordinates used in images (which is different from that in graphics), and this is adequately addressed in the link. Also see the link in Matthias Odisio's comment in the duplicate. – rm -rf Jan 07 '14 at 23:55

1 Answers1

0
getPixelValue[img_, {x_, y_}] := PixelValue[img, {x , ImageDimensions[img][[2]]+1-y}]
phdstudent
  • 423
  • 3
  • 12
  • 1
    If this answer solves your problem, that's good. But why do you want to introduce another coordinate system? There are already three... If x is supposed to be a column index from 1 to width and y a row index from 1 to height, then your formula should be PixelValue[img, {x, height + 1 - y}]. You may want to check out the section "Coordinate Systems" from this tutorial (http://reference.wolfram.com/mathematica/tutorial/ImageProcessing.html). – Matthias Odisio Jan 08 '14 at 04:09
  • @MatthiasOdisio, sorry I forget just to add 1 to ImageDimensions[img][[2]]+1-y – phdstudent Jan 08 '14 at 04:16