how to put all the png image properties?
    3 views (last 30 days)
  
       Show older comments
    
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 Comments
  Geoff Hayes
      
      
 on 24 Apr 2016
				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?
Answers (1)
  Walter Roberson
      
      
 on 10 May 2016
        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.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


