Display images from a folder. Error in 'MakeTexture'
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
hi everyone, I'm just trying to load pictures from a folder and show them on the screen. But he continues to give me this error:
Error in function MakeTexture: Invalid Window (or Texture) Index provided: It doesn't correspond to an open window or texture.
Did you close it accidentally via Screen('Close') or Screen('CloseAll') ?
Error using Screen
Usage:
textureIndex=Screen('MakeTexture', WindowIndex, imageMatrix [, optimizeForDrawAngle=0] [, specialFlags=0]
[, floatprecision] [, textureOrientation=0] [, textureShader=0]);
Error in minimale2 (line 38)
imageDisplay = Screen('MakeTexture', w, imageArray);
Does anyone know what it is?
I'm using Psychtoolbox on MATLAB for Windows
%prova
clc; % clean console
clear all; % check PTB version
AssertOpenGL;
Screen('Preference', 'SkipSyncTests', 2);
PsychDefaultSetup(2);
% set keyboard commands
space = KbName('space');
escapeKey = KbName('ESCAPE');
% Get the image files for the experiment
myFolder = 'C:\Users\clari\OneDrive\Desktop\MATLAB\cartella esperimento\im.prova';
imgList = dir(fullfile(myFolder, '*.png'));
imageArray = cell(size(imgList));
% settare lo schermo prima di andare in RUN
screens = Screen('Screens');
myscreen = max(Screen('Screens'));
[w, rect] = Screen('OpenWindow', myscreen, [], [], 32, 2); % APRE LO SCREEN
[X,Y] = RectCenter(rect); % X e Y = coordinate centro dello schermo
%LOOP
for k = 1 : length(imgList)
baseFileName = imgList(k).name;
fullFileName = fullfile(imgList(k).folder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
imageArray = imread(fullFileName);
end
for k = 1 : length(imageArray)
imageDisplay = Screen('MakeTexture', w, imageArray);
% Show the images
Screen(w, 'FillRect', 127);
Screen('DrawTexture', w, imageDisplay, [])
Screen('Flip', w)
KbWait;
%end
% end's screen
Screen('Flip', w);
KbStrokeWait;
Screen('CloseAll');
fprintf('**************************\n');
fprintf('... and this concludes the experiment\n');
close('all');
end
1 Kommentar
Rohit
am 28 Okt. 2022
Hi,
You can use the “imread()” and “imshow()” functions to read and display the images from the folder. Below are the links to MATLAB documentation for “imread()” and “imshow()” along with related MATLAB Answers example that might prove useful:
Antworten (1)
Shivam Lahoti
am 12 Mär. 2025
Hi Clarissa,
I understand you are facing an error while using Psychtoolbox.
As mentioned in the error log, the error occurs while running the "Screen" function. I would suggest running the Screen command individually to see if MATLAB can resolve the name.
I encountered a similar error a while back, which was due to the path not being properly set in MATLAB. To fix it, follow the steps below:
- Run the "pathtool" command in the MATLAB Command Window. This should make a window with file paths open up
- Find the entry for "PsychtoolboxAddons" and move it to the top of the window
- If you do not have a folder for "PsychtoolboxAddons", then you will have to go to the toolbox website for instructions on how to make it.
- Also put your personal MATLAB directory at the top as well
- Don't run "SetupPsychtoolbox" again
I hope this might help you resolve this issue.
Regards,
Shivam.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Timing and presenting 2D and 3D stimuli finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!