필터 지우기
필터 지우기

Hello! How to extract Images in multiple class folders through MATLAB code. I have image dataset (training,​testing,ev​aluation) folders but I have only xlsx file with labels.

조회 수: 2 (최근 30일)
I have image datastore (training,testing,evaluation) 47 classes dataset. I want to save images in 47 different class folders but I only have xlsx file with labels.I want to extract images from this excel labels. mean I make folder with their names(label) extract image from training etc and save the image to labels folder. if any body help me outh with this problem I will be very thankful

답변 (1개)

Image Analyst
Image Analyst 2022년 12월 1일
  1. Get a directory listing of all the files in your source folder.
  2. Read the workbook and get the class label from the appropriate column - the CSR column.
  3. Build a new destination filename using the class label as a folder.
  4. Use a for loop and copyfile to copy the files.
Something like (untested)
filePattern = fullfile(inputFolder, '*.png');
imds = imageDatastore(filePattern);
t = readtable(workbookName);
classFolderNames = t.CSR;
allFileNames = imds.Files;
for k = 1 : numel(allFileNames)
% Get input file name from datastore.
sourceFileName = allFileNames{k}
[folder, baseFileNameNoExt, ext] = fileparts(sourceFileName);
% Get class name from workbook.
% Assuming the order of class assignments matches up with that in the
% datastore (NOT a good assumption though), you can do this
subFolderName = classFolderNames{k};
destinationFolder = fullfile(folder, subFolderName);
if ~isfolder(destinationFolder)
% Create subfolder if it does not exist.
mkdir(destinationFolder);
end
% Build destination file name
destinationBaseFileName = [baseFileNameNoExt, ext]; % Same name as input
destinationFullFileName = fullfile(destinationFolder, destinationBaseFileName);
% Copy file into output folder.
copyfile(sourceFileName, destinationFullFileName);
fprintf('Copied "%s" to \n "%s".\n', sourceFileName, destinationFullFileName)
end
  댓글 수: 3
Tahir Arshad
Tahir Arshad 2022년 12월 1일
sir I have one folder name training and that folder have all classes images and above figure all clases label are given in xlsx file. how can i get all classes image from xlsx file.here each image has given name but in folder all image have 1,2,3 to 1920 sequence.
Image Analyst
Image Analyst 2022년 12월 1일
Please wrangle your data and upload a workbook that has the file names in column 1, and the class number or name you've assigned to that image in column 2.

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

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by