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!