Filter löschen
Filter löschen

Read particular images from a folder

1 Ansicht (letzte 30 Tage)
annmaria
annmaria am 9 Aug. 2015
Beantwortet: Walter Roberson am 9 Aug. 2015
I have a folder which contain 17 images and are named like 1im,2im...17im. I am classified this images into two classes 1 and 2. so I got 12 images are in group 1 and 5 images are in group 2. I want to read the images which are classified in group 1. p gives the indices of the image which are classified into first group. I tried the following code but it does'nt give exact answer. please help me.thanks in advance
p=find(Group==1);
disp(p);
A=[];
for ii=1:17
A{ii} = imread(['H:\dataa\try4\' num2str(ii) 'im' '.bmp']);
figure;imshow(A{p});
end

Antworten (2)

Image Analyst
Image Analyst am 9 Aug. 2015
Bearbeitet: Image Analyst am 9 Aug. 2015
How do you know what filenames correspond to Group? Is Group created with the same 17 files in the very same order as you're making up the filename strings? If so, do this
p= Group==1 % Logical vector.
A=cell(1, length(Group)); % Preallocate
for k = 1 : length(Group)
thisFilename = sprintf('H:\dataa\try4\%dim.bmp', k);
if exist(thisFilename, 'file')
A{k} = imread(thisFilename);
% Display it only if it's in group 1
subplot(4, 5, k);
if p(k)
imshow(A{k});
end
else
message = sprintf('%s does not exist', thisFilename);
uiwait(warndlg(message));
end
end

Walter Roberson
Walter Roberson am 9 Aug. 2015
A={};
for ii=1:17
if p(ii)
A{end+1} = imread(['H:\dataa\try4\' num2str(ii) 'im' '.bmp']);
figure;imshow(A{end});
end
end

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by