how to put all the png image properties?

조회 수: 1 (최근 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.

Community Treasure Hunt

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

Start Hunting!

Translated by