필터 지우기
필터 지우기

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 CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by