0

In my experiment I am displaying lots of different gratings. To save time during the experiment's execution, I'm pre-drawing the corresponding textures and keep them in a buffer. However, this takes about 10-20 seconds depending on how many stimuli the run uses, and how fast the machine is.

I was wondering whether there is a way of storing the pre-drawn textures on the hard drive and just have them read in?

Here is the current code:

    tic
    stimulus_matrix = [];
      for ifrequencies = 1:length(frequencies)
        for iphase = 1:length(phases)
            for icontrast_manipulation = 1:length(contrast_manipulation)
                for icontrast_values = 1:length(contrast_values(1,:))

grating = makeStimulus(contrast_values(icontrast_manipulation,icontrast_values),grating_size_degrees,phases(iphase),frequencies(ifrequencies,1));

stimulus_matrix(ifrequencies,iphase,icontrast_manipulation,icontrast_values) = Screen('MakeTexture', my_window, grating);

Screen('FillOval', stimulus_matrix(ifrequencies,iphase,icontrast_manipulation,icontrast_values), background, CenterRect(ovalRect,gratingRect));


                % Display a progress bar during buffering
                % code for progress bar removed for clarity

            end
        end
    end
end
Chris
  • 1
  • 1

3 Answers3

1

you can use

save('mydata.mat',stimulus_matrix);

and when you need the matrix, you can load it.

load mydata.mat;

then use stimulus_matrix as you want.

yangscar
  • 11
  • 1
  • Hi yangscar, sorry for essentially never responding. As said in the comment that was posted yesterday, stimulus_matrix doesn't actually contain the stimulus textures, but just the pointers to those textures. The textures themselves are stored in a way that is not really usable for functions outside of psychtoolbox: psychtoolbox creates variables for each created texture in the workspace, but these variables only contain a number. Therefore I guess that the actual textures are stowed away somewhere in memory where the user is not supposed to access. – Chris Mar 30 '15 at 07:25
0

Isn't stimulus_matrix just an index to the generated texture? These indices are just pointers. So if you close the textures but keep the windows open, I don't think loading the matrix enables you to draw textures again.

Ratbert
  • 5,463
  • 2
  • 18
  • 37
amir
  • 1
  • Sorry for not responding earlier - but that was exactly the problem. stimulus_matrix is indeed just a matrix of pointers to the PTB textures, not the textures themselves. Until now I haven't found a way to save those textures (which are stored in RAM or VRAM I guess) away. – Chris Mar 30 '15 at 07:22
0

Not sure if this is ideal for your situation, but you could try:

screen_array = Screen('GetImage', my_window);

while the textures are drawn. This would give you a 3D array of the screen content at that time (including your texture), which you could then edit down to include only your texture, and/or subsequently export.

KerrBer
  • 129
  • 11