Show image for just one frame

3 vues (au cours des 30 derniers jours)
Lask
Lask le 23 Oct 2017
Commenté : Walter Roberson le 24 Oct 2017
Hi,
I want to do the following task in a loop for 100 times:
  • change image color to white during just one frame
  • change image color to black for 200 ms
  • go to start
So, every 200 ms the image is white for just one frame and black the rest of the time. I've written this code to achieve it:
% Create image
img = zeros(600, 600, 3, 'uint8');
% Get handle of the image
handle = imshow(img);
% Loop
for i = 1:1:100
set(handle,'CData',255*ones(600, 600, 3, 'uint8'))
drawnow;
set(handle,'CData',zeros(600, 600, 3, 'uint8'))
drawnow;
pause(0.2);
end
But this doesn't seem to change the color to white at anytime. I have V-Sync active.
Thanks in advance.

Réponse acceptée

Walter Roberson
Walter Roberson le 24 Oct 2017
For this kind of work you should use the third party Psychtoolbox, which does a lot of work to hook into retraces and the like.
  2 commentaires
Lask
Lask le 24 Oct 2017
Hi Walter,
is there any way to update an image so MATLAB doesn't give the control back until those changes are represented in the screen by the renderer?
Walter Roberson
Walter Roberson le 24 Oct 2017
Sorry, that is an internal that I do not know the answer to.

Connectez-vous pour commenter.

Plus de réponses (1)

Cam Salzberger
Cam Salzberger le 23 Oct 2017
It's tough to understand exactly what you mean by "one frame", as you're not exactly displaying a video here. You are giving no explicit time for the figure to appear as white, since there is no pause after that. Based on your other question, I'm assuming that by "one frame" you mean "one refresh cycle of your monitor".
My first question is how do you know that it is not turning white at any point? Our eyes can't all see at 60 Hz, and even if it did, it might not be immediately apparent if it's just one frame.
What I can recommend to provide more control over how the images are displaying is to actually create a video. Then you can control the FPS, and easily check to ensure that the white is display for exactly one frame. Check out VideoWriter and related examples to see how to do this.
There are a few different ways that you can play videos in MATLAB - frame by frame, VideoViewer, implay - or you can just play it in your local system's video playback program.
-Cam
  4 commentaires
Lask
Lask le 24 Oct 2017
Hi Cam,
the issue is, I don't understand why in:
set(handle,'CData',255*ones(600, 600, 3, 'uint8'))
tic
drawnow;
toc
the toc takes less than 16.7 ms, which is the time interval associated to a frecuency of 60 Hz, having said, I have activated vertical sync in my computer.
Best regards.
Walter Roberson
Walter Roberson le 24 Oct 2017
"You initiate an update by calling the drawnow function. drawnow completes execution when the renderer accepts the updates, which can happen before the renderer completes updating the screen. "
So you are timing how long it takes the renderer to accept the updates, not how long it takes for the update to appear.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by