Using indexing to superimpose images:

2 views (last 30 days)
Hello, I was wondering if someone could help me. I am trying to superimpose images so that both images are visible. I have found the perfect example at the address below. I am using second lot of code (using indexing) as i want a single image as a result that is easily saved.
I have simply cut and paste the code from section 2 but it does not seem to work. There is no error and a figure is displayed with the images but it looks like the images have been overlayed without any of the pixels from the underlying image showing through.
Just wanted to see if this example has worked for others or maybe something is wrong at my end.
I am using matlab 7.1 with the image processing toolbox
Regards Dana

Accepted Answer

Amith Kamath
Amith Kamath on 2 Nov 2011
From the description on the link you posted:
Use this method if you have an image that you want to place in a scene, but prefer to have only a single image as a resultant. The following example achieves this by replacing the scene pixels with the object image pixels.
So I'm guessing it is doing what it is meant to do! but if you want the underlying pixels to be shown too, you need to edit:
result((1:size(obj,1))+rowshift, (1:size(obj,2))+colshift, :) = 0.25.*obj + 0.25.*scene((1:size(obj,1))+rowshift, (1:size(obj,2))+colshift, :);
in the part where result is assigned the pixel values. Note that the 0.25 scaling is just so that the index values don't go > 1.
Hope this helps!
  1 Comment
Dana
Dana on 2 Nov 2011
Hello Amith, Thanks for the response that is exactly what i wanted. I was unsure why the underlying pixels were not showing but this solution solves it. Thanks
Regards Dana Post

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!