フィルターのクリア

Change white pixels to invisible

4 ビュー (過去 30 日間)
Jacob L
Jacob L 2020 年 11 月 26 日
コメント済み: Matt J 2020 年 11 月 26 日
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.

回答 (1 件)

Matt J
Matt J 2020 年 11 月 26 日
編集済み: Matt J 2020 年 11 月 26 日
Shouldn't you have
alphachannel = 1-double(all(image == 255, 3));
  3 件のコメント
Matt J
Matt J 2020 年 11 月 26 日
I recommend you attach all images so we can play with them.
Jacob L
Jacob L 2020 年 11 月 26 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLighting, Transparency, and Shading についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by