what does an handle for imshow mean

4 views (last 30 days)
Adithya Chakilam
Adithya Chakilam on 17 Jan 2017
Answered: Image Analyst on 17 Jan 2017
What does this line mean? This is described as "Create a handle to an imshow figure for faster updating", but how?
hShow = imshow(zeros(480,640,3,'uint8'));
title('Security Camera');
  2 Comments
Stephen23
Stephen23 on 17 Jan 2017
Edited: Stephen23 on 17 Jan 2017
"but how"
How what ?
Adam
Adam on 17 Jan 2017
Faster updating comes from the fact you get a handle to the image object and you can then change individual properties of this (e.g. CData) rather than replotting the whole image if you are making changes to it.

Sign in to comment.

Answers (2)

Image Analyst
Image Analyst on 17 Jan 2017
The handles, hShow, is used here:
set(hShow,'CData',object_detected);
By changing just the CData, which is the pixels themselves, you can update the screen much faster than calling imshow(). imshow() does some overhead (setting magnification, etc.) that slows down the process. This will not be noticeable for just a single call to imshow() but if you are doing it in real time -- video at 30 frames per second -- using imshow() will be noticeably slower than setting the CData property to the updated pixel array.

Stephen23
Stephen23 on 17 Jan 2017
Edited: Stephen23 on 17 Jan 2017
According to the imshow documentation this syntax:
himage = imshow(___) returns the image object created by imshow.
If you do not know what graphics objects are, and how to use their handles, then you can learn about them in the documentation:
You will also find hundreds of tutorials online that introduce and explain graphics handles.
  2 Comments
Adithya Chakilam
Adithya Chakilam on 17 Jan 2017
hey stephen, why dose he take time to add that line to the code when he can execute simply without that line. can you just say me the work done that by line?
Stephen23
Stephen23 on 17 Jan 2017
Edited: Stephen23 on 17 Jan 2017
@Adithya Chakilam: aha, I think understand your question now: you want to know how this line speeds up the code (as the code comment states).
The answer is: it doesn't.
But that handle can be used later in the code to speed up the code quite a lot.
The handle to a graphics object (in this case an image object) can be used to access this object and change its properties. Changing the object properties is faster than calling imshow again, or calling other functions to change how this image is displayed. For example, you might plot some lines:
plot(X,Y)
and want to do this thousand of times in your code. It would be slow to call plot each time. Much faster would be to call plot once and return a handle to the line objects:
H = plot(X,Y);
and then later update the line data points:
set(H,'XData',1:3,'YData',[0,1,0])
You will learn more about this by reading the documentation links that I gave in my answer. For fast and robust code it is recommended to use graphics handles explicitly for every graphics operation: generating figures, axes, lines, etc. using the Parent property. For example do not simply call functions that assume the desired axes are the current axes.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!