-
Notifications
You must be signed in to change notification settings - Fork 0
/
batch_summarize.m
66 lines (53 loc) · 1.81 KB
/
batch_summarize.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
function ret = batch_summarize(d, ret)
if ~exist('ret', 'var')
ret = {};
end
files = dir(d);
for i = 1:numel(files)
nm = files(i).name;
if files(i).isdir
% skip special direcruntories
if strcmp(nm(1), '.')
continue
end
% run for subdirectory
ret = batch_summarize(fullfile(d, nm), ret);
else
[~, ~, ext] = fileparts(nm);
if strcmp(ext, '.mat')
% get annotation file
annot_file = fullfile(d, nm);
% get image file
f = load(annot_file, 'file');
im_file = f.file;
% load image
im = imread(im_file);
% load
an = Annotator(im_file, im, annot_file);
% perform calculations
[d1, a1, c1] = an.fitConvexHull();
[d2, a2, c2] = an.fitEllipse(1);
[d3, a3, c3] = an.fitEllipse(2);
distances = an.distancesToNearestNeighbor();
% draw scale
an.drawScale();
% save
an.saveAnnotatedImage(sprintf('%d.jpg', 1 + (length(ret) / 3)));
% scatter histogram
f = figure;
% flip y axis (axis ij messes up histogram)
y = an.annotations(:, 2) * an.scale;
my = mean(y);
y = 2 * my - y;
scatterhist(an.annotations(:, 1) * an.scale, y);
print(f, sprintf('%d.png', 1 + (length(ret) / 3)), '-dpng', '-r300');
close(f);
% append to ret
ret{end + 1} = im_file;
ret{end + 1} = [size(an.annotations, 1) d1 a1 c1 d2 a2 c2 d3 a3 c3];
ret{end + 1} = distances;
delete(an);
end
end
end
end