how to put all the png image properties?

4 ビュー (過去 30 日間)
dafniz91
dafniz91 2016 年 4 月 22 日
コメント済み: dafniz91 2016 年 5 月 10 日
Hello, this is my first post here, although I've been using matlab for a while. Here is my problem and I hope someone could help me : I want to show some PNG images on axes, within a GUI. I've managed to show it but some colors is changed. This is the original PNG image:
and in the axes I get this:
when I have this code:
axes(handles.walkonly);
elderlywalking= imread('elderlywalking.png');
Wonly=imshow(elderlywalking);
set(Wonly, 'AlphaData', elderlywalking(:,:,1));
The sky picture that you can see on the "background", is set for me, as a background of the whole project, so I prefer to not change it. I thought that may be I'm missing some of the original image datas. So I tried the next code:
% % % axes for "walkandcar" option% % %
axes(handles.walkANDcar);
[walkandcar, ~, alpha] = imread('walkandcar.png');
% walkandcar= imread('walkandcar.png');
WandC=imshow(walkandcar);
set(WandC, 'AlphaData', walkandcar(:,:,1));
but I keep on having the same image. From what I've been looking, combining the image can be an option, but I prefer to work on the axes and not as a single combined picture, because those images are the representation of an icon to be selected afterwards...
How can I solve it? Is it easier to combine the images ? thank you!
  2 件のコメント
Geoff Hayes
Geoff Hayes 2016 年 4 月 24 日
dafniz91 - what are you calling the line of code
set(Wonly, 'AlphaData', elderlywalking(:,:,1));
as this adds transparency to your graphics object (see Add Transparency to Graphics Objects for details. What happens if you remove this line of code?
dafniz91
dafniz91 2016 年 5 月 10 日
編集済み: Walter Roberson 2016 年 5 月 10 日
hi Geoff I thought that I replied your comment but I think it didn´t load...
so sorry for my absense. I tried what you suggest but no results.... i got this image by adjusting transparency with different values.
as you can see it added "transparency" effectively, but that not what I want and also it added the black background.
do you have another idea of what can be done?
sorry for my english.
dafniz91

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

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 5 月 10 日
You need to create an ROI from the image that excludes the white parts. Then you need to fill the holes in that ROI using imfill('holes'), like
BW = imfill(BW, 'holes');
and then
fg_alpha = double(BW);
Then
image(BackgroundImage)
hold on
image(ElderlyMatrix, 'AlphaData', fg_alpha)
this will use everything within the ROI as-is, but everything outside the ROI will show through the background image.
  1 件のコメント
dafniz91
dafniz91 2016 年 5 月 10 日
thank you! I will try that.

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

Community Treasure Hunt

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

Start Hunting!

Translated by