how can I access the index of one class? details are given below
1 view (last 30 days)
Show older comments
i have a dataset which contains 1400 images.. these images are divided into 70 classes. Each class contains the 20 images. so i have each image name as "class number_image number" e.g if i have class 2 and its image number 17 then I'll write it as "2_17"..
now keep all above in mind, i have made indexing of images from 1 to 1400.... So if i need to access an image that is on index 34 then its mean that it is from class 2 and its image number is 14 in that class.. but how can i do that??.. i.e. just looking at the image number how can identify that its belong to which class and in that class actually it is on which index??
u got it??.. plz help me out to write its syntax....
for this i have tried to separate the image number into digits and then divided the first one digit on 2 but not getting the accurate result as it fails if the image number is say 235 or 1245 or 1375..
0 Comments
Accepted Answer
José-Luis
on 17 Sep 2012
classnumber = floor((your_number-1)/20) + 1;
inclass = mod(your_number-1,20) + 1;
0 Comments
More Answers (2)
Walter Roberson
on 17 Sep 2012
classnumber = floor((indexnumber-1)/20)+1;
inclass = indexnumber - 20*classnumber;
Image Analyst
on 17 Sep 2012
Edited: Image Analyst
on 17 Sep 2012
How about this (untested):
% Get only those filenames with given class number, and NO others.
classNumberToRetrieve = 2;
filePattern = sprintf('%d_*.*', classNumberToRetrieve);
files = dir(filePattern)
% Get the index of the one image wanted.
imageNumberWanted = 17;
for index = 1 : length(files)
if strfind(files(index).name, num2str(imageNumberWanted))
break;
end
end
% index is now the item in the files list that you want.
% Now process files(index).name
0 Comments
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!