1
votes

I'm trying to alpha blend a couple of images, but I'm running into a few problems. I'm kind of developing somebody else's code, so I apologize in advance for possibly not making sense, but I'll be as clear as possible.

Originally we made two different plots containing 1 image in each. For the first image, the plot is made by creating the figure and then doing the following:

%part of initializing the figure
Fig.figim=image(double(zeros(RGBparam.height, RGBparam.width,3)));
...
%later we have a loop, then we do:
set(Fig.figim, 'CData', imresize(RGBparam.image,[RGBparam.height, RGBparam.width]);

where the size of the image (RGBparam.image) is 720x1280x3

For the second image, we do the exact same initilization of the image (except 1 part which I'll put below) and do the following:

%the only different in initialization of the figure
Fig.figim=imagesc(double(zeros(RGBparam.height, RGBparam.width)));
...
%and here is the same loop again
set(Fig.figim, 'cdata', outImage)

where the size of the image (outImage) is 720x1280. Notice the difference between the dimensions...one is a 2-D matrix and another is a 3-D matrix (although note, it's still a 2-D image, it just has those 3 extra dimensions for the RGB colors). I guess I just don't know how to deal with this when I go about alpha blending. I'm guessing I'm going to want to combine the images before plotting them, alpha blending before and then just plotting the final figure. I don't know how to go about this though, since for my first image it's 3-D and includes the RGB channels, where my second figure does not! Any help giving the next steps in the process of alpha blending these two images, and then plotting them would be great. Thanks!

1
Are you sure it is 3D not that the 3 is not to provide space for RGB and the other image is monocrome?Steve Barnes
Sorry, you are completely right. I didn't necessarily mean the image was 3-D, I just meant that it was a 2-D image and the RGB colors have been split into different dimensions. So yeah, it's exactly what you are saying. I still don't know how to deal with this difference though.spaderdabomb
I think I can just create an RGB image out of the monocrome so they have the same dimensions....spaderdabomb
You can either copy the second, monochrome image 3 times into a H x W x 3 array - (this will make it grey scale) or into a singe channel, (plane), of the one - that will make it one of R, G or B. To do true alpha blending you will need to make both of them RGBA and set an alpha valueSteve Barnes

1 Answers

1
votes

If you have the image processing toolbox, matlab offers

C = imfuse(A,B,'blend')

that overlays images A and B using alpha blending.

For example, the following code (please note the getframe function),

h = figure('Color','w');

ha = subplot(1,3,1); image(rand(720, 1280,3)); Fa = getframe(ha);

hb = subplot(1,3,2); imagesc(ones(720, 1280)); Fb = getframe(hb);

subplot(1,3,3); C = imfuse(Fa.cdata,Fb.cdata,'blend'); imshow(C)

will produce

enter image description here