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 want to superpose an image with a graphics in order to evaluate their alignment.

I am writting this exemple of code.

s1 = Graphics[{RGBColor[{1,0,0}],Circle[{0, 1}]}];
model = ContourPlot[x^2 + y^2 - 1 == 0, {x, -2, 2}, {y, -2, 2}]
imref = Rasterize[s1, ImageSize -> {200, 150}](*suppose that is given by camera*)
Show[imref,model]; 
(*second method*)
immodel=Rasterize[model, ImageSize -> {200, 150}];
ImageCompose[imref,immodel]

I have an other idea, I can binarize the two images and Multiply them or do ImageDifference to get the result alignement but I need also to show graphically the results! Is there any idea to add the opacity or transparency parameters in order to see both images superposed images? thanks

share|improve this question
    
Take a look at the examples of Inset, including the one that displays a map and country information in a grid: reference.wolfram.com/mathematica/ref/Inset.html –  David Carraher Oct 22 '13 at 19:17
    
take a look at inset. Dont know if Cercle is a mispell or what.. you might want to fix that.. –  george2079 Oct 22 '13 at 19:21
    
similar question –  Vitaliy Kaurov Oct 22 '13 at 21:02

3 Answers 3

Similar to inset or show you can also use Overlay. Related questions might be this. or this.

s1 = Graphics[{RGBColor[{1, 0, 0}], Circle[{0, 1}]}]
model = ContourPlot[x^2 + y^2 - 1 == 0, {x, -2, 2}, {y, -2, 2}]
img = Import["http://i.stack.imgur.com/3ynJe.png"]

Overlay[{img, s1, model}]

enter image description here

share|improve this answer

You can try something like this I guess,

s1 = Graphics[{RGBColor[{1, 0, 0}], 
    Circle[{0, 0}, 1], {PointSize[.02], Point[{0, 0}]}}, 
   GridLines -> Automatic];
p1 = ContourPlot[x^2 + y^2 - 1 == 0, {x, -1, 1}, {y, -1, 1}, 
   GridLines -> Automatic, FrameStyle -> Directive[Orange, 12]];
ImageCompose[s1, {p1, 1}]

enter image description here

If Inset is used

Graphics[{{RGBColor[{1, 0, 0}], Circle[{0, 1}]}, 
  Inset[ContourPlot[x^2 + y^2 - 1 == 0, {x, -1, 1}, {y, -1, 1}, 
    Axes -> True]]}, Frame -> True, GridLines -> Automatic]

enter image description here

share|improve this answer
    
Thanks for your response, I know how Can I supperpose two graphics, we can use Show[],inset,... also. But in my case, I need to supperpose two images or an image and a graphics. I need to supperpose a reference image and a plotting of the model. –  phdstudent Oct 22 '13 at 19:59
    
with image you cannot control coordinates so how will you decide..? To measure relative size, you need frame of reference. –  Rorschach Oct 22 '13 at 20:02
    
OK!thanks, I will try again, surely, there is a solution! –  phdstudent Oct 22 '13 at 20:10

The trick to Inset..ing a raster is to supply the required offset/scale arguments:

   s1 = Graphics[{RGBColor[{1, 0, 0}], Circle[{1 - .05, .05}, 1]}, 
       PlotRange -> {{-2, 2}, {-2, 2}}];
   model = ContourPlot[(x - 1)^2 + y^2 - 1 == 0, {x, -2, 2}, {y, -2, 2}];
   imref = Rasterize[s1, ImageSize -> {400, 400}];
   Show[{Graphics[Inset[imref, {-2, -2}, {0, 0}, {4, 4}] ], model}, 
           PlotRange -> {{-3, 3}, {-3, 3}}]

This aligns the two circles (sorry I cant post graphics) by placing the "0,0" of the raster at the lower left of the range specified in the first graphics object, and scaling appropriately.

For some reason this looses the contour plot axes, but you can do within contourplot as a prolog:

ContourPlot[(x - 1)^2 + y^2 - 1 == 0, {x, -2, 2}, {y, -2, 2}, 
     Prolog -> Inset[imref, {-2, -2}, {0, 0}, {4, 4}],AspectRatio->Automatic]
share|improve this answer

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.