rii-mango / Papaya

A pure JavaScript medical research image viewer.
Other
554 stars 205 forks source link

Float32Array to papaya.Container.addImage #225

Open gaiborjosue opened 9 months ago

gaiborjosue commented 9 months ago

Hello @rii-mango,

I am currently having a bit of trouble trying to add as an overlay to my current container (0) the output of a tensorflow model (Float32Array).

I read the documentation, and it says that it does accept arrays as input instead of image URLS. Thus, my approach was the following:

            let predictionArray = prediction.dataSync();

            let params = [];

            params["binaryImages"] = {lut: "Spectrum"};

            papaya.Container.addImage(0, [predictionArray], params);

However, I am getting the following error:

papaya.js:3723 Uncaught (in promise) RangeError: Invalid string length
    at Float32Array.join (<anonymous>)
    at Float32Array.toString (<anonymous>)
    at Array.join (<anonymous>)
    at Array.toString (<anonymous>)
    at papaya.Container.findLoadableImage 

Is my approach right? If not, how can I achieve the overlay to the original container with the new output array?

Thank you!

gaiborjosue commented 9 months ago

Hello @rii-mango; quick update. I got past the previous error, but now I get a new type of error.

I figured out I needed to convert my Array output to an array buffer with the correct size. Now that I feed it correctly the same way as before, this is the new error I am getting:

Uncaught (in promise) TypeError: a[0].lastIndexOf is not a function
    at papaya.volume.Volume.readURLs (papaya.js:3026:109)
    at papaya.viewer.Viewer.loadOverlay (papaya.js:3371:362)
    at papaya.viewer.Viewer.loadImage (papaya.js:3366:123)
    at papaya.Container.addImage (papaya.js:3666:215)
    at loadModel (researchexperiment/:142:30)

Could you please tell me what this refers to and whether my approach to adding the image is correct?