Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

How to modify all the images in different folders under a folder

3 Ansichten (letzte 30 Tage)
Jhilam Mukherjee
Jhilam Mukherjee am 31 Aug. 2016
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
I have 10 folders under a folder. Each folder contains nearly 200 images. I can aceess the folder using recurse_subfolders.m matlab file. While read or write operations are performed on these images. It generate error.
clc; % Clear the command window. workspace; % Make sure the workspace panel is showing. format long g; format compact;
% Define a starting folder. start_path = fullfile('E:\testing', '\testing'); if ~exist(start_path, 'dir') start_path = 'E:\testing\'; end % Ask user to confirm or change. uiwait(msgbox('Pick a starting folder on the next window that will come up.')); 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}; filePattern = sprintf('%s/*.*', thisFolder); baseFileNames = dir(filePattern); tic numberOfImageFiles = length(baseFileNames); if numberOfImageFiles >= 1 for i=1:numberOfImageFiles filename = fullfile(thisFolder, baseFileNames(i).name); listing = dir; allDirNames = { listing.name }; dirLA = [ listing.isdir ]; dirLA(1:2) = 0; dirNames = allDirNames(dirLA); for idx = 1:length(dirNames) cd(dirNames{idx}) % assuming that all files in the directory to be run fileNames = ls; fileNames = cellstr(fileNames(3:end,:)); for id2 = 1:length(fileNames) %eval(fileNames{id2}(1:end-2)) srcFiles = dir('E:\testing\dirNames{idx}\*.jpg'); X=strcat('E:\testing\dirNames{id2}\',srcFiles(id2).name); % I{id2} = imread(fileNames); % figure,imshow(I{id2}); end cd .. end
end
end
end

Antworten (0)

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by