-
Notifications
You must be signed in to change notification settings - Fork 1
/
CSTwriteSegmentationToTXT.m
114 lines (101 loc) · 5.94 KB
/
CSTwriteSegmentationToTXT.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
function CSTwriteSegmentationToTXT(listOfWorms, videoName, flagShowGUI, precision)
% Copyright (c) 2013 Rutgers
% Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
% The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
global filenames CeleSTVersion;
if nargin < 3
flagShowGUI = true;
end
if nargin < 4
precision = 2;
end
% flagVersion29 = false;
factor = 10^precision;
blockSize = 2 + length(fieldnames(listOfWorms));
if flagShowGUI
hWaitBar = waitbar(0,'Saving segmentation results...');
end
nbOfWorms = length(listOfWorms.skel);
if nbOfWorms > 0
nbOfFrames = length(listOfWorms.skel{1});
else
nbOfFrames = 0;
end
formatting = '%s %02d %s %04d';
header = ['version ',CeleSTVersion,'\nformat ',strrep(strrep(formatting, '%','%%'),' ','_'),'\nblock ',num2str(blockSize),'\nworms ',num2str(nbOfWorms),'\nframes ',num2str(nbOfFrames),'\nprecision ', num2str(precision),'\n'];
fid = fopen(fullfile(filenames.segmentation, ['wormSegm_',videoName,'.txt']),'w+');
% if isfield(listOfWorms, 'valid')
% fprintf(fid, 'version 2.9.01\n');
% flagVersion29 = true;
% end
fprintf(fid, header);
if isfield(listOfWorms, 'status')
if length(listOfWorms.status) > 0
fprintf(fid, 'status\n');
for ww = 1:nbOfWorms
fprintf(fid, [listOfWorms.status{ww} '\n']);
end
end
end
for ww = 1:nbOfWorms
if flagShowGUI && isgraphics(hWaitBar); waitbar(ww/nbOfWorms, hWaitBar); end
for ff = 1:nbOfFrames
if (length(listOfWorms.skel{ww}) >= ff) && (~isempty(listOfWorms.skel{ww}{ff}))
coordX = round(factor*listOfWorms.skel{ww}{ff}(1,:));
coordY = round(factor*listOfWorms.skel{ww}{ff}(2,:));
else
coordX = [];
coordY = [];
end
stringToSave = [sprintf(formatting, 'worm', ww, 'frame', ff),'\n'...
, 'x ', sprintf('%d,',coordX),'\n'...
, 'y ', sprintf('%d,',coordY),'\n'...
, 'w ', sprintf('%d,',round(factor*listOfWorms.width{ww}{ff})),'\n'...
, 't ', sprintf('%d,',round(factor*listOfWorms.localthreshold{ww})),'\n'...
, 'g ', sprintf('%d,',round(factor*listOfWorms.lengthWorms(ww,ff))),'\n'...
, 'm ', sprintf('%d,',listOfWorms.missed(ww,ff)),'\n'...
, 'l ', sprintf('%d,',listOfWorms.lost(ww,ff)),'\n'...
, 'o ', sprintf('%d,',listOfWorms.overlapped(ww,ff)),'\n'];
% if flagVersion29
% if (length(listOfWorms.cblSubSampled{ww}) >= ff) && (~isempty(listOfWorms.cblSubSampled{ww}{ff}))
% coordX = round(factor*listOfWorms.cblSubSampled{ww}{ff}(1,:));
% coordY = round(factor*listOfWorms.cblSubSampled{ww}{ff}(2,:));
% else
% coordX = [];
% coordY = [];
% end
% stringToSave = [stringToSave...
% , 'v ', sprintf('%d,',listOfWorms.valid(ww,ff)),'\n'...
% , 'h ', sprintf('%d,',listOfWorms.outOfLengths(ww,ff)),'\n'...
% , 'p ', sprintf('%d,',listOfWorms.outOfPrevious(ww,ff)),'\n'...
% , 'z ', sprintf('%d,',listOfWorms.inGlareZone(ww,ff)),'\n'...
% , 's ', sprintf('%d,',listOfWorms.selfOverlap(ww,ff)),'\n'...
% , 'a ', sprintf('%d,',round(factor*listOfWorms.positionCenterX(ww,ff))),'\n'...
% , 'b ', sprintf('%d,',round(factor*listOfWorms.positionCenterY(ww,ff))),'\n'...
% , 'c ', sprintf('%d,',round(factor*listOfWorms.widthCenter(ww,ff))),'\n'...
% , 'd ', sprintf('%d,',coordX),'\n'...
% , 'e ', sprintf('%d,',coordY),'\n'...
% , 'k ', sprintf('%d,',round(factor*listOfWorms.overlapPrev(ww,ff))),'\n'...
% , 'n ', sprintf('%d,',listOfWorms.manualInvalid(ww,ff)),'\n'...
% , 'r ', sprintf('%d,',listOfWorms.manualValid(ww,ff)),'\n'...
% , 'u ', sprintf('%d,',round(factor*listOfWorms.headThrashCount(ww,ff))),'\n']; %#ok<AGROW>
% % , 'U ', sprintf('%d,',round(factor*listOfWorms.tailThrashCount(ww,ff))),'\n'];
% % , 'f ', sprintf('%d,',round(factor*listOfWorms.angleHead(ww,ff))),'\n'...
% % , 'q ', sprintf('%d,',round(factor*listOfWorms.angleTail(ww,ff))),'\n'...
% % , 'I ', sprintf('%d,',round(factor*listOfWorms.I(ww,ff))),'\n'...
% % , 'J ', sprintf('%d,',round(factor*listOfWorms.J(ww,ff))),'\n'...
% % , 'C ', sprintf('%d,',round(factor*listOfWorms.C(ww,ff))),'\n'...
% % , 'S ', sprintf('%d,',round(factor*listOfWorms.S(ww,ff))),'\n'...
% % , 'O ', sprintf('%d,',round(factor*listOfWorms.O(ww,ff))),'\n'...
%
% end
fprintf(fid, stringToSave);
end
end
fclose(fid);
if flagShowGUI && isgraphics(hWaitBar)
close(hWaitBar)
pause(0.001)
end
end