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..
0 个评论
采纳的回答
José-Luis
2012-9-17
classnumber = floor((your_number-1)/20) + 1;
inclass = mod(your_number-1,20) + 1;
0 个评论
更多回答(2 个)
Walter Roberson
2012-9-17
classnumber = floor((indexnumber-1)/20)+1;
inclass = indexnumber - 20*classnumber;
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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!