Skip to content

Instantly share code, notes, and snippets.

@dannyrb
Last active January 27, 2020 16:07
Show Gist options
  • Save dannyrb/63e5f4e76711f8539aea934357344e21 to your computer and use it in GitHub Desktop.
Save dannyrb/63e5f4e76711f8539aea934357344e21 to your computer and use it in GitHub Desktop.
Cornerstone Tool v3 - Simplest example, using Web Image Loader
<!DOCTYPE html>
<html>
<head>
<title>My first Cornerstone Tools app</title>
<!-- Dependencies -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cornerstoneMath.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cornerstone.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cornerstoneWebImageLoader.js"></script>
<!-- development version, includes helpful console warnings -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cornerstoneTools.js"></script>
<style>
.cornerstone-element-wrapper,
.cornerstone-element {
width: 512px;
height: 512px;
margin: 0 auto;
}
</style>
</head>
<body>
<!-- Our beautiful element target -->
<div class="cornerstone-element-wrapper">
<div class="cornerstone-element" data-index="0" oncontextmenu="return false"></div>
</div>
<script>
// Register the web image loader (JPEG & PNG)
cornerstoneWebImageLoader.external.cornerstone = window.cornerstone;
cornerstone.registerImageLoader('http', cornerstoneWebImageLoader.loadImage);
cornerstone.registerImageLoader('https', cornerstoneWebImageLoader.loadImage);
// Initialize cornerstone tools, and create an "enabled element"
// RE: An element that contains our canvas/viewport
const csTools = cornerstoneTools.init();
const element = document.querySelector('.cornerstone-element');
cornerstone.enable(element);
// Display our image on the "enabled element"
const imageId =
'https://www.asteris.biz/Keystone/ImageDownload.aspx?ClinicCode=TESTKEYSTONE&ImageId=01b1755e-33d1-4b24-b9af-a4a019689d5f&ImageType=PreviewImage&FrameIndex=0';
cornerstone.loadImage(imageId).then(function (image) {
cornerstone.displayImage(element, image);
});
</script>
</body>
</html>
@kuehlc
Copy link

kuehlc commented Jan 27, 2020

Thank you

@kuehlc
Copy link

kuehlc commented Jan 27, 2020

@dannyrb The image loader is the same as the v3 example then? Only the wado image loader changed?

@dannyrb
Copy link
Author

dannyrb commented Jan 27, 2020

I don't believe the WebImageLoader has changed much / at all. It's a bit easier to setup, so I tend to use the WADO Image Loader in examples as it tends to trip people up more frequently. It's also almost always preferable to use the WADO Image Loader.

@kuehlc
Copy link

kuehlc commented Jan 27, 2020

Makes sense. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment