# Identify color at each pixel in an image and show as tooltip

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:

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"];
Dynamic[
pos = MousePosition["Graphics", {0, 0}];
graphics = Graphics[{
RGBColor[ImageValue[image, pos]],
Rectangle[]
}, ImageSize -> 100];
Tooltip[image, graphics]
]


• Somehow, that crashed Mathematica, when moving the mouse too fast. But code works, thank you! – holistic Aug 20 '17 at 17:03
• 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) – Alucard Aug 20 '17 at 17:18
• +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. – C. E. Aug 20 '17 at 19:42
• @C.E. i appreciate it! i didn't know how to fix the problem – Alucard Aug 20 '17 at 20:02
• Thanks for thinking about it, works well! – 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:

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.

• 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 – holistic Aug 20 '17 at 15:56

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

FrontEndFindFileOnPath["AttachedImage2D.nb",
"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:

FEPrivateWrapImageWithEditCell[InputNotebook[]] // FEEvaluate;


Here's an example of that:

SelectionMove[EvaluationCell[], Before, Cell];
NotebookWrite[
InputNotebook[],
Cell[
BoxData@ToBoxes@Import["https://i.stack.imgur.com/36JuK.png"],
"Output"
]
];
box =
Nest[
First@*FrontEndExecute@*FrontEndObjectChildren,
PreviousCell[],
1
];
SelectionMove[box, All, Box];
FEPrivateWrapImageWithEditCell[InputNotebook[]] // FEEvaluate;


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.