rii-mango / Daikon

A JavaScript DICOM reader.
Other
221 stars 54 forks source link

convert series.concatenateImageData() data to interpreted array #5

Closed dvenkatsagar closed 8 years ago

dvenkatsagar commented 8 years ago

I assume that the function series.concatenateImageData gives a single stream of data of all the images as a raw ArrayBuffer.

series.concatenateImageData(null,function(imageData){
  // imageData is a ArrayBuffer{}
});

Is there a way to convert this buffer to sensible data like something similar to the image.getInterpretedData()? Or simple by creating a Float32Array out of it would suffice?

dvenkatsagar commented 8 years ago

Well, for now the only work around is to go for the traditional approach or use the module ndarrays.js to get things done.

    ...
    series.buildSeries();
    var r = series.images[0].getRows();
    var c = series.images[0].getCols();
    var no = series.images.length;

    var volume_buffer = new Array(no);
    var i = no, j = 0,k = 0;
    while(i--){
      var slice_buffer = series.images[j++].getInterpretedData(true);
      volume_buffer[j-1] = slice_buffer;
    }
    var slice = ndarray(new Float32Array(volume_buffer[115]),[r,c]);
    ...

The weird thing is that, if I try to convert all the images to a single Float32Array/Array like this :

    ...
    series.buildSeries();
    var r = series.images[0].getRows();
    var c = series.images[0].getCols();
    var no = series.images.length;

    var volume_buffer = new Array(r*c*no);
    var i = no, j = 0,k = 0;
    while(i--){
      var slice_buffer = series.images[j++].getInterpretedData(true);
      var l = slice_buffer.length, m = 0;
      while(l--){
        volume_buffer[k++] = slice_buffer[m++]; // A single stream
      }
    }
    var volume = ndarray(new Float32Array(volume_buffer),[r,c,no]);
    var slice = volume.pick(null,null,115);
    ...

The images dont show up correct. I dont know what I am doing wrong here.

rii-mango commented 8 years ago

Can you post a screenshot of what it looks like? Is it just noise or do you see some pattern?

dvenkatsagar commented 8 years ago

It comes as a pattern i guess. Here is the link

rii-mango commented 8 years ago

Based on the image, it looks like somewhere the dimensions are wrong. Try swapping c and r? The data is usually ordered by column then row.

var volume = ndarray(new Float32Array(volume_buffer),[c,r,no]);

dvenkatsagar commented 8 years ago

I think that wouldnt help as the ndarray.shape is a array. from the looks of it, the images are of size 512x512, so because of that, it will give the same result i guess.

dvenkatsagar commented 8 years ago

Ok I was able to fix it.... it was the way the array is stored in the ndarray, i changed the order as [no,r,c] and it worked