Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 10 down vote accepted

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

share|improve this answer
3  
That torn edge looks suspiciously like Heike's method. :) –  rcollyer Apr 13 '12 at 1:19
    
Just what the doctor ordered, thanks! –  Kaelin Colclasure Apr 13 '12 at 1:24
    
@rcollyer nice name haha :) –  Eiyrioü von Kauyf Apr 13 '12 at 1:43
    
@EiyrioüvonKauyf whatever works. :) –  rcollyer Apr 13 '12 at 1:44
    
@rcollyer indeed ;-) –  Vitaliy Kaurov Apr 13 '12 at 5:21

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.

share|improve this answer
2  
Just to note that result produced by Overlay will be neither Graphics or Image. Sometimes people are surprised by that :) –  Vitaliy Kaurov Apr 13 '12 at 2:17
    
I'm suitably surprised :) It appears to be ... an Overlay ! –  image_doctor Apr 13 '12 at 2:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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