imread file does not exist - Unable to read file with multiple images

조회 수: 4 (최근 30일)
Vishnu Sree Shanthanu
Vishnu Sree Shanthanu 2024년 3월 14일
편집: Walter Roberson 2024년 3월 14일
I am trying the following code which reads a file containing multiple images -
clc; clear all;
% Specify the filename containing images
filename = 'D:\BMPtoPNG'
% Read all images from the file
images = imread(filename); ......
But the command prompt shows -
Error using imread
File "D:\BMPtoPNG" does not exist.
Please let me know how to solve this error.
  댓글 수: 4

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

답변 (2개)

Walter Roberson
Walter Roberson 2024년 3월 14일
% Specify the filename containing images
foldername = 'D:\BMPtoPNG';
% Read all images from the file
dinfo = dir(foldername);
dinfo([dinfo.isfolder]) = []; %get rid of all subfolders including . and ..
filenames = fullfile({dinfo.folder}, {dinfo.name});
nfile = numel(filenames);
images = cell(nfile,1);
for K = 1 : nfile
this_image = imread(filenames{K});
images{K} = this_image;
end
%now images is a cell array of image contents

Image Analyst
Image Analyst 2024년 3월 14일
To process a sequence of files in a folder, see code snippets in the FAQ:

카테고리

Help CenterFile Exchange에서 Import, Export, and Conversion에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by