how can I access the index of one class? details are given below

1 次查看(过去 30 天)
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..

采纳的回答

José-Luis
José-Luis 2012-9-17
classnumber = floor((your_number-1)/20) + 1;
inclass = mod(your_number-1,20) + 1;

更多回答(2 个)

Walter Roberson
Walter Roberson 2012-9-17
classnumber = floor((indexnumber-1)/20)+1;
inclass = indexnumber - 20*classnumber;
  1 个评论
sani ars
sani ars 2012-9-17
The class number is ok.... but the 2nd line of your code is not giving me the exact index of the image in that identified class.... e.g if I want to know in which class the image number 125 is, then the result is 7 that is correct classnumber....
Now within this class7, this image is on index 5 as class7 contains 1 to 20 images as well.... so my "inclass" variable should get the number 5.... but according to your 2nd line of code it is giving me number 15 which is not the actual index within that class7... The actual index of the image within that class is 5

请先登录,再进行评论。


Image Analyst
Image Analyst 2012-9-17
编辑:Image Analyst 2012-9-17
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

Community Treasure Hunt

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

Start Hunting!

Translated by