Effacer les filtres
Effacer les filtres

Hello guys, I have a question concerning my Matlab script. I try to read/load several pictures but I always get the same error. Could anyone have a quick look at my script? The files I try to load defintely exist and they all have the .jpg format.

2 vues (au cours des 30 derniers jours)
affectivepictures = dir('C:\Users\Kilian\Desktop\Arbeit Köln\Matlab\Bilddateien\affektive_Bilder_neu/*.jpg');
numFiles = length(affectivepictures);
for i_pics = 1:numFiles
bild = imread(affectivepictures(i_pics).name);
image{i_pics} = double(bild)/255;
% convert image matrices to textures
theImage{i_pics} = Screen('MakeTexture', window, image{i_pics});
end
  1 commentaire
tom
tom le 4 Déc 2017
the error is: Error using imread>get_full_filename (line 516) File "1.jpg" does not exist.
Error in imread (line 340) fullname = get_full_filename(filename);
Could anyone help me out with this? Kind of desperate already

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 4 Déc 2017
projectdir = 'C:\Users\Kilian\Desktop\Arbeit Köln\Matlab\Bilddateien\affektive_Bilder_neu';
affectivepictures = dir( fullfile(projectdir, '*.jpg') );
numFiles = length(affectivepictures);
filenames = fullfile( projectdir, {affectivepictures.name});
for i_pics = 1:numFiles
thisfile = filenames{i_pics};
bild = imread(thisfile);
images{i_pics} = im2double(bild);
% convert image matrices to textures
theImage{i_pics} = Screen('MakeTexture', window, images{i_pics});
end
  4 commentaires
Walter Roberson
Walter Roberson le 4 Déc 2017
What shows up for
ls(projectdir)
?
One thing I worry about is the ö in your string. In English versions of MATLAB, .m files are not stored as UTF-8, so although the ö would show up on your screen, what would be saved in the file might be something different. It is probably okay because ö is char(246) rather than being something about 255 that would require two bytes to represent, but it is something I would double check.
Image Analyst
Image Analyst le 4 Déc 2017
The line of code you posted is
theImage{i_pics} = Screen('MakeTexture', window, images{i_pics});
yet the error is regarding this line of code:
Screen('DrawTexture', window, theImage{Identification(trial)}, [], instrImagePosition);
which is not in the code you posted. Note that the third argument of Screen() is "images" in the first code and "theImage" in the second code. So which is it? If you're using the second line of code, then theImage has never been defined yet so that's why you're getting the error message.
I think you need to take more care about your variable names and which are used where, and also in showing us the proper code and matching error message.

Connectez-vous pour commenter.

Plus de réponses (3)

KL
KL le 4 Déc 2017
Probably you're not working on the same directory. Try using fullfile,
bild = imread(fullfile(affectivepictures(i_pics).path,affectivepictures(i_pics).name));
  2 commentaires
tom
tom le 4 Déc 2017
Hey KL, thanks for your answer. Now I get this error "Reference to non-existent field 'path'."
sorry, I´am completely new to the field.
The strange thing is, a few days ago it already worked out fine with the Code above. I don´t think I changed something about it.
Any other ideas? Best regards
Walter Roberson
Walter Roberson le 4 Déc 2017
The 'path' field for dir() was new as of a small number of releases ago.

Connectez-vous pour commenter.


Image Analyst
Image Analyst le 4 Déc 2017
You forgot to use fullfile() to prepend the folder.
This is a very F.A.Q. So see the faq (the second chunk of code): http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F

tom
tom le 5 Déc 2017
Thank you all!
It works now totally fine. First question --> first answer. Great community.
best regards Kilian

Catégories

En savoir plus sur Convert Image Type dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by