フィルターのクリア

imshow displays black instead of transparent background of png image

12 ビュー (過去 30 日間)
Denis Perotto
Denis Perotto 2024 年 2 月 7 日
コメント済み: Joshua 2024 年 3 月 22 日
I need to display a .png image that has transparent background in a figure. I also need to change the transparency of its solid part. I tried to do it using imshow like this:
figure
hold on
plot([1 2], [1 2])
axes("pos",[.1 .1 .1 .1])
foo = imshow("some_image.png");
foo.AlphaData = 0.8;
The problem is that the transparent background of my .png becomes solid black on figure. How to fix it?

採用された回答

Walter Roberson
Walter Roberson 2024 年 2 月 7 日
figure
hold on
plot([1 2], [1 2])
axes("pos",[.1 .1 .1 .1])
[myimage, cmap, alpha] = imread("some_image.png");
foo = imshow(myimage, cmap);
foo.AlphaData = alpha;
  2 件のコメント
Denis Perotto
Denis Perotto 2024 年 2 月 7 日
Thanks, it works, except for the last line should be
foo.AlphaData = 0.8 .* alpha;
Joshua
Joshua 2024 年 3 月 22 日
I would like to thank you for all of your responses throughout the years. I am new to MATLAB, but not new to coding, and you have made learning this language exponentially easier with your consistent, accurate tips. Your comment here is just +1 to the massive amount of times you have helped me in my project. Take care!

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by