6
$\begingroup$

I am using Mathematica to explore the face detection feature of Core Image on Mac OS X Lion. To do this I have an Objective-C program which captures images from the iSight camera, runs face detection and logs the coordinates of any detected features, and then saves the image to the clipboard. I then switch to Mathematica and paste the captured image into one variable, and copy-and-paste the logged feature coordinates into another.

I've written a simple Mathematica function that can subsequently produce a "normalized" face image, but it would be helpful to be able to draw graphics on top of an image in order to visualize where features are and how they're oriented. When I naively try this I get the error: "Image is not a graphics primitive or directive."

Is there a simple way to draw (or composite) graphics on top of an image?

$\endgroup$

2 Answers 2

10
$\begingroup$

Show can combine Image and Graphics:

a = ExampleData[{"AerialImage", "Oakland2"}];
b = Graphics[{Red, Thick, Circle[{400, 400}, 300]}];
Show[a, b]

enter image description here

In this way you can do it in a programmatic way. But you can also do this manually and interactively via right-click menu access to Drawing Tools:

enter image description here

enter image description here

$\endgroup$
6
  • 3
    $\begingroup$ That torn edge looks suspiciously like Heike's method. :) $\endgroup$
    – rcollyer
    Apr 13, 2012 at 1:19
  • $\begingroup$ Just what the doctor ordered, thanks! $\endgroup$ Apr 13, 2012 at 1:24
  • $\begingroup$ @rcollyer nice name haha :) $\endgroup$ Apr 13, 2012 at 1:43
  • $\begingroup$ @EiyrioüvonKauyf whatever works. :) $\endgroup$
    – rcollyer
    Apr 13, 2012 at 1:44
  • $\begingroup$ @rcollyer indeed ;-) $\endgroup$ Apr 13, 2012 at 5:21
4
$\begingroup$

You can also achieve the same effects with ImageCompose

a = ExampleData[{"AerialImage", "Oakland2"}];
b = Graphics[{Opacity[0.5], Red, Thick, Circle[{200, 200}, 300], 
    Circle[{1500, 200}, 200], Circle[{0, 0}, 200]}];

ImageCompose[a, b]

And also with Overlay:

Overlay[{a, b}, Alignment -> {Center}]

Though the co-ordinate system is not consistent between the two.

$\endgroup$
2
  • 2
    $\begingroup$ Just to note that result produced by Overlay will be neither Graphics or Image. Sometimes people are surprised by that :) $\endgroup$ Apr 13, 2012 at 2:17
  • $\begingroup$ I'm suitably surprised :) It appears to be ... an Overlay ! $\endgroup$ Apr 13, 2012 at 2:21

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.