Effacer les filtres
Effacer les filtres

Change white pixels to invisible

4 vues (au cours des 30 derniers jours)
Jacob L
Jacob L le 26 Nov 2020
Commenté : Matt J le 26 Nov 2020
Hi, I have a .png I'm trying to overlay on top of an existing figure in matlab. Most of the image is just a white background. Is it possible to overlay everything but the white background from the .png to the existing figure? In other words, can I make the white background transparent/invisible?
The image is RGB 'unit8'. When I do this:
alphachannel = all(image == 255, 3);
imwrite(image,'invisible.png','Alpha',alphachannel);
This error comes up:
Error using writepng>parseInputs (line 349)
The value of 'alpha' is invalid. Expected input to be one of these types:
double, uint8, uint16
Instead its type was logical.
When I do this:
alphachannel = double(all(image ~= 255, 3));
imwrite(image,'invisible.png','Alpha',alphachannel);
The .png file appears to have the invisible pixels instead of the white pixels, but ,when I try to overlay the new .png on top of the existing figure in matlab, the "invisible" background is black. Is there anything I can do? Any help is appreciated, thanks.

Réponses (1)

Matt J
Matt J le 26 Nov 2020
Modifié(e) : Matt J le 26 Nov 2020
Shouldn't you have
alphachannel = 1-double(all(image == 255, 3));
  3 commentaires
Matt J
Matt J le 26 Nov 2020
I recommend you attach all images so we can play with them.
Jacob L
Jacob L le 26 Nov 2020
Okay - here is a summary of what's going on:
Starting with the Teddy_Bear.png
Then using
teddyBearProcessed = padarray(image,[1000,1000],255,'post');
to get Teddy_Bear_Padded.png
Then using
shiftedTeddy = imtranslate(image,[150, 150],'FillValues',255);
to get Teddy_Bear_Shifted.png
Then using
alphachannel = 1-double(all(image == 255, 3));
imwrite(image,'invisible.png','Alpha',alphachannel);
to get Teddy_Bear_Invisible.png
In the meantime I have another figure open in MATLAB. The output of the figure is saved in the attached as Stationary_Teddy_Centroid.png.
Then using
hold on
imshow('Teddy_Bear_Invisible.png');
to get problem.png.
What I'm trying to do is move the teddy bear on the screen so I can see the the path it takes. Kind of like how the path of the arm is seen in Stationary_Teddy_Centroid.png.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Lighting, Transparency, and Shading dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by