Created
October 23, 2014 13:30
-
-
Save JorritPosthuma/431cba90d36e90e0de45 to your computer and use it in GitHub Desktop.
A small File Image Loader using the NodeJS FS lib. For use in a Node-Webkit application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DicomFileReader | |
colorInterpretations: [ | |
"RGB" | |
"PALETTE COLOR" | |
"YBR_FULL" | |
"YBR_FULL_422" | |
"YBR_PARTIAL_422" | |
"YBR_PARTIAL_420" | |
"YBR_RCT" | |
] | |
isColorImage: (photoMetricInterpretation) => | |
-1 isnt @colorInterpretations.indexOf photoMetricInterpretation | |
createImageObject: (dataSet, imageId) => | |
# make the image based on whether it is color or not | |
photoMetricInterpretation = dataSet.string("x00280004") | |
isColor = @isColorImage photoMetricInterpretation | |
if not isColor | |
cornerstoneWADOImageLoader.makeGrayscaleImage imageId, dataSet, dataSet.byteArray, photoMetricInterpretation, 0 | |
else | |
cornerstoneWADOImageLoader.makeColorImage imageId, dataSet, dataSet.byteArray, photoMetricInterpretation, 0 | |
loadImage: (imageId) => | |
deferred = $.Deferred() | |
@fs = require("fs") if not @fs | |
url = imageId.substring 10 | |
@fs.readFile url, (err, buffer) => | |
dataSet = dicomParser.parseDicom new Uint8Array buffer | |
imagePromise = @createImageObject dataSet, imageId | |
imagePromise.then deferred.resolve, -> deferred.reject() | |
deferred | |
reader = new DicomFileReader | |
cornerstone.registerImageLoader "dicomfile", reader.loadImage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment