Display images from a folder. Error in 'MakeTexture'

조회 수: 10 (최근 30일)
Clarissa
Clarissa 2022년 10월 25일
답변: Shivam Lahoti 2025년 3월 12일
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;
Unrecognized function or variable '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
Rohit
Rohit 2022년 10월 28일
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:

댓글을 달려면 로그인하십시오.

답변 (1개)

Shivam Lahoti
Shivam Lahoti 2025년 3월 12일
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:
  1. Run the "pathtool" command in the MATLAB Command Window. This should make a window with file paths open up
  2. Find the entry for "PsychtoolboxAddons" and move it to the top of the window
  3. 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.
  4. Also put your personal MATLAB directory at the top as well
  5. Don't run "SetupPsychtoolbox" again
I hope this might help you resolve this issue.
Regards,
Shivam.

카테고리

Help CenterFile Exchange에서 Timing and presenting 2D and 3D stimuli에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by