| |
|
| | for dirName = {'train', 'test'}
|
| | imageDir = dirName{1};
|
| |
|
| |
|
| | fileComments = containers.Map();
|
| |
|
| |
|
| | imageFiles = dir(fullfile(imageDir, '*.jpg'));
|
| |
|
| | disp(['Total number of image files: ', num2str(length(imageFiles))]);
|
| |
|
| |
|
| | for i = 1:length(imageFiles)
|
| |
|
| | imagePath = fullfile(imageDir, imageFiles(i).name);
|
| |
|
| |
|
| | try
|
| | info = imfinfo(imagePath);
|
| | catch
|
| | disp(['Image not recognized or corrupted: ', imagePath]);
|
| | continue;
|
| | end
|
| | info = imfinfo(imagePath);
|
| | commentParts = info.Comment;
|
| |
|
| | commentDict = containers.Map();
|
| | for j = 1:length(commentParts)
|
| | keyValue = strsplit(strtrim(commentParts{j}), '=');
|
| | if length(keyValue) == 2
|
| | commentDict(keyValue{1}) = keyValue{2};
|
| | end
|
| | end
|
| | fileComments(imageFiles(i).name) = commentDict;
|
| | end
|
| |
|
| | outputJsonFile = strcat(imageDir, '.json');
|
| |
|
| |
|
| | fid = fopen(outputJsonFile, 'w');
|
| | if fid ~= -1
|
| | fwrite(fid, unicode2native(jsonencode(fileComments, 'PrettyPrint', true), 'UTF-8'));
|
| | fclose(fid);
|
| | else
|
| | disp('Error opening file.');
|
| | end
|
| | end
|
| | disp('Comments saved to JSON file.'); |