0

I am trying to overlay one image on top of another in MATLAB.

I checked out Superimpose two images in MATLAB for an answer. But the issue is that the overlayed images are being shown as blue boxes on the original image, instead of the actual image.

The incorrect output is shown here https://i.stack.imgur.com/7tH3Q.jpg.

The code I am using is

    a = 0.2;
    tform = affine2d([1 0 0; a 1 0; 0 0 1]);
    B = imwarp(z,tform, 'FillValues',255);
    B = ~B;
    figure; imshow(B);
    h = imagesc([X1 X2], [Y1 Y2], B);
    set(h, 'AlphaData', 1);

The normal imshow(B) shows me the correct image but the overlaying part is giving me the problem.

I have tried changing the value of AlphaData but that doesn't seem to be working.

Community
  • 1
  • 1
Kanishka Ganguly
  • 1,252
  • 4
  • 18
  • 38

1 Answers1

1

Have a look to function imshowpair with properties Blend

You can try this too :

figure;
h = imshow(FirstImage);
set(h,'AlphaData',0.2);

hold on;
imshow(SecondImage);    
hold off;
Vuwox
  • 2,331
  • 18
  • 33
  • I saw that function, looked quite interesting. But the thing is, I have multiple images being generated in a loop and they are being superimposed onto the original image. How can I achieve that with `imshowpair`? – Kanishka Ganguly Jun 04 '14 at 20:02
  • Like if you have 3 images to overlay? – Vuwox Jun 04 '14 at 20:03
  • Yeah, and the position for each new image needs to be set, as can be seen in my original code. – Kanishka Ganguly Jun 04 '14 at 20:03
  • Maybe you can try to call multiple time imshowpair ? Like this : `figure;imshowpair(im,im2); I = getframe; figure;imshowpair(im3,I.cdata);` – Vuwox Jun 04 '14 at 20:06
  • Thing is, I don't know how many times I will need to call `imshowpair` since the loop is dynamic, based on input. Also, how can I set the position of the superimposed image? – Kanishka Ganguly Jun 04 '14 at 20:08
  • You'll need to provide a code sample and maybe a bit more information. Because Its starting to be a more specific problem. – Vuwox Jun 04 '14 at 20:10
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/55088/discussion-between-kanishka-ganguly-and-alexandre-bizeau). – Kanishka Ganguly Jun 04 '14 at 20:11
  • This works fine but how can I set the position of `h` on the `FirstImage`? – Kanishka Ganguly Jun 04 '14 at 20:33
  • Just catch the handle on first image instead of the second. I'll edit. – Vuwox Jun 04 '14 at 21:44