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

采纳的回答

Image Analyst
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 CenterFile Exchange 中查找有关 Image Processing and Computer Vision 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by