7 public enum SliceOrientation
64 private string description = null;
92 Debug.Log (
"Loading Meta Data for Series: " +
seriesUID);
95 if (filenames.Count <= 0) {
96 throw(
new System.Exception (
"No files found for series " + seriesUID +
"."));
101 firstSlice = SimpleITK.ReadImage( filenames[0] );
102 lastSlice = SimpleITK.ReadImage( filenames[Math.Max(filenames.Count-1,0)] );
109 VectorDouble direction = firstSlice.GetDirection();
110 if( direction.Count < 6 )
111 throw(
new System.Exception (
"Invalid direction cosines found in images."));
112 directionCosineX =
new Vector3 ((
float)direction [0], (
float)direction [3], (
float)direction [6]);
113 directionCosineY =
new Vector3 ((
float)direction [1], (
float)direction [4], (
float)direction [7]);
117 if (lastSlice != null) {
120 VectorDouble o1 = firstSlice.GetOrigin();
122 throw(
new System.Exception (
"Invalid origins found in first image."));
124 Vector3 origin =
new Vector3 ((
float)o1 [0], (
float)o1 [1], (
float)o1 [2]);
125 VectorDouble o2 = lastSlice.GetOrigin ();
127 throw(
new System.Exception (
"Invalid origins found in last image."));
129 Vector3 lastOrigin =
new Vector3 ((
float)o2 [0], (
float)o2 [1], (
float)o2 [2]);
141 VectorDouble directionLast = lastSlice.GetDirection ();
142 if (directionLast.Count < 6)
143 throw(
new System.Exception (
"Invalid direction cosines found in images."));
144 Vector3 directionCosineXLast =
new Vector3 ((
float)directionLast [0], (
float)directionLast [3], (
float)directionLast [6]);
145 Vector3 directionCosineYLast =
new Vector3 ((
float)directionLast [1], (
float)directionLast [4], (
float)directionLast [7]);
147 Vector3 sliceNormalLast = Vector3.Cross (directionCosineXLast, directionCosineYLast);
154 Debug.LogWarning (
"First and last slice of the series do not have the same orientation. This will not be considered a volume.\n" +
155 "\tNormal first slice, Normal last slice: " +
sliceNormal +
" " + sliceNormalLast);
165 float absX = Mathf.Abs (sliceNormal.x);
166 float absY = Mathf.Abs (sliceNormal.y);
167 float absZ = Mathf.Abs (sliceNormal.z);
168 if (absX > absY && absX > absZ) {
170 }
else if (absY > absX && absY > absZ) {
172 }
else if (absZ > absX && absZ > absY) {
186 minPixelValue = UInt32.Parse( firstSlice.GetMetaData(
"0028|0106") );
187 maxPixelValue = UInt32.Parse( firstSlice.GetMetaData(
"0028|0107") );
198 if (description != null && description.Length > 0)
202 string modality =
"";
203 string acquisitionContextDescription =
"";
204 string seriesDescription =
"";
205 string imageComment =
"";
206 string bodyPartExamined =
"";
207 string acquisitionDate =
"";
210 modality = firstSlice.GetMetaData (
"0008|0060");
214 acquisitionContextDescription = firstSlice.GetMetaData (
"0040|0556");
218 seriesDescription = firstSlice.GetMetaData (
"0008|103E");
222 imageComment = firstSlice.GetMetaData (
"0020|4000");
226 bodyPartExamined = firstSlice.GetMetaData (
"0018|0015");
230 acquisitionDate = firstSlice.GetMetaData (
"0008|0022");
231 if (acquisitionDate != null) {
232 DateTime time = DateTime.ParseExact (acquisitionDate,
"yyyyMMdd",
233 System.Globalization.CultureInfo.InvariantCulture);
234 acquisitionDate = time.ToString (
"dd MMMM yyyy");
240 if (modality.Length > 0)
241 description +=
"[" + modality +
"]";
243 if (bodyPartExamined.Length > 0)
244 description +=
" " + bodyPartExamined;
246 if (acquisitionDate != null && acquisitionDate.Length > 0)
247 description +=
", " + acquisitionDate;
250 if (imageComment != null && imageComment.Length > 0)
251 description +=
"\n<color=#dddddd>\t" + imageComment +
"</color>";
252 else if (seriesDescription != null && seriesDescription.Length > 0)
253 description +=
"\n<color=#dddddd>\t" + seriesDescription +
"</color>";
254 else if (acquisitionContextDescription != null && acquisitionContextDescription.Length > 0)
255 description +=
"\n<color=#dddddd>\t" + acquisitionContextDescription +
"</color>";
258 description =
"Failed to generate DICOM description (valid DICOM?).";
SliceOrientation sliceOrientation
DICOMSeries(string directory, string seriesUID)
bool foundMinMaxPixelValues
void setMinMaxPixelValues(UInt32 min, UInt32 max)