MATLAB: Imshow in GUI too slow

gui imshow imagesc image

Hello, I've made a GUI that displays a series of images (250×500, jpg) in a portion (usually 5-10) of 36 existing axes. The axes are in a special pattern (so can not use montage) and sometimes overlapping. I am using IMSHOW to match images with axes (and imshow with blank images to erase the axes). These get updated about every 3-5 seconds, but take 2-3 seconds to display. I would like to make it display as fast as possible.
I've experimented using IMAGESC instead, but it has not sped this up at all. I've tried all three renderers and put direct buffering to no avail.
I read a very old post that reccomended not changing the image on each axis, but rather keeping the image and changing the image data using set(himage, 'CData', newdata) where new data is your MxNx3 uint8. So that I would store the images as a matrix and only update the image data. I tried this but it wouldn't cooperate with how I've written my parent code.
Although I think this may work, it would take a week to reconstruct the parent code. Are there any other methods I can try to avoid this?

Best Answer

If performance is critical, you would do well to refresh the images via setting the 'CData' of each existing image handle rather than taking the performance hit of input parsing in imshow/imagesc and the performance hit of needing to recreate an HG image object each time you want to refresh an image.
If you are using subplot to layout the axes within your figure, you should be aware that subplot returns a handle to the axes being created/accessed.
hAxes = subplot(1,1,1);
hImage = imshow('pout.tif','Parent',hAxes);
Once you have created an HG image in a given axes using imshow, you can now refresh the 'CData' of the image object.
set(hImage,'CData',rand(200,200,3));
Note that if the size of the image data has changed, you will see alignment issues with your axes, there is no management of the position of the axes when you refresh the 'CData'.
This is all there is to what you're trying to do.