Show image for just one frame
    3 ビュー (過去 30 日間)
  
       古いコメントを表示
    
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.
0 件のコメント
採用された回答
  Walter Roberson
      
      
 2017 年 10 月 24 日
        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 件のコメント
その他の回答 (1 件)
  Cam Salzberger
      
 2017 年 10 月 23 日
        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 件のコメント
  Walter Roberson
      
      
 2017 年 10 月 24 日
				"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.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!