Show image for just one frame
Afficher commentaires plus anciens
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
Plus de réponses (1)
Cam Salzberger
le 23 Oct 2017
0 votes
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
le 23 Oct 2017
Modifié(e) : Walter Roberson
le 24 Oct 2017
Cam Salzberger
le 23 Oct 2017
Fair enough. I'll assume the photodetector has a sufficiently-high frequency.
How about the video generation workflow? Will this meet your needs?
Lask
le 24 Oct 2017
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.
Catégories
En savoir plus sur Video capture and display dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!