我在這裏有一個代碼。從子文件夾讀取圖像並保存到另一個文件夾中
start_path = fullfile(matlabroot, '\toolbox\images\imdemos');
% Ask user to confirm or change.
topLevelFolder = uigetdir(start_path);
if topLevelFolder == 0
return;
end
% Get list of all subfolders.
allSubFolders = genpath(topLevelFolder);
% Parse into a cell array.
remain = allSubFolders;
listOfFolderNames = {};
while true
[singleSubFolder, remain] = strtok(remain, ';');
if isempty(singleSubFolder)
break;
end
listOfFolderNames = [listOfFolderNames singleSubFolder];
end
numberOfFolders = length(listOfFolderNames)
% Process all image files in those folders.
for k = 1 : numberOfFolders
% Get this folder and print it out.
thisFolder = listOfFolderNames{k};
fprintf('Processing folder %s\n', thisFolder);
% Get PNG files.
filePattern = sprintf('%s/*.png', thisFolder);
baseFileNames = dir(filePattern);
% Add on TIF files.
filePattern = sprintf('%s/*.tif', thisFolder);
baseFileNames = [baseFileNames; dir(filePattern)];
% Add on JPG files.
filePattern = sprintf('%s/*.jpg', thisFolder);
baseFileNames = [baseFileNames; dir(filePattern)];
numberOfImageFiles = length(baseFileNames);
% Now we have a list of all files in this folder.
if numberOfImageFiles >= 1
% Go through all those image files.
for f = 1 : numberOfImageFiles
fullFileName = fullfile(thisFolder, baseFileNames(f).name);
pathname = strcat('C:\\xampp\\htdocs\\PACS_Client\\cbir_matlab\\ano\\');
outputBaseFileName = sprintf('%3.3d.jpg',f);
outputFullFileName = fullfile(pathname, outputBaseFileName);
fprintf('Processing image file %s\n', fullFileName);
im=imread(fullFileName);
imshow(im);
data = im;
imwrite(data,[pathname,outputBaseFileName]);
end
else
fprintf(' Folder %s has no image files in it.\n', thisFolder);
end
end
我試圖從所有子文件夾中的圖像保存到另一個folder.But無法獲得所有圖像的images.Only幾個數字是saved.I要保存所有images.can有人幫我這個代碼?
什麼圖像丟失?他們都在同一個目錄或不同的目錄?那裏有多少個文件夾? – Finn
在主文件夾中有4個子文件夾每個子文件夾都有很多圖像我只能保存在第一個子文件夾中的圖像 – Jury
我想將子文件夾中的所有圖像保存到一個文件夾中 – Jury