7
$\begingroup$

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

$\endgroup$
3
  • $\begingroup$ 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 $\endgroup$
    – DavidC
    Commented Oct 22, 2013 at 19:17
  • $\begingroup$ take a look at inset. Dont know if Cercle is a mispell or what.. you might want to fix that.. $\endgroup$
    – george2079
    Commented Oct 22, 2013 at 19:21
  • $\begingroup$ similar question $\endgroup$ Commented Oct 22, 2013 at 21:02

3 Answers 3

2
$\begingroup$

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["https://i.sstatic.net/3ynJe.png"]

Overlay[{img, s1, model}]

enter image description here

$\endgroup$
1
$\begingroup$

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]
$\endgroup$
0
$\begingroup$

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

$\endgroup$
3
  • $\begingroup$ 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. $\endgroup$
    – phdstudent
    Commented Oct 22, 2013 at 19:59
  • $\begingroup$ with image you cannot control coordinates so how will you decide..? To measure relative size, you need frame of reference. $\endgroup$ Commented Oct 22, 2013 at 20:02
  • $\begingroup$ OK!thanks, I will try again, surely, there is a solution! $\endgroup$
    – phdstudent
    Commented Oct 22, 2013 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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