Sign up Calendar Latest Topics
 
 
 


Reply
  Author   Comment  
aboharbf

Member
Registered:
Posts: 68
Reply with quote  #1 
I'd like to try showing shorter durations of a video instead of the whole thing. To achieve that, I attempted the following:

I turned this:

fix2 = SingleTarget(eye_);
fix2.Target = sample;
fix2.Threshold = fix_rectangle;
lh2 = LooseHold(fix2);
lh2.BreakTime = break_time;
lh2.HoldTime = sample_time;
sample_scene = create_scene(lh2, sample);

Into This:

rewind_movie(sample, stim_start) %move the stimulus to the right start time
fix2 = SingleTarget(eye_);
fix2.Target = sample;
fix2.Threshold = fix_rectangle;
lh2 = LooseHold(fix2);
lh2.BreakTime = break_time;
lh2.HoldTime = sample_time;
tc = TimeCounter(null_);
tc.Duration = stim_dur;
and = AndAdapter(lh2);
and.add(tc)
sample_scene = create_scene(and, sample);
%sample_scene = create_scene(lh2,sample);

I also switched the case the run scene from aborting if ~lh2.Success, to ~and.Success

Now when I break fixation in simulation mode, the video keeps playing and the trial doesn't fail until my cursor returns to the fixation box. This seems odd. This continues to happen even when the ~lh2.Success is returned, which seems odd. Is there something obvious I'm doing wrong? 

0
Jaewon

Administrator
Registered:
Posts: 727
Reply with quote  #2 
You combined LooseHold and TimeCounter with AndAdapter.

AndAdapter does not stop until both adapters succeed.
ftp://helix.nih.gov/lsn/monkeylogic/ML2_doc/runtimefunctions.html#AndAdapter

LooseHold succeeds when the fixation is maintained for HoldTime.
ftp://helix.nih.gov/lsn/monkeylogic/ML2_doc/runtimefunctions.html#LooseHold

TimeCounter succeeds when Duration has elapsed.
ftp://helix.nih.gov/lsn/monkeylogic/ML2_doc/runtimefunctions.html#TimeCounter

Therefore, your scene (and movie) stops when the fixation is held for sample_time AND stim_dur is passed, which perfectly matches the behavior you described.

run_scene is not aborted by the if statement. It ends when the stop condition of the adapter provided to create_scene (i.e., AndAdapter in your case) is satisfied.

Now the question is do you want to present the movie for stim_dur, whether the fixation is broken or not? Or do you want to stop the movie as soon as the fixation is broken?
0
aboharbf

Member
Registered:
Posts: 68
Reply with quote  #3 
I want the movie to stop as soon as fixation breaks (or more accurately, as soon as LooseHold fails), but I also want the movie to play for a particular duration and then stop. I'm calling on the entire .avi file and I saw this combination as the best way to play a segment of video from a larger file.
0
Jaewon

Administrator
Registered:
Posts: 727
Reply with quote  #4 
There is still one thing that your description is not clear about. You assigned two different values (sample_time and stim_dur) to the HoldTime of LooseHold and the Duration of TimeCounter. I understand you want to show the movie for stim_dur, but how long do you want to hold fixation, if it is not broken?

For example, if you want to show the movie for 5 sec and the HoldTime is 3 sec, is the scene supposed to stop after 3 sec or 5 sec?
0
aboharbf

Member
Registered:
Posts: 68
Reply with quote  #5 
Ahh Apologies. These two values should match. I want the animal to fixate for the entirety of the video presented. The movie file itself may be 5 seconds long, but if I use the rewind function to move it to 1 second in, and stim_dur is 3 seconds, than I'd want to the animal to fixate for the entire 3 seconds which I display. I think the reason I had two variables was because I was afraid that the Loosehold function would allow for variability in the length of the stimulus display I didn't want (for example if the fixation was broken for 200 ms, and came back, the video shown would actually be 3.2 seconds, not 3). I figured this would be the correct way to go about that - thinking the and adapter would fail the moment either of its components failed (since once one of them fails, the whole statement is false immediately).
0
Jaewon

Administrator
Registered:
Posts: 727
Reply with quote  #6 
LooseHold does allow some variability in the length of the stimulus display because its time unit is milliseconds, not because of the BreakTime.

Let's say you want to hold fixation for 1 sec. If the refresh rate is 60 Hz, you know that the 1-sec time is up after 60 frames are presented. Then you stop the scene, but you are already in the 61st frame, so the scene ends after 61 frames.

