开发者

How to unblend two images from a blend image

开发者 https://www.devze.com 2023-01-03 13:14 出处:网络
I have 开发者_开发技巧blended/merged 2 images img1 and img2 with this code which is woking fine.What i want to know is how to obtain the original two images img1 and img2.The code for blending is as u

I have 开发者_开发技巧blended/merged 2 images img1 and img2 with this code which is woking fine.What i want to know is how to obtain the original two images img1 and img2.The code for blending is as under

img1=imread('C:\MATLAB7\Picture5.jpg');
img2=imread('C:\MATLAB7\Picture6.jpg');
for i=1:size(img1,1)
  for j=1:size(img1,2)
    for k=1:size(img1,3)
      output(i,j,k)=(img1(i,j,k)+img2(i,j,k))/2;
    end
   end
end
imshow(output,[0 255]);


You could recover the 2nd image if you had one original image plus the blended image.

If you have only the blended image there are a near infinite number of img1 and img2 that could have been combined to create the two images so you can't recover them.

For future matlab programming, note that in matlab you don't need the loops that you've written, this is equivialnt to the code you gave:

img1=imread('C:\MATLAB7\Picture5.jpg');
img2=imread('C:\MATLAB7\Picture6.jpg');
output = (img1 + img2) ./ 2;
imshow(output,[0 255]);


If you blend the images like this:

img1=imread('C:\MATLAB7\Picture5.jpg');
img2=imread('C:\MATLAB7\Picture6.jpg');
blendedImg = (img1/2 + img2/2); % divide images before adding to avoid overflow

You can get back img1 from the blended image (with maybe some rounding errors) if you have img2

img1recovered = 2*(blendedImg - img2/2);

figure,subplot(1,2,1)
imshow(img1,[0 255])
subplot(1,2,2)
imshow(img1recovered,[0 255])
0

精彩评论

暂无评论...
验证码 换一张
取 消