'fill' and 'image' incompatible

13 次查看(过去 30 天)
This demonstrates my previous question(<http://www.mathworks.com/matlabcentral/answers/6749-graphic-ghost)>, now with real code.
There is a wrong behaviour when I mix 'fill' and 'image' on the same plot.
This is demonstrated by the following code.
clc
close all
clear all
axis([-5 200 -5 200]);
axis square;
hold on
for pos=120:200
a=fill([10 10 0 0]+pos/2,[10 0 0 10]+pos/2,'r');
b=image([pos pos+40],[pos pos+40],rand(40)*100,'AlphaData',0.5*ones(40));
drawnow
if ishandle(b)
delete(a);
delete(b);
end
end
In Matlab r2010b the random color image will disapear as soon as it touch the axis(plot border). I can see only a thin line on the edge of the image. If you comment the 'a=fill...' and 'delete(a)' lines, it will work as expected. I tried to generate a animated gif with this, but it showed another bug, that I had complained previously. If you look at http://geodac.di.ubi.pt/nuno/bug1.gif you will see the 'fill' moving without the 'image'. When I add the image, at http://geodac.di.ubi.pt/nuno/bug2.gif, everything freezes on the first position. That means frame = getframe(1); only gets the first frame after the image was inserted, and the transparency seems to have been applied to the entire image.
This bug only appears when 'AlphaData' is used. Opaque images work fine!

采纳的回答

Patrick Kalita
Patrick Kalita 2011-5-4
The problem generating the movie is a known issue, documented here: http://www.mathworks.com/support/bugreports/384622. It mentions Windows Vista, but it also seems to occur on Windows 7.
The original issue of the image not showing up correctly could be a bug. I would recommend contacting support about it.
In just playing around with your example, it looks like perhaps swapping the order in which the image and the fill are created could be a workaround. Compare this ...
axis([-5 200 -5 200]);
axis square;
hold on
pos=160;
a=fill([10 10 0 0]+pos/2,[10 0 0 10]+pos/2,'r');
b=image([pos pos+40],[pos pos+40],rand(40)*100,'AlphaData',0.5*ones(40));
...and this...
axis([-5 200 -5 200]);
axis square;
hold on
pos=160;
b=image([pos pos+40],[pos pos+40],rand(40)*100,'AlphaData',0.5*ones(40));
a=fill([10 10 0 0]+pos/2,[10 0 0 10]+pos/2,'r');
  1 个评论
Nuno
Nuno 2011-5-4
Thanks for your answer.
Your workaround might work on this case but not in real life...That is because I don't delete the objects for performance reasons, so both 'image' and 'fill' objects are updated after they are created, so it's not possible to never change the 'image' after the 'fill' is created.

请先登录,再进行评论。

更多回答(1 个)

Nuno
Nuno 2011-5-4
This bug doesn't exist on the UNIX version. Probably only Win Vista and Win 7.

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by