# How to define the foreground and background of an image?

Consider the following image of a knee:

By default the background of this image is the black regions on the left and right sides of the image.

But is it possible to interactively define the foreground and background of this image or any image in general so that whenever I hover the mouse on a specific portion of the image the corresponding region will be considered as the foreground and the background will become transparent?

The idea is motivated from

Healthline Bodymap (http://www.healthline.com/human-body-maps/male) and

Brain Data Crawler (http://community.wolfram.com/groups/-/m/t/568284)

• Isn't this basically the same question as you posed here: mathematica.stackexchange.com/questions/112164/… (but with "black background" instead of "gradient"?) – bill s Apr 11 '16 at 16:00
• Yes, actually it's my updated question. Since, I've already accepted your answer, I thought probably that's why I'm not receiving any answer for my updated question. – Majis Apr 11 '16 at 16:03
• Maybe you could try to use the previous answers to solve your updated question? – bill s Apr 11 '16 at 16:07
• From your answer, I can get the gradient values near about the position of the mouse. Now I need to apply suitable segmentation scheme to segment the corresponding part of the knee. Yes, I'm trying it myself. But any direction will always be helpful. – Majis Apr 12 '16 at 9:14

## 1 Answer

RemoveBackground + HighlightImage seem to work for the provided example.

(Though HighlightImage does not seem to support Mouseover, so I insert it after the fact...)

knee = Import["http://i.stack.imgur.com/hCC57.jpg"];

mask = Binarize[RemoveBackground[knee], 0];

HighlightImage[knee, mask] /. f_FilledCurve :>
Tooltip[Mouseover[{EdgeForm[None], Opacity[0], f}, f], "Knee Joint"]


• Thanks for your response. Now I need to implement suitable segmentation scheme to get the different masks for different parts of the knee. – Majis Apr 12 '16 at 9:09