Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to get the Pixel value of an image.and here is my code

DynamicModule[{p = {50, 50}},
  {Show[img, Graphics[Locator[Dynamic[p]]]], 
                 ImageValue[img, Dynamic[p]]}]

and it came up with a warning that p is with a non integer value, to solve the problem ,I used Floor to get an integer value

DynamicModule[{p = {50, 50}},
  {Show[img, Graphics[Locator[Dynamic[p]]]], 
                 ImageValue[img,Floor/@Dynamic[p]]}]

this time it still doesnt work, with a warning:

    ImageValue::imgrng: The specified argument Floor[p$20303] should be a pair of real or      integer numbers or a list of those.

My question is ,can I strict the loactor to Integer Domain?or is there any more elegent way to deal with this problem?

share|improve this question

closed as off-topic by Kuba, Artes, m_goldberg, István Zachar, ssch Sep 10 '13 at 15:49

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Kuba, Artes, m_goldberg, István Zachar, ssch
If this question can be reworded to fit the rules in the help center, please edit the question.

    
The approach is almost good. However Dynamic[p] has Head Dynamic and some functions are not able to cooperate with it so you have to move Dynamic outside. You may also want to take a look at related locator on a png file. (pay attention to the coordinates which are relevant in your case) –  Kuba Sep 10 '13 at 6:03
    
@Kuba,tks, as you said, I fixed the problem, it works well now –  tintin Sep 10 '13 at 6:05
add comment

1 Answer 1

up vote 2 down vote accepted

Kuda's help is quite useful, it helps me to fix the problem,

The thing is that Floor[Dynamic[p]]would not work properly, so ImageValue can't be updated.

So, After moving the Dynamicout side the ImageValue,it works

DynamicModule[{p = {50, 50}},
    {Show[img, Graphics[Locator[Dynamic[p]]]], 
       Dynamic[ImageValue[img, Floor /@ p]]}]

enter image description here

share|improve this answer
add comment

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