How to access images?

I have one folder contain 50K images, I want to cut a group (5000 image) of this images according to indexing numbers. For example [ 6, 9, 2000,40215,...]. How to code such this?
path='E:\CIFAR-10\train';
jpeg_files = dir(fullfile(path,'*.png'));
for cnt = 1 : 50000
I{cnt} = imread(fullfile(path,jpeg_files(cnt).name));
% figure,imshow(I{cnt});
for j=1:5000
if cnt==class1num(1,j)
imwrite(I{cnt},sprintf('%s%d.jpg','0',cnt));
end
end
end

6 Comments

mohammed - which images do you want to index on? Those in the outer loop or in the inner loop? How are you expecting to use your [ 6, 9, 2000,40215,...] array in the above code?
By the way: Redifining the important Matlab command path can cause severe effects during debugging. It is recommended to avoid this strictly. Use "filePath" or anything unique instead.
What is class1num? Maybe the innerloop can be simplified.
Why do you insert a '0' in the file name? sprintf('0%d.jpg', cnt) would be easier. Maybe you mean:
sprintf('%02d.jpg', cnt)
to insert a leading zero, if the number is smaller than 10?
To simply my qusetion, I have the training images of cifar10 dataset which contains 50k images and the labels (name of image,class number), so i want to seperate every class images in one directory.
Jan
Jan on 16 Jan 2019
"I have the labels" does not allow to suggest some running code. What does "separate each class in one directory" mean? Separate what into what based on which criterion?
Jan
Jan on 16 Jan 2019
This link does not contain more useful information. I asked some questions for clarifications there also. Please read: How to ask a good question

Sign in to comment.

Answers (0)

Asked:

on 15 Jan 2019

Commented:

Jan
on 16 Jan 2019

Community Treasure Hunt

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

Start Hunting!