Where does Intensity come from in the image_slice function?

I’m trying to replicate the hovertool with image intensity (and mask intensity from an external mask).

How do I do this? So far I have:

MyHover1 = HoverTool(
tooltips=[
( ‘(x, y)’, ‘($x, $y)’),
(‘Intensity’, ‘$Intensity’),
],
formatters={
‘(x, y)’ : ‘numeral’,
‘Intensity’: ‘numeral’,
},
point_policy=“follow_mouse”
)

def image_slice(dims, array, lbrt, mapper, smooth_fun):
array = np.asarray(array)
low = mapper[‘low’] if mapper else array.min()
high = mapper[‘high’] if mapper else array.max()
cmap = mapper[‘palette’] if mapper else ‘fire’
img = hv.Image(smooth_fun(array), bounds=lbrt, kdims=dims, vdims=‘Intensity’).opts(tools=[MyHover1])
reset_fun = partial(hook_reset_range, lbrt=lbrt)
return img.opts(clim=(low, high), cmap=cmap, hooks=[reset_fun])

Intensity come from the vdims name declared in the holoviews hv.Image
In your case I suppose you want this:

MyHover1 = HoverTool(
    tooltips=[
        ( '(x, y)', '($x, $y)'),
        ('Intensity', '@image'),
    ],
    formatters={
        '(x, y)' : 'numeral',
        'Intensity': 'numeral',
    },
    point_policy="follow_mouse"
)

where Intensity corresponds to the value of the image at the curent pixel position

Thanks @xavArtley! I’m interested to know where the @image comes from. In particular, I want to understand so I can append a binary mask to the image, which I can overlay on the image with opacity, and use its values to translate to labels. E.g. if the pixel intensity in the mask is 0, the hovertool shows background. If it’s 1, it shows dog, and if it’s 2, it shows cat.

From what I can figure out so far, it looks like an Overlay might be the easiest solution. But then the HoverTools overlap and this is inefficient as it looks like it will require a 2D array of strings the same size as the image array, rather than a UINT8 mask with a dictionary to translate intensity to label.