简体   繁体   English

在Matlab中读取图像权限

[英]read image permission in Matlab

I'm trying to access images in a matlab interface my code is as follows: 我正在尝试在matlab界面中访问图像,我的代码如下:

global  im2 im  
axes(handles.axes4); 

[path1, user_cance]= imgetfile();
if user_cance 
    msgbox(sprintf('Error'), 'Error', 'Error'); 

    return
end

srcFiles = dir('C:\Users\User\Desktop\images test\yale faces\yalefaces\..');    
 % yale faces is the database folder 

for i = 1 : length(srcFiles)
    file_name=dir(strcat('C:\Users\User\Desktop\images test\yale faces\yalefaces')); 

  im2=imread(strcat('C:\Users\User\Desktop\images test\yale faces\yalefaces',file_name(i).name));  
    %processing of read image

end

the issue is that when I run the code, it gives the following error: 问题是,当我运行代码时,它给出以下错误:

Can't open file "C:\\Users\\User\\Desktop\\images test\\yale faces\\yalefaces" for reading; 无法打开文件“ C:\\ Users \\ User \\ Desktop \\ images test \\ yale faces \\ yalefaces”进行读取; you may not have read permission. 您可能没有阅读权限。

Does anyone know how to solve this issue? 有谁知道如何解决这个问题?

When you do a directory listing (without any wildcards) you are going to get the current directory '.' 当您执行目录列表(不带通配符)时,将获得当前目录'.' and parent directory as well '..' . 以及父目录'..' You can't read these like files because they are directories. 您无法读取这些文件,因为它们是目录。 You will need to filter out the directories prior to trying to read them with imread. 您将需要过滤掉目录,然后才能尝试使用imread读取它们。

files = dir('C:\Users\User\Desktop\images test\yale faces\yalefaces'); 

% Remove directories
files = files(~[files.isdir]);

As a side note, it is very hard to tell what your code is doing, but I'm pretty sure it doesn't do what you hope. 附带说明一下,很难说出您的代码在做什么,但是我很确定它不会满足您的期望。

It seems like you want to get all images within the database. 似乎您想在数据库中获取所有图像。 If that's so, you'll want to do something like. 如果是这样,您将想要做类似的事情。

folder = 'C:\Users\User\Desktop\images test\yale faces\yalefaces';

% Get a list of all files in this folder
files = dir(folder);
files = files(~[files.isdir]);

for k = 1:numel(files)
    % Append the folder with the filename to get the path and load
    im2 = imread(fullfile(folder, files(k).name));
end

I highly discourage using strcat to construct file paths particularly because it removes trailing/leading whitespace from each input which can corrupt a filename. 我极力劝阻使用strcat构造文件路径,特别是因为它从每个输入中删除可能导致文件名损坏的尾随/前导空格。 fullfile was designed for exactly this so please use that. fullfile正是为此而设计的,因此请使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM