MATLAB Answers

How can I make image objects update faster in MATLAB?

88 views (last 30 days)
I am modifying the "CData" property of an image object multiple times. However, updating the image seems to take a long time.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 17 May 2011
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:
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:
set(gca, 'xlimmode','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".
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:


Sign in to comment.

More Answers (1)

Mahmood Haithami
Mahmood Haithami on 10 Feb 2018
I am using "imshow" for every change in the image instead of CData. it is much faster For example you can write:
>>image1 = imread('example.tif');
>>image2 = imread('example2.tif');
>>change(image1); % this function change the image
>>figure(1), imshow(image1);
>>figure(2), imshow(image2);


Sign in to comment.


Community Treasure Hunt

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

Start Hunting!