フィルターのクリア

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 ビュー (過去 30 日間)
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 件のコメント
tom
tom 2017 年 12 月 4 日
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

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2017 年 12 月 4 日
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 件のコメント
Walter Roberson
Walter Roberson 2017 年 12 月 4 日
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 2017 年 12 月 4 日
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.

サインインしてコメントする。

その他の回答 (3 件)

KL
KL 2017 年 12 月 4 日
Probably you're not working on the same directory. Try using fullfile,
bild = imread(fullfile(affectivepictures(i_pics).path,affectivepictures(i_pics).name));
  2 件のコメント
tom
tom 2017 年 12 月 4 日
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 2017 年 12 月 4 日
The 'path' field for dir() was new as of a small number of releases ago.

サインインしてコメントする。


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

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by