-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheckInfo.m
125 lines (93 loc) · 4.23 KB
/
CheckInfo.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
115
116
117
118
119
120
121
122
123
124
125
function [ImageInfo] = CheckInfo(ImageInfo)
warning('off','backtrace')
MetadataStru = ImageInfo.metadata;
ExperimentStru = ImageInfo.Experiment;
Description = ImageInfo.description;
Description(Description == 39) = [];
Description(Description == 0) = ' ';
DescriptionSplitIndex = find(Description == 13);
DimensionsIndex = strfind(Description, 'Dimensions');
Dimensions = Description(DimensionsIndex + 12:min(DescriptionSplitIndex(DescriptionSplitIndex > DimensionsIndex)) - 1);
Dimensions(Dimensions == 120) = [];
DimensionsCell = strsplit(Dimensions);
for i = 1:size(DimensionsCell, 2)
Dimensionsi = DimensionsCell{i};
DimensionsStruct(i).name = Dimensionsi(1:find(Dimensionsi == 40) - 1);
DimensionsStruct(i).Size = sscanf(Dimensionsi(find(Dimensionsi == 40):end), '(%d)');
if isempty(DimensionsStruct(i).name)
ChannelDimension = i;
else
end
end
if exist('ChannelDimension','var')
DimensionsStruct(ChannelDimension) = [];
else
end
ChannelNumIndex = strfind(Description, 'Planes');
if isempty(ChannelNumIndex)
ChannelNum = 1;
ChannelIndex = max(strfind(Description, 'Name'));
Channel.name = Description(ChannelIndex(i) + 6:min(DescriptionSplitIndex(DescriptionSplitIndex > ChannelIndex(i) + 5) - 1));
else
ChannelNum = str2double((Description(ChannelNumIndex + 8:min(DescriptionSplitIndex(DescriptionSplitIndex > ChannelNumIndex) - 1))));
ChannelIndex = strfind(Description, 'Plane #');
for i = 1:ChannelNum
Channel(i).name = Description(ChannelIndex(i) + 18:min(DescriptionSplitIndex(DescriptionSplitIndex > ChannelIndex(i) + 18) - 1));
end
end
if isempty(MetadataStru)
warning('%s\n%s','Can not get Metadata.','Set channel infomation with ImageInfo.description.');
MetadataStru.contents.channelCount = ChannelNum;
for i = 1:ChannelNum
MetadataStru.channels(i).channel.name = Channel(i).name;
end
else
if MetadataStru.contents.channelCount == ChannelNum
else
warning('Channel number not match')
end
for i = 1:ChannelNum
if strcmp(MetadataStru.channels(i).channel.name, Channel(i).name)
else
warning(['Channel ', num2str(i), ' name not match'])
end
end
end
if isempty(ExperimentStru)
warning('%s\n%s','Can not get Experiment Info.','Set loops infomation with ImageInfo.description.');
for i = 1:size(DimensionsStruct, 2)
ExperimentStru(i,1).count = DimensionsStruct(i).Size;
ExperimentStru(i,1).type = [DimensionsStruct(i).name, 'loop'];
end
else
for i = 1:size(DimensionsStruct, 2)
if contains(ExperimentStru(i).type, DimensionsStruct(i).name)
else
warning('%s\n%s',['Loop name not match in loop ', num2str(i), ', name ', ExperimentStru(i).type, ' vs ', DimensionsStruct(i).name, 'Loop.'], 'Set loops infomation with ImageInfo.description');
ExperimentStru(i).type = [DimensionsStruct(i).name, 'loop'];
end
if ExperimentStru(i).count == DimensionsStruct(i).Size
else
warning('%s\n%s', ['Loop size not match in ', ExperimentStru(i).type, '.'], 'Set loops infomation with ImageInfo.description.')
ExperimentStru(i).count = DimensionsStruct(i).Size;
end
end
end
if ImageInfo.CoordSize==size(ExperimentStru,1)
else
warning('%s\n%s', ['CoordSize not match.'], 'Set CoordSize infomation with ImageInfo.description.')
ImageInfo.CoordSize=size(ExperimentStru,1);
end
ImageCount=1;
for i=1:size(ExperimentStru,1)
ImageCount=ExperimentStru(i).count*ImageCount;
end
if ImageCount==ImageInfo.numImages
else
warning('Image number not match!!!');
return
end
ImageInfo.metadata = MetadataStru;
ImageInfo.Experiment = ExperimentStru;
warning('on','backtrace')
end