MATLAB Answers

0

How can I make image objects update faster in MATLAB?

I am modifying the "CData" property of an image object multiple times. However, updating the image seems to take a long time.

Products

2 Answers

Answer by MathWorks Support Team on 17 May 2011
 Accepted Answer

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 Comments

Sign in to comment.


Answer by 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);
>>change(image2);
>>figure(2), imshow(image2);

  0 Comments

Sign in to comment.