-
Notifications
You must be signed in to change notification settings - Fork 9
/
getImageIdsAndNamesFromDatasetIds.m
76 lines (65 loc) · 2.59 KB
/
getImageIdsAndNamesFromDatasetIds.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
function [sortedImages imageIds imageNames sortedDatasetNames] = getImageIdsAndNamesFromDatasetIds(datasetIds)
% Copyright (C) 2013-2014 University of Dundee & Open Microscopy Environment.
% All rights reserved.
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License along
% with this program; if not, write to the Free Software Foundation, Inc.,
% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
global session
numDs = length(datasetIds);
datasets = getDatasets(session, datasetIds, true);
datasetNames = {};
images = java.util.ArrayList;
for thisDs = 1:numDs
dsId = datasets(thisDs).getId.getValue;
datasetName = char(datasets(thisDs).getName.getValue.getBytes');
numImages = datasets(thisDs).sizeOfImageLinks;
imageIter = datasets(thisDs).iterateImageLinks;
while imageIter.hasNext
datasetNames{end+1} = datasetName;
dsImageLink = imageIter.next;
images.add(dsImageLink.getChild);
end
end
%pass in the whole datasetId list and all the images will be returned, no
%need to loop through the datasets for this.
numImages = images.size;
if numImages == 0
images = [];
imageIds = [];
imageNames = [];
return;
end
%imageNameId{numImages,2} = [];
%imageNames{numImages} = [];
%Put the imageIds and Names into cells to be sorted alphabetically
imageIter = images.iterator;
counter = 1;
while imageIter.hasNext
imageNameId{counter,1} = char(images.get(counter-1).getName.getValue.getBytes');
imageNameId{counter,2} = num2str(images.get(counter-1).getId.getValue);
imageNameId{counter,3} = datasetNames{counter};
counter = counter + 1;
imageIter.next;
end
datasetNames = [];
[imageNameId sortIdx] = sortrows(imageNameId,1);
%Move the sorted Ids and Names into vector/cells to be returned.
%imageNameId = sortrows(imageNameId);
sortedImages = java.util.ArrayList;
for thisImage = 1:numImages
imageNames{thisImage} = imageNameId{thisImage, 1};
imageIds(thisImage) = str2double(imageNameId{thisImage, 2});
sortedDatasetNames{thisImage} = imageNameId{thisImage, 3};
sortedImages.add(images.get(sortIdx(thisImage)-1));
end