Storing image properties in loop
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I would like to ask you to help me to store image name and map in for-end loop. Here they are in square brackets [X, mapX] but how to store for each image name the properties in different letter?
a = dir(fullfile(yourfolder, 'img_??.jpg'));
for i = 1:length(a)
imgname(i) = char(a(i.name)
[X, mapX] = rgb2ind(imread(imgname),256);
end ;
Best regards
Michal
0 个评论
采纳的回答
Image Analyst
2022-9-12
@Mathew Smith do it this more robust way:
imageFolder = pwd;
fileListing = dir(fullfile(imageFolder, 'img_*.jpg'));
if isempty(fileListing)
warningMessage = sprintf('No jpg image files found in %d.\n', imageFolder);
uiwait(warndlg(warningMessage));
return;
end
allFileNames = {fileListing.name}'
numFiles = numel(allFileNames)
counter = 0;
ca = cell(numFiles, 2); % Preallocate space.
for k = 1 : numFiles
thisFileName = fullfile(imageFolder, allFileNames{k});
fprintf('Processing file #%d of %d : "%s"\n', k, numFiles, thisFileName);
[rgbImage, embeddedColorMap] = imread(thisFileName);
[rows, columns, numberOfColorChannels] = size(rgbImage);
% If it's not RGB, skip it.
if numberOfColorChannels < 3
fprintf(' Skipping "%s" because it is not true color RGB.\n', thisFileName);
continue;
end
[indexedImage, computedColorMap] = rgb2ind(rgbImage,256);
% Save these in a cell array
counter = counter + 1;
ca{counter, 1} = indexedImage;
ca{counter, 2} = computedColorMap;
end
% Crop in case we skipped any
if counter < numFiles
ca = ca(1 : counter);
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing and Computer Vision 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!