question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question/Issue] Draw_editor example with segmentationLUT/Freesurfer

See original GitHub issue

Hello!

I have a question/issue regarding how to access and modify the raw data content of a stack. Particularly, my scene is data + a freesurfer labelmap generated with the segmentationLUT, which can be seen on this live fiddle.

What I want to do is to modify the contents of the stack (as a drawing tool would do, for instance). To do so in the most basic way, I access the contents of the stack2 after the stack2.pack() line and try to change some values. For instance the segmentation label 7 (voxel value present on the stack).

stack2.prepare();
  // pixels packing for the fragment shaders now happens there
  stack2.pack();
  for(let i = 0; i < stack2._rawData[0].length; i++){
    if(stack2._rawData[0][i] != 7) stack2._rawData[0][i] = 0;
  }
  var textures2 = [];

When I do this everything turns to 0 (transparent), except the 7 label, which works as intended. HOWEVER, when trying to do other things such as:

 for(let i = 0; i < stack2._rawData[0].length; i++){
       stack2._rawData[0][i] = 7;
  }
  var textures2 = [];

which should turn the entire stack to one color (the one of the segmentation label number 7) or

 for(let i = 0; i < stack2._rawData[0].length; i++){
       if(stack2._rawData[0][i] == 0) stack2._rawData[0][i] = 6;
  }
  var textures2 = [];

Which should turn everything transparent to color label number 6 for instance, etc. etc. it is not working, everything turns transparent as the labelmap is not applied. The stack values are changed though, what can be the issue there? can it be due to the pixel packing, the shader, the model stack…? Which would be the best way to modify the contents of the stack/texture?

Cheers,

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
NicolasRannoucommented, Sep 15, 2017

so therewere a couple of issues:

1- the voxel increment is 4 because we are in 32 bits:

            let voxelIndex = i
                            + j * stack2._columns
                            + k * stack2._rows * stack2._columns;
            voxelIndex *= 4;

2- get the old value:

            let oldValue =
              (stack2.rawData[rawDataIndex][inRawDataIndex + 3] << 24) |
              (stack2.rawData[rawDataIndex][inRawDataIndex + 2] << 16) |
              (stack2.rawData[rawDataIndex][inRawDataIndex + 1] << 8) |
              (stack2.rawData[rawDataIndex][inRawDataIndex]);

And that should be it.

Finally, I think context.getImageData should be moved out of the crazy i/j/k for loops: -> Get all image data into an array at the very beginning of mapCanvasToData. -> access the right index from array instead of let pixel = <get right index>.

1reaction
NicolasRannoucommented, Sep 15, 2017

_rawData is the data to be passed to the shaders, encoded in 8 bits.

The data you are looking is encoded in 32 bits (stack2.bitsAllocated). In order to directly update the “packed” _rawData, you’d have to do something like:

   const value = 7;
   for(let i = 0; i < stack2._rawData[0].length; i+=4){
       stack2._rawData[0][i] =  (value) & 0x000000FF;
       stack2._rawData[0][i+1] = (value >>> 8) & 0x000000FF;
       stack2._rawData[0][i+2] = (value >>> 16) & 0x000000FF;
       stack2._rawData[0][i+3] = (value >>> 24) & 0x000000FF;
  }

That is a shortcut not to have to run “pack()” another time as it is expensive.

Depending on the format of the data you want to update, you would have to adjust the approach: https://github.com/FNNDSC/ami/blob/dev/src/models/models.stack.js#L523

http://jsfiddle.net/2f4bL2w3/19/

For reference, I’ve been doing something similar in the past but somehow it seems very slow now: https://fnndsc.github.io/ami/#editor_draw

(was much faster before 😕)

Please re-open in needed -

Read more comments on GitHub >

github_iconTop Results From Across the Web

FsTutorial/QuestionAnswers - Free Surfer Wiki
This wiki page contains a historical archive of student questions and answers from various Freesurfer courses. Question List ...
Read more >
FsTutorial/TroubleshootingData - Free Surfer Wiki
This set of exercises will take you through a few examples of problem outputs, asking you to identify the problems and possible methods...
Read more >
FreeSurfer Tutorial
The FreeSurfer tools deal with two main types of data: volumetric data (volumes of voxels) and surface data (polygons that tile a surface)....
Read more >
FreeviewGuide/FreeviewTools/VoxelEdit - Free Surfer Wiki
You can create custom labels or an entire manual segmentation composed of many regions with custom names. The Voxel Edit tools can be...
Read more >
FsTutorial/OutputData_freeview - Free Surfer Wiki
Some outputs are only necessary to check when troubleshooting, for example. However, it is a good idea for new users to become familiar...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found