Filter löschen
Filter löschen

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 Ansichten (letzte 30 Tage)
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 Kommentar
tom
tom am 4 Dez. 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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 4 Dez. 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 Kommentare
Walter Roberson
Walter Roberson am 4 Dez. 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 am 4 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (3)

KL
KL am 4 Dez. 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 Kommentare
tom
tom am 4 Dez. 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

Melden Sie sich an, um zu kommentieren.


Image Analyst
Image Analyst am 4 Dez. 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 am 5 Dez. 2017
Thank you all!
It works now totally fine. First question --> first answer. Great community.
best regards Kilian

Kategorien

Mehr zu Convert Image Type 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!

Translated by