Skip to content

Instantly share code, notes, and snippets.

@kousu
Last active October 9, 2022 19:04
Show Gist options
  • Save kousu/2a31328d9c320393fbd603534265faa7 to your computer and use it in GitHub Desktop.
Save kousu/2a31328d9c320393fbd603534265faa7 to your computer and use it in GitHub Desktop.
nifti demo
node_modules

Install

npm install

Run

Start a web server, for example

python -m http.server

then open http://localhost:8000 in your browser.

Expected output

screenshot

TODO

  • upgrade to @cornerstonejs/core (aka Cornerstone3D) when possible
<!DOCTYPE html>
<html>
<head>
<script type="module" src="/node_modules/cornerstone-core/dist/cornerstone.js"></script>
<script type="module" src="/node_modules/@cornerstonejs/nifti-image-loader/dist/cornerstoneNIFTIImageLoader.js"></script>
<script>
// hook up the cornerstone plugins
// cornerstone demands this boilerplate
window.addEventListener('DOMContentLoaded', (event) => {
cornerstoneNIFTIImageLoader.external.cornerstone = cornerstone;
});
</script>
</head>
<body>
<script>
window.addEventListener('DOMContentLoaded', (event) => {
const canvas = document.getElementById('cornerstone-viewport')
cornerstone.enable(canvas)
cornerstone
.loadAndCacheImage('nifti:./sub-glen_acq-MTon_MTS.nii.gz')
.then((image) => {
console.log(image)
const viewport = cornerstone.getDefaultViewportForImage(canvas, image)
cornerstone.displayImage(canvas, image, viewport)
})
.catch((err) => {
console.error(err)
})
});
</script>
<div id="margin-wrap" style="margin-left: auto; margin-right: auto; width: 80%">
<h1>cornerstone-nifti-image-loader demo</h1>
<div id="cornerstone-viewport" style="width: 100%; height: 70vh"></div>
</div>
</body>
</html>
Written 2022 <[email protected]>: and donated to the public domain, except for
- `sub-glen_acq-MTon_MTS.nii.gz`
- imported from https://github.com/spine-generic/data-single-subject/
- CC-BY 4.0 International, 2021 Julien Cohen-Adad <[email protected]>
{
"name": "starter",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"dependencies": {
"@cornerstonejs/nifti-image-loader": "^1.0.7",
"cornerstone-core": "^2.6.1",
"cornerstone-tools": "^6.0.8",
"hammer": "^0.0.5"
}
},
"node_modules/@babel/runtime": {
"version": "7.1.2",
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.1.2.tgz",
"integrity": "sha512-Y3SCjmhSupzFB6wcv1KmmFucH6gDVnI30WjOcicV10ju0cZjak3Jcs67YLIXBrmZYw1xCrVeJPbycFwrqNyxpg==",
"dependencies": {
"regenerator-runtime": "^0.12.0"
}
},
"node_modules/@cornerstonejs/nifti-image-loader": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/@cornerstonejs/nifti-image-loader/-/nifti-image-loader-1.0.7.tgz",
"integrity": "sha512-jzczoc52XKE8colMxl0FcpLRr+GA2eQp/OsV+H65ed3LnFa728KWfBW6mIMWALXKS0ggT06X8cqn2T56xDllIA==",
"dependencies": {
"ndarray": "^1.0.18",
"nifti-reader-js": "^0.5.4",
"pako": "^1.0.6"
}
},
"node_modules/cornerstone-core": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/cornerstone-core/-/cornerstone-core-2.6.1.tgz",
"integrity": "sha512-LAXjXwNnK2W65ZxpE7phVLjbijkYUrAQIGv5xqKjK8+dmIGlBxqvPHnyGwEqVDyKOWVrpXP6ymUPwrGGRwzgMg=="
},
"node_modules/cornerstone-math": {
"version": "0.1.10",
"resolved": "https://registry.npmjs.org/cornerstone-math/-/cornerstone-math-0.1.10.tgz",
"integrity": "sha512-23XSAyP7t70ANvhFyqwvva+zFd1bQ2d5GL7tg9qKE932WmImjA2Y9tiy5n0iTtnf51W/78Png8Lia2o4dCdJaQ=="
},
"node_modules/cornerstone-tools": {
"version": "6.0.8",
"resolved": "https://registry.npmjs.org/cornerstone-tools/-/cornerstone-tools-6.0.8.tgz",
"integrity": "sha512-eTM+bwq2CjDmkFxCp2X/bRpsoWm5I6O0WVNeIH8W0hVjhplJGfUUx08vKRZXABdqIRkgLaby6VhswA33AuYpcw==",
"dependencies": {
"@babel/runtime": "7.1.2",
"cornerstone-math": "0.1.10"
},
"engines": {
"node": ">=8.16.0"
},
"peerDependencies": {
"cornerstone-core": "^2.6.0"
}
},
"node_modules/hammer": {
"version": "0.0.5",
"resolved": "https://registry.npmjs.org/hammer/-/hammer-0.0.5.tgz",
"integrity": "sha512-mdGMKdrHiO1QVY7A+514ZtoaujioWjd8LT1DQpKMsgGke1JmmSvbywgbOWFRRmSfGupcSGra1N9fvFXNtwXb+Q==",
"bin": {
"hammer": "bin/hammer"
},
"engines": {
"node": "*"
}
},
"node_modules/iota-array": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/iota-array/-/iota-array-1.0.0.tgz",
"integrity": "sha512-pZ2xT+LOHckCatGQ3DcG/a+QuEqvoxqkiL7tvE8nn3uuu+f6i1TtpB5/FtWFbxUuVr5PZCx8KskuGatbJDXOWA=="
},
"node_modules/is-buffer": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
"integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w=="
},
"node_modules/ndarray": {
"version": "1.0.19",
"resolved": "https://registry.npmjs.org/ndarray/-/ndarray-1.0.19.tgz",
"integrity": "sha512-B4JHA4vdyZU30ELBw3g7/p9bZupyew5a7tX1Y/gGeF2hafrPaQZhgrGQfsvgfYbgdFZjYwuEcnaobeM/WMW+HQ==",
"dependencies": {
"iota-array": "^1.0.0",
"is-buffer": "^1.0.2"
}
},
"node_modules/nifti-reader-js": {
"version": "0.5.4",
"resolved": "https://registry.npmjs.org/nifti-reader-js/-/nifti-reader-js-0.5.4.tgz",
"integrity": "sha512-KnZMEw9Wd39x1eTTZQaF5Zjh7LbUeWcxfEj0v5VS/yTkV2y/YHrAnC6VJyf2FjrmsUOElDVjIoHGLMCkcnpiNg==",
"dependencies": {
"pako": "*"
}
},
"node_modules/pako": {
"version": "1.0.11",
"resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz",
"integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw=="
},
"node_modules/regenerator-runtime": {
"version": "0.12.1",
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.12.1.tgz",
"integrity": "sha512-odxIc1/vDlo4iZcfXqRYFj0vpXFNoGdKMAUieAlFYO6m/nl5e9KR/beGf41z4a1FI+aQgtjhuaSlDxQ0hmkrHg=="
}
},
"dependencies": {
"@babel/runtime": {
"version": "7.1.2",
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.1.2.tgz",
"integrity": "sha512-Y3SCjmhSupzFB6wcv1KmmFucH6gDVnI30WjOcicV10ju0cZjak3Jcs67YLIXBrmZYw1xCrVeJPbycFwrqNyxpg==",
"requires": {
"regenerator-runtime": "^0.12.0"
}
},
"@cornerstonejs/nifti-image-loader": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/@cornerstonejs/nifti-image-loader/-/nifti-image-loader-1.0.7.tgz",
"integrity": "sha512-jzczoc52XKE8colMxl0FcpLRr+GA2eQp/OsV+H65ed3LnFa728KWfBW6mIMWALXKS0ggT06X8cqn2T56xDllIA==",
"requires": {
"ndarray": "^1.0.18",
"nifti-reader-js": "^0.5.4",
"pako": "^1.0.6"
}
},
"cornerstone-core": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/cornerstone-core/-/cornerstone-core-2.6.1.tgz",
"integrity": "sha512-LAXjXwNnK2W65ZxpE7phVLjbijkYUrAQIGv5xqKjK8+dmIGlBxqvPHnyGwEqVDyKOWVrpXP6ymUPwrGGRwzgMg=="
},
"cornerstone-math": {
"version": "0.1.10",
"resolved": "https://registry.npmjs.org/cornerstone-math/-/cornerstone-math-0.1.10.tgz",
"integrity": "sha512-23XSAyP7t70ANvhFyqwvva+zFd1bQ2d5GL7tg9qKE932WmImjA2Y9tiy5n0iTtnf51W/78Png8Lia2o4dCdJaQ=="
},
"cornerstone-tools": {
"version": "6.0.8",
"resolved": "https://registry.npmjs.org/cornerstone-tools/-/cornerstone-tools-6.0.8.tgz",
"integrity": "sha512-eTM+bwq2CjDmkFxCp2X/bRpsoWm5I6O0WVNeIH8W0hVjhplJGfUUx08vKRZXABdqIRkgLaby6VhswA33AuYpcw==",
"requires": {
"@babel/runtime": "7.1.2",
"cornerstone-math": "0.1.10"
}
},
"hammer": {
"version": "0.0.5",
"resolved": "https://registry.npmjs.org/hammer/-/hammer-0.0.5.tgz",
"integrity": "sha512-mdGMKdrHiO1QVY7A+514ZtoaujioWjd8LT1DQpKMsgGke1JmmSvbywgbOWFRRmSfGupcSGra1N9fvFXNtwXb+Q=="
},
"iota-array": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/iota-array/-/iota-array-1.0.0.tgz",
"integrity": "sha512-pZ2xT+LOHckCatGQ3DcG/a+QuEqvoxqkiL7tvE8nn3uuu+f6i1TtpB5/FtWFbxUuVr5PZCx8KskuGatbJDXOWA=="
},
"is-buffer": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
"integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w=="
},
"ndarray": {
"version": "1.0.19",
"resolved": "https://registry.npmjs.org/ndarray/-/ndarray-1.0.19.tgz",
"integrity": "sha512-B4JHA4vdyZU30ELBw3g7/p9bZupyew5a7tX1Y/gGeF2hafrPaQZhgrGQfsvgfYbgdFZjYwuEcnaobeM/WMW+HQ==",
"requires": {
"iota-array": "^1.0.0",
"is-buffer": "^1.0.2"
}
},
"nifti-reader-js": {
"version": "0.5.4",
"resolved": "https://registry.npmjs.org/nifti-reader-js/-/nifti-reader-js-0.5.4.tgz",
"integrity": "sha512-KnZMEw9Wd39x1eTTZQaF5Zjh7LbUeWcxfEj0v5VS/yTkV2y/YHrAnC6VJyf2FjrmsUOElDVjIoHGLMCkcnpiNg==",
"requires": {
"pako": "*"
}
},
"pako": {
"version": "1.0.11",
"resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz",
"integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw=="
},
"regenerator-runtime": {
"version": "0.12.1",
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.12.1.tgz",
"integrity": "sha512-odxIc1/vDlo4iZcfXqRYFj0vpXFNoGdKMAUieAlFYO6m/nl5e9KR/beGf41z4a1FI+aQgtjhuaSlDxQ0hmkrHg=="
}
}
}
{
"dependencies": {
"@cornerstonejs/nifti-image-loader": "^1.0.7",
"cornerstone-core": "^2.6.1",
"cornerstone-tools": "^6.0.8",
"hammer": "^0.0.5"
}
}
This file has been truncated, but you can view the full file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment