cornerstone icon indicating copy to clipboard operation
cornerstone copied to clipboard

Get image blob data(or source data, png or jpg) from cornerstone image data

Open gracegyu opened this issue 4 years ago • 7 comments

Hello there,

When I call cornerstone.loadImage(imageId) then I get image data; Is there any way to get image blob data(or source data, png or jpg) from the image data. to use it in image tag. I know after drawing(with cornerstone.displayImage) I can get the image blob from canvas. I want to get image blob data without drawing the image. I found image.getPixelData(). Can I use this function to get image blob data? Could anyone help me with that issue, please?

Thank you in advance.

gracegyu avatar Apr 03 '20 03:04 gracegyu

I am facing a similar issue too. I'm looking to send the image blob to a post request. Did you find any solution?

kkmehta03 avatar Apr 03 '20 12:04 kkmehta03

According to cornerstone's image documentation, there's a function called getImage() that describes the same thing you want. I also tried it, but I get an error that there's no such function in existence.

kkmehta03 avatar Apr 03 '20 13:04 kkmehta03

The solution I found is using image.getPixelData() function. I can get raw data of pixels. I should convert it to 0~255 RGB data. I'm now sure whether this is the best solution.

gracegyu avatar Apr 06 '20 02:04 gracegyu

If you're running orthanc for your database, they have an API to get the image png if you give them an instance id. I'm not sure at the moment of how you can access. here's a link for their api documentation - https://docs.google.com/spreadsheets/d/e/2PACX-1vSBEymDKGZgskFEFF6yzge5JovGHPK_FIbEnW5a6SWUbPkX06tkoObUHh6T1XQhgj-HqFd0AWSnVFOv/pubhtml?gid=986690746&single=true

kkmehta03 avatar Apr 06 '20 05:04 kkmehta03

any updates on this? really want to load the raw image pixel data into png..

kkmehta03 avatar Apr 11 '20 09:04 kkmehta03

Hello! If you want to get the blob, all you have to do is:

const activeEnabledElement = cornerstone.getEnabledElements()[0]
cornerstone.loadImage(activeEnabledElement.image.imageId).then(image => {
    const imageBlob = image.getCanvas().toDataURL('image/png');
});

kkmehta03 avatar Apr 11 '20 11:04 kkmehta03

This won't work unless the image is a color image

randikabanura avatar Jan 12 '21 06:01 randikabanura