Is it somehow possible to recognize the color at each pixel in an image and show this color as a tooltip?

For example, with this picture:

cranial cross-section

I found a solution that uses LocatorPane in combination with DynamicModule:

DynamicModule[{pt = {1, 1}/2}, {LocatorPane[Dynamic[pt], img], 
  Dynamic[pt], Dynamic[RGBColor@PixelValue[img, {pt[[1]], pt[[2]]}]]}]

There is no Tooltip however. That I didn't figure out yet.


I have written this piece code (with the help of C.E.):

image = Import["https://i.stack.imgur.com/36JuK.png", "Image"];
 pos = MousePosition["Graphics", {0, 0}];
 graphics = Graphics[{
    RGBColor[ImageValue[image, pos]],
    }, ImageSize -> 100];
 Tooltip[image, graphics]


| improve this answer | |
  • $\begingroup$ Somehow, that crashed Mathematica, when moving the mouse too fast. But code works, thank you! $\endgroup$ – holistic Aug 20 '17 at 17:03
  • $\begingroup$ i can't fix that problem sorry,maybe someone else will improve the solution. you can also switch from mouseposition[], which force mathematica to re-evaluate everything each time the mouse move, to a different strategy ( for example retrieve the mouse position only when you click or double click with the mouse) $\endgroup$ – Alucard Aug 20 '17 at 17:18
  • 2
    $\begingroup$ +1. It seems like it was displaying RGBColor that caused the crash. Displaying the color using Graphics appears to work. I made an update with that, I hope you don't mind. $\endgroup$ – C. E. Aug 20 '17 at 19:42
  • $\begingroup$ @C.E. i appreciate it! i didn't know how to fix the problem $\endgroup$ – Alucard Aug 20 '17 at 20:02
  • $\begingroup$ Thanks for thinking about it, works well! $\endgroup$ – holistic Aug 20 '17 at 22:47

You can use built-in Image Assistant. Click once on an image in the notebook to select it. Image Assistant will appear under it:

enter image description here

In various tabs of the Image Assistant at the bottom you can find Tooltip Options. Select options you need and mouse-over pixels - you will get your tooltip as shown on the image below.

enter image description here

| improve this answer | |
  • $\begingroup$ Thank you! But this does not work in my case, since I want to build it into a Manipulate later and it should be done automatically $\endgroup$ – holistic Aug 20 '17 at 15:56

This is an extended comment on @VitalyKaurov's answer. That edit interface is actually loaded from here:

  "PrivatePathsSystemResources"] // FrontEndExecute

So you can look at the source for that to see how it's implemented in the front end (the code is actually pretty cool). You can also get the thing to wrap on a selected image box like so:

FEPrivate`WrapImageWithEditCell[InputNotebook[]] // FE`Evaluate;

Here's an example of that:

SelectionMove[EvaluationCell[], Before, Cell];
box =
SelectionMove[box, All, Box];
FEPrivate`WrapImageWithEditCell[InputNotebook[]] // FE`Evaluate;

Theoretically, then we could find a way to reuse what the FE uses to get a (mostly) pure front-end approach to this. Whether this is better than a Manipulate is up to preference.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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