Combine images in matlab with transparency
Afficher commentaires plus anciens
Hi could anyone among you give me the code on how to combine images
If this is Image(A)

& this is Image(B)

so is it possible to create an image like the one shown below in MATLAB (produced using photoshop) I yes, pease tell me how as i want the appe only to show and the rest to be fully balck or white thanks

Réponse acceptée
Plus de réponses (3)
Joseph Cheng
le 19 Avr 2014
Modifié(e) : Joseph Cheng
le 19 Avr 2014
If you have the 2nd image (background 0's and apple areas 1) lets call that MASK, and let's call the apple image APPLE.
JustApple = zeros(size(APPLE));
JustApple(MASK) = APPLE(MASK);
if MASK is type logical then above will work. If MASK is not logical and just a matrix of 1s and 0s then JustApple(logical(MASK)) = APPLE(logical(MASK));
3 commentaires
Saqib
le 20 Avr 2014
Image Analyst
le 20 Avr 2014
His code assumes you have the mask already . My code shows you how to get the mask. It displays the mask for you to see in the lower middle, and it also gets the "JustApple" image as you can see from the lower right image in my screenshot.
Saqib
le 20 Avr 2014
Saqib
le 19 Avr 2014
0 votes
#
Suppose:
# A=Name1.bmp;
J = imread(A);
I=rgb2gray(J);
[sz1,sz2]=size(I);
K=zeros(sz1,sz2);
for a=1:2:sz1
for b=1:2:sz2
M=I(a:a+1,b:b+1);
if sum(M(:))>=1000 %I chose white, but you may choose whatever color you want
K(a:a+1,b:b+1)=255;
end
end
end
set(gcf,'Color','None')
# B=Name2.tiff; % (transparent, obtained like Jonas
( <https://stackoverflow.com/questions/13660108/matlab-how-to-save-tiff-with-transparency-or-png-with-no-compression> ) but change "ch" with "K"
#
# Then:
# testbmp=imread('Name1.bmp');
# testtiff=imread(Name2.tiff');
# testbmp(:,:,4)=testtiff(:,:,4);
# imwrite(testbmp,'transparent_fusion.tiff');
1 commentaire
Image Analyst
le 7 Sep 2014
Horia, we have no idea what this is. Please start a new discussion on it and paste the link back here.
Catégories
En savoir plus sur Image Processing Toolbox dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
