سؤال

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!

هل كانت مفيدة؟

المحلول

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top