matlab - 从matlab中的特定文件夹访问图像

标签 matlab image-processing

有人可以向我解释一下下面的代码不起作用吗?

myFolderdepth = 'C:\Users\owner\Desktop'; %Specify Directory to get image from
Depth = dir (fullfile(myFolderdepth,'shower_depth','*.png'))%%Get images from file named     shower_depth
Depth_name = {Depth.name}'; %gets the name
figure;
imshow(Depth_name{3})

我收到的错误消息如下: 使用 getImageFromFile 时出错(第 11 行) 找不到指定的文件: “深度_003.png”。

我正在工作的目录是:C:\Users\owner\Desktop

图片名称为Depth_001,Depth_002,Depth_003,……

奇怪的是,我有另一个包含图像的文件夹,如果我将“shower_depth”更改为其他文件夹名称,它就可以正常工作。

谢谢! P.S 我做了一些进一步的实验,事实证明这是因为图像的命名方式;如果它的 Depth_01.png 没问题,它可以工作,但 Depth_001.png 不行

有人知道为什么吗?

最佳答案

以下命令:

Depth = dir (fullfile(myFolderdepth,'shower_depth','*.png'))

仅获取文件的相对名称。这意味着仅检索文件名,而不是文件的完整路径。查看您收到的错误:

Error using getImageFromFile (line 11)

Cannot find the specified file: "Depth_003.png".

你看到上面文件名中你的图片所在的路径了吗?没有!您只能看到存储在目录中的文件。您需要指定图像所在的完整路径。

您需要做的是将目录以及图像本身作为您提供给 imshow 的字符串附加:

myFolderdepth = 'C:\Users\owner\Desktop'; %Specify Directory to get image from
Depth = dir (fullfile(myFolderdepth,'shower_depth','*.png'))%%Get images from file named     shower_depth
Depth_name = {Depth.name}'; %gets the name
figure;
imshow(fullfile(myFolderDepth, Depth_name{3})); %// CHANGE HERE

关于matlab - 从matlab中的特定文件夹访问图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27852507/

相关文章:

image - 组合相交边界矩形的有效方法

python - 在python中找到坐标并突出显示图像中所需的文本

python - 最常用的视频处理 Python 模块?

matlab - 使用 x、y、z 点绘制曲面

javascript - 哪个plot.ly json属性允许将鼠标悬停在一行上时显示所有悬停数据

matlab - How to access memory information in Matlab on Unix - 相当于用户view.MaxPossibleArrayBytes

c++ - 如何自动确定2D阵列的CUDA block 大小和网格大小?

iphone - 动态裁剪风景图像

matlab - LSTM Matlab中 `MiniBatchSize`参数的含义是什么

matlab - 使用 MATLAB 获取信号的包络