필터 지우기
필터 지우기

Storing image properties in loop

조회 수: 1 (최근 30일)
Mathew Smith
Mathew Smith 2022년 9월 12일
댓글: Mathew Smith 2022년 9월 12일
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
  댓글 수: 1
Mathew Smith
Mathew Smith 2022년 9월 12일
This is a masterpiece. Thanks!

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

추가 답변 (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