필터 지우기
필터 지우기

imshow command will not display my images

조회 수: 22 (최근 30일)
Kyle Davis
Kyle Davis 2019년 1월 29일
편집: Stephen23 2019년 1월 29일
Hi all, I am currently trying to randomly present 21 images, one after the other, all located within the same folder. When I run my code, Matlab does not display any errors, but no images are shown either. I currently have the following code;
dirname= 'C:\Users\User\Documents\MATLAB\stimuli\';
d=dir([dirname '*.jpg']);
for i= randperm(numel(d))
imshow(d(i).name)
pause(2);
end

답변 (3개)

KSSV
KSSV 2019년 1월 29일
d=dir([dirname '*.jpg']);
for i= randperm(numel(d))
I = imread(d(i).name) ;
imshow(I)
pause(2);
end
  댓글 수: 1
Stephen23
Stephen23 2019년 1월 29일
편집: Stephen23 2019년 1월 29일
Note that imshow accepts a filename as its first inpout argument. Using another image display function does not resolve the actual issue with the code in the question (the missing path).

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


Walter Roberson
Walter Roberson 2019년 1월 29일
dirname= 'C:\Users\User\Documents\MATLAB\stimuli\';
d=dir(fullfile(dirname, '*.jpg'));
for i = randperm(numel(d))
imshow( fullfile(dirname, d(i).name) )
pause(2);
end

Stephen23
Stephen23 2019년 1월 29일
편집: Stephen23 2019년 1월 29일
The reason is very simple: you forgot to use the path when you tried to read the file:
D = 'C:\Users\User\Documents\MATLAB\stimuli';
S = dir(fullfile(D,'*.jpg'));
for k = randperm(numel(S))
imshow(fullfile(D,S(k).name))
pause(2);
end
Note that it is recommended to avoid using i for a loop iterator, as this is the name of the imaginary unit. Using fullfile is recommended instead of string concatenation:

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by