Here is another pitfall. When run_scene stops, it deactivates the movie but does not present the frame in which the movie is removed, in case that you want to present the same stimulus at the same place continuously in the next scene. So you can present a blank frame or run the next scene to overwrite the movie, which will be shown at the end of the 62nd frame. Therefore, the movie will stay on the screen for 62 frames, if you assign 1000 ms to the HoldTime.

In your case, it is not LooseHold that determines the scene duration, if fixation is not broken. So you can control the length of the movie precisely. You just need to use FrameCounter, instead of TimeCounter. FrameCounter takes into account what I just said above and finishes the scene two frames earlier than the given duration.
0
Edward

Administrator
Registered:
Posts: 251
Reply with quote  #7 
Hello aboharbf,

I looked at your post today. If you are still having trouble, I believe the following code fragment will help you:

rewind_movie(sample, stim_start) %move the stimulus to the right start time
fix2 = SingleTarget(eye_);
fix2.Target = sample;
fix2.Threshold = fix_rectangle;
lh2 = LooseHold(fix2);
lh2.BreakTime = break_time;
lh2.HoldTime = sample_time;
tc = FrameCounter(null_);
tc.Duration = stim_dur;
dpt = OrAdapter(lh2);
dpt.add(tc)
sample_scene = create_scene(and, sample);

The Or adaptor allows the trial to terminate prematurely if lh2, or loose fixation, fails; otherwise the movie in the trial will be played for a specific duration. I think this is what you hope to achieve right? Let me know if you have any questions.

======

Edit:
aboharbf, I'm sorry there's a minor bug in the code I posted before. The code I presented before does indeed end the trial when loose fixation is broken, but if the subject does not break fixation, then it only ends when HoldTime of LooseHold is up, not when FrameCounter is done. It will not matter in your experiment if your HoldTime is smaller or equal to the timer in FrameCounter, but if your HoldTime is longer then the code will not behave as expected. Following is an updated, more robust code thanks to Jaewon:

rewind_movie(sample, stim_start) %move the stimulus to the right start time

fix2 = SingleTarget(eye_);

fix2.Target = sample;

fix2.Threshold = fix_rectangle;

lh2 = LooseHold(fix2);

lh2.BreakTime = break_time;

lh2.HoldTime = sample_time;

stop2 = GetStopStatus(lh2);

tc = FrameCounter(null_);

tc.Duration = stim_dur;

dpt = OrAdapter(stop2);

dpt.add(tc)

sample_scene = create_scene(dpt, sample);

run_scene(sample_scene);

0
aboharbf

Member
Registered:
Posts: 68
Reply with quote  #8 
Hey Edward,

I gave this a shot and it works great. Thanks a ton. I am now trying to present individual movie frames without creating .pngs outside. I figure there must be some way to put on a movie and freeze it to create this effect but I've yet to find it. If you've got any suggestions I'd greatly appreciate them.

0
Edward

Administrator
Registered:
Posts: 251
Reply with quote  #9 
Unfortunately I don't think there is any built-in functionality for what you described. Since extracting and presenting individual movie frames is a pretty standard way to do it, I'm actually curious about what are your concerns using the standard method?
0
aboharbf

Member
Registered:
Posts: 68
Reply with quote  #10 
It mostly has to do with not created a huge library of frames in the process of displaying them. I will see if I can put it into the ML code.

I got the impression once something was loaded as a "TaskObject", It wouldn't be good to manipulate. I may be able to integrate this functionality into the userloop file, by creating introducing variables in the timing file which act as switches ('playFrames = 1'), and then having the userloop file read this switch, then process the movies (load, pull frame, save), THEN reading them in with the 'pic' argument. I was worried this would lead to significant increases in ISI, but if I make it persistant perhaps not.
0
Edward

Administrator
Registered:
Posts: 251
Reply with quote  #11 
Correct, you cannot manipulate a TaskObject once it is loaded. If you really do not want to create a set of movie frame image files, then yes you need to go through the complications as you described. I believe you need to load the movie files and process them with VideoReader() and readFrame() Matlab functions to extract your desired frame, save it as an image file, then use the 'pic' function from NIMH to create TaskObjects that can be used in your trial. If you need fast performance for your trial this method may be too slow.
0
aboharbf

Member
Registered:
Posts: 68
Reply with quote  #12 
Given that MKL actually runs through and creates the structures beforehand, making the stimuli and storing them as a persistent structure may be a suitable solution. I will report back on the results.
0
Edward

Administrator
Registered:
Posts: 251
Reply with quote  #13 
Sounds good, let us know if you have any questions!
0
Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Easily create a Forum Website with Website Toolbox.