-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathND2Info.m
106 lines (88 loc) · 3.65 KB
/
ND2Info.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
function [ImageInfo] = ND2Info(FileName)
if not(libisloaded('libNd2ReadSdk'))
warning('off', 'MATLAB:loadlibrary:cppoutput')
[~, ~] = loadlibrary('libNd2ReadSdk', 'Nd2ReadSdk.h');
end
FileID = libpointer('voidPtr', [int8(FileName) 0]);
[FilePointer] = calllib('libNd2ReadSdk', 'Lim_FileOpenForReadUtf8', FileID);
numImages = calllib('libNd2ReadSdk', 'Lim_FileGetSeqCount', FilePointer);
CoordSize = calllib('libNd2ReadSdk', 'Lim_FileGetCoordSize', FilePointer);
Attributes = calllib('libNd2ReadSdk', 'Lim_FileGetAttributes', FilePointer);
setdatatype(Attributes, 'int8Ptr', 500)
AttributesValue = Attributes.Value';
Attributeslength = find(AttributesValue == 0, 1);
AttributesJson = char(AttributesValue(1:Attributeslength - 1));
AttributesStru = jsondecode(AttributesJson);
TextInfo = calllib('libNd2ReadSdk', 'Lim_FileGetTextinfo', FilePointer);
TestLength=3000;
setdatatype(TextInfo, 'int8Ptr', TestLength)
TextInfoValue = TextInfo.Value';
while isempty(find(TextInfoValue == 0, 1))
TestLength=TestLength*2;
setdatatype(TextInfo, 'int8Ptr', TestLength)
TextInfoValue = TextInfo.Value';
end
TextInfolength = find(TextInfoValue == 0, 1);
TextInfoJson = char(TextInfoValue(1:TextInfolength - 1));
TextInfoStru = jsondecode(TextInfoJson);
Metadata = calllib('libNd2ReadSdk', 'Lim_FileGetMetadata', FilePointer);
if Metadata.isNull
MetadataStru=[];
else
TestLength=3000;
setdatatype(Metadata, 'int8Ptr', TestLength)
MetadataValue = Metadata.Value';
while isempty(find(MetadataValue == 0, 1))
TestLength=TestLength*2;
setdatatype(Metadata, 'int8Ptr', TestLength)
MetadataValue = Metadata.Value';
end
Metadatalength = find(MetadataValue == 0, 1);
MetadataJson = char(MetadataValue(1:Metadatalength - 1));
MetadataStru = jsondecode(MetadataJson);
end
Experiment = calllib('libNd2ReadSdk', 'Lim_FileGetExperiment', FilePointer);
if Experiment.isNull
ExperimentStru=[];
NumInCoord=[];
else
TestLength=3000;
setdatatype(Experiment, 'int8Ptr', TestLength)
ExperimentValue = Experiment.Value';
while isempty(find(ExperimentValue == 0, 1))
TestLength=TestLength*2;
setdatatype(Experiment, 'int8Ptr', TestLength)
ExperimentValue = Experiment.Value';
end
Experimentlength = find(ExperimentValue == 0, 1);
ExperimentJson = char(ExperimentValue(1:Experimentlength - 1));
ExperimentStru=jsondecode(ExperimentJson);
NumInCoord=zeros(1,CoordSize);
for i = 1:CoordSize
NumInCoord(i)=ExperimentStru(i).count;
end
end
ImageInfo.metadata = MetadataStru;
ImageInfo.Experiment = ExperimentStru;
ImageInfo.capturing = TextInfoStru.capturing;
ImageInfo.description = TextInfoStru.description;
ImageInfo.numImages = numImages;
ImageInfo.CoordSize = CoordSize;
% ImageInfo.NumInCoord = NumInCoord;
warning('off','backtrace')
if AttributesStru.widthBytes==AttributesStru.widthPx*AttributesStru.componentCount*AttributesStru.bitsPerComponentInMemory/8
ImageInfo.ImageWidth = AttributesStru.widthPx;
ImageInfo.ImageWidthOriginal = AttributesStru.widthPx;
else
warning('Image width is not fit the bytes of width. Reset image width.')
ImageInfo.ImageWidth=AttributesStru.widthBytes/AttributesStru.componentCount/(AttributesStru.bitsPerComponentInMemory/8);
ImageInfo.ImageWidthOriginal = AttributesStru.widthPx;
end
warning('on','backtrace')
ImageInfo.ImageHeight = AttributesStru.heightPx;
ImageInfo.Component = AttributesStru.componentCount;
[ImageInfo] = CheckInfo(ImageInfo);
PrintInfo(ImageInfo);
ND2Close(FilePointer)
clear('FilePointer')
end