How can I make image objects update faster in MATLAB?
29 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2011-5-17
编辑: MathWorks Support Team
2022-10-14
I am modifying the "CData" property of an image object multiple times. However, updating the image seems to take a long time.
采纳的回答
MathWorks Support Team
2022-10-14
编辑:MathWorks Support Team
2022-10-14
Here are some suggestions on how to make image objects update faster in MATLAB:
1. Use the smallest datatype possible. Using a "uint8" datatype for your image will be faster than using a "double" datatype. Part of the process of setting the image's "CData" property includes copying the matrix for the image's use. The overall size of the matrix is dependent on the size of its individual elements. Using smaller individual elements (i.e. a smaller datatype) will make the matrix itself smaller and decrease the amount of time needed to copy the matrix.
2. Use the smallest acceptable matrix. If the speed at which the image is displayed is your highest priority, you may need to compromise on the size and quality of the image. Again, decreasing the size will reduce the time needed to copy the matrix.
3. Make the axes exactly the same size (in pixels) as the matrix in the "CData" property. This will eliminate the need for interpolation, since there should be a one-to-one correspondence between the data and the onscreen pixels. For example:
set(gca,'Units','pixels')
pos = get(gca,'Position')
width = pos(3);
height = pos(4);
The size of your "CData" should be exactly equal to "[width height]", so each element of the array corresponds directly to a pixel. Otherwise, MATLAB must interpolate the values in the "CData" array, so it will fit onscreen.
4. Set the limit mode properties ("XLimMode", "YLimMode") of your axes to "manual". If they are set to "auto", then every time an object (such as an image, line, patch, etc) changes some aspect of its data, the axes must recalculate its related properties. For example, use something like this:
image(firstimage);
set(gca, 'xlimmode','manual',...
'ylimmode','manual',...
'zlimmode','manual',...
'climmode','manual',...
'alimmode','manual');
Now the axes will not recalculate any of the limit values before redrawing the image.
5. Set the figure's "DoubleBuffer" property to "off".
set(gcf,'doublebuffer','off');
The "DoubleBuffer" property should be "on" for flicker-free animation. However, for the purposes of raw speed, it should be set to "off".
6. Alternately, you may want to consider using a movie object if the main point of your task is to simply display a series of images onscreen. The MATLAB movie object utilizes the underlying system graphics resources directly, instead of going through MATLAB object code. This is faster than repeatedly setting an image's "CData" property. See the documentation for the MOVIE function for more information on its use:
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Properties 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!