From 4943918a5c7ceeee9ca00fc48ee91fcfa1188b34 Mon Sep 17 00:00:00 2001 From: Erik Ziegler Date: Thu, 29 Jun 2017 09:37:45 +0200 Subject: [PATCH] Refactor DICOMZero a bit, begin adding Display Segmentation and Linear Measurement -> SR examples --- examples/createSegmentation/index.html | 70 ++--- .../QIN_HEADNECK_024_PET_multiframe.dcm | Bin 0 -> 9922256 bytes .../QIICR_Test3/tumor_User1_Manual_Trial1.dcm | Bin 0 -> 38152 bytes examples/displaySegmentation/index.html | 264 ++++++++++++++++++ examples/index.html | 1 + examples/linearMeasurements/index.html | 223 +++++++++++++++ src/DICOMZero.js | 10 +- src/DicomMetaDictionary.js | 6 +- src/datasetToBlob.js | 18 ++ src/normalizers.js | 1 + src/packBitArray.js | 34 +++ 11 files changed, 585 insertions(+), 42 deletions(-) create mode 100755 examples/data/QIICR_Test3/QIN_HEADNECK_024_PET_multiframe.dcm create mode 100644 examples/data/QIICR_Test3/tumor_User1_Manual_Trial1.dcm create mode 100644 examples/displaySegmentation/index.html create mode 100644 examples/linearMeasurements/index.html create mode 100644 src/datasetToBlob.js create mode 100644 src/packBitArray.js diff --git a/examples/createSegmentation/index.html b/examples/createSegmentation/index.html index a66e4992..40d2352f 100644 --- a/examples/createSegmentation/index.html +++ b/examples/createSegmentation/index.html @@ -80,6 +80,8 @@
Controls:
+ + @@ -89,17 +91,42 @@
Controls:
+ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/index.html b/examples/index.html index 02aa3533..bc7cd2c4 100755 --- a/examples/index.html +++ b/examples/index.html @@ -17,6 +17,7 @@

dcmjs Examples


diff --git a/examples/linearMeasurements/index.html b/examples/linearMeasurements/index.html new file mode 100644 index 00000000..0f7077e8 --- /dev/null +++ b/examples/linearMeasurements/index.html @@ -0,0 +1,223 @@ + + + + + + + + + + +
+ + +
+

Drag and drop DICOM files here...

+
+
+
+
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/DICOMZero.js b/src/DICOMZero.js index f5fac845..54393fb0 100644 --- a/src/DICOMZero.js +++ b/src/DICOMZero.js @@ -37,17 +37,15 @@ class DICOMZero { } else { this.readers.splice(readerIndex, 1); // remove the reader } + if (this.fileIndex === this.dataTransfer.files.length) { console.log(`Normalizing...`); this.multiframe = Normalizer.normalizeToDataset(this.datasets); console.log(`Creating segmentation...`); this.seg = new Segmentation([this.multiframe]); console.log(`Created ${this.multiframe.NumberOfFrames} frame multiframe object and segmentation.`); - let frameMax = this.multiframe.NumberOfFrames-1; - //$('#instanceOffset')[0].max = frameMax; - let middle = Math.floor((frameMax)/2); - //$('#instanceOffset')[0].value = middle; - doneCallback() + + doneCallback(); } else { console.log(`Reading... (${this.fileIndex+1}).`); this.readOneFile(doneCallback); @@ -67,4 +65,4 @@ class DICOMZero { this.files.push(file); this.readers.push(reader); } -} \ No newline at end of file +} diff --git a/src/DicomMetaDictionary.js b/src/DicomMetaDictionary.js index 7bb25da2..1e284218 100755 --- a/src/DicomMetaDictionary.js +++ b/src/DicomMetaDictionary.js @@ -1,16 +1,16 @@ class DicomMetaDictionary { static punctuateTag(rawTag) { - if (rawTag.indexOf(',') != -1) { + if (rawTag.indexOf(',') !== -1) { return (rawTag); } - if (rawTag.length == 8 && rawTag == rawTag.match(/[0-9a-fA-F]*/)[0]) { + if (rawTag.length === 8 && rawTag === rawTag.match(/[0-9a-fA-F]*/)[0]) { var tag = rawTag.toUpperCase(); return ("("+tag.substring(0,4)+","+tag.substring(4,8)+")"); } } static unpunctuateTag(tag) { - if (tag.indexOf(',') == -1) { + if (tag.indexOf(',') === -1) { return (tag); } return(tag.substring(1,10).replace(',','')); diff --git a/src/datasetToBlob.js b/src/datasetToBlob.js new file mode 100644 index 00000000..a5bc905b --- /dev/null +++ b/src/datasetToBlob.js @@ -0,0 +1,18 @@ +datasetToBlob = function (dataset) { + const meta = { + FileMetaInformationVersion: dataset._meta.FileMetaInformationVersion.Value[0], + MediaStorageSOPClass: dataset.SOPClass, + MediaStorageSOPInstance: dataset.SOPInstanceUID, + TransferSyntaxUID: "1.2.840.10008.1.2", + ImplementationClassUID: DicomMetaDictionary.uid(), + ImplementationVersionName: "DICOMzero-0.0", + }; + + const denaturalized = DicomMetaDictionary.denaturalizeDataset(meta); + const dicomDict = new DicomDict(denaturalized); + + dicomDict.dict = DicomMetaDictionary.denaturalizeDataset(dataset); + + const buffer = dicomDict.write(); + return new Blob([buffer], {type: "application/dicom"}); +} \ No newline at end of file diff --git a/src/normalizers.js b/src/normalizers.js index 3f28ac99..359d8ff0 100644 --- a/src/normalizers.js +++ b/src/normalizers.js @@ -31,6 +31,7 @@ class Normalizer { "EnhancedMRImage" : EnhancedMRImageNormalizer, "EnhancedUSVolume" : EnhancedUSVolumeNormalizer, "PETImage" : PETImageNormalizer, + "EnhancedPETImage": PETImageNormalizer, "PositronEmissionTomographyImage" : PETImageNormalizer, "Segmentation" : SEGImageNormalizer, "DeformableSpatialRegistration" : DSRNormalizer, diff --git a/src/packBitArray.js b/src/packBitArray.js new file mode 100644 index 00000000..ddd31fb7 --- /dev/null +++ b/src/packBitArray.js @@ -0,0 +1,34 @@ +/* eslint no-bitwise: 0 */ +function getBytesForBinaryFrame (numPixels) { + // Check whether the 1-bit pixels exactly fit into bytes + const remainder = numPixels % 8; + + // Number of bytes that work on an exact fit + let bytesRequired = Math.floor(numPixels / 8); + + // Add one byte if we have a remainder + if (remainder > 0) { + bytesRequired++; + } + + return bytesRequired; +} + +packBitArray = function(pixelData) { + const numPixels = pixelData.length; + const length = getBytesForBinaryFrame(numPixels); + const bitPixelData = new Uint8Array(length); + + let bytePos = 0; + + for (let count = 0; count < numPixels; count++) { + // Compute byte position + bytePos = Math.floor(count / 8); + + const pixValue = (bitPixelData[count] !== 0); + + bitPixelData[bytePos] |= pixValue << (count % 8); + } + + return pixelData; +} \ No newline at end of file