Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could you please help on abling pixel value? #2

Open
zhengchencai opened this issue May 1, 2022 · 0 comments
Open

Could you please help on abling pixel value? #2

zhengchencai opened this issue May 1, 2022 · 0 comments

Comments

@zhengchencai
Copy link

Hi there,

Thank you very much for making this wrapper and it helps a lot for R users. I am trying to enable "flagValue" and "colormap" such that pixel values could be displayed like the demo here (https://brainsprite.github.io/auto_examples/plot_stat_map.html). However, it only shows "no value" no matter where I click.

image

What I did is just simply hacked brainsprite.R and add "flagValue" and "colormap" in the script. I also added "crosshair" and "colorCrosshair" which works. colormap input is just a png colorbar.

brainsprite_new = function(sprites,
                       spriteHeight = 233,
                       spriteWidth = 189,
                       inputId = tempfile('id') %>% basename,
                       spriteID = tempfile('id') %>% basename,
                       flagCoordinates = FALSE,
                       flagValue = TRUE,
                       crosshair = TRUE,
                       colormap = FALSE,
                       nanValue = T,
                       colorCrosshair = "black",
                       origin = c(0,0,0),
                       fontColor = "#FFFFFF",
                       background = "#000000",
                       overlay = NULL,
                       overlayHeight = NULL,
                       overlayWidth = NULL,
                       overlayID = tempfile('id') %>% basename,
                       overlayOpacity = 0.5,
                       height = NULL,
                       width = NULL){

  script = glue::glue(" $( <spriteID> ).load(function() {
                       var brain = brainsprite({
                       canvas: '<inputId>', // That is the ID of the canvas to build slices into
                       sprite: '<spriteID>', // That is the ID of the sprite image that includes all (sagital) brain slices
                       nbSlice: { 'Y':<spriteHeight> , 'Z':<spriteWidth> },
                       colorBackground: '<background>',
                       colorFont: '<fontColor>',
                       crosshair: '<tolower(crosshair)>',
                       colorCrosshair: '<colorCrosshair>',
                       flagValue: '<tolower(flagValue)>',
                       colormap: '<colormap>',
                       nanValue: '<nanValue>',
                       flagCoordinates: <tolower(flagCoordinates)>
                       "
                      ,.open = '<',.close = '>')

 script = glue::glue(" $( <spriteID> ).load(function() {
                       var brain = brainsprite({
                       canvas: '<inputId>', // That is the ID of the canvas to build slices into
                       sprite: '<spriteID>', // That is the ID of the sprite image that includes all (sagital) brain slices
                       nbSlice: { 'Y':<spriteHeight> , 'Z':<spriteWidth> },
                       colorBackground: '<background>',
                       colorFont: '<fontColor>',
                       crosshair: '<tolower(crosshair)>',
                       colorCrosshair: '<colorCrosshair>',
                       flagValue: '<tolower(flagValue)>',
                       colormap: '<colormap>',
                       nanValue: '<nanValue>',
                       flagCoordinates: <tolower(flagCoordinates)>
                       "
                      ,.open = '<',.close = '>')

I hasn't fully understood how brainspriteR works since I am not familiar with java scrip. It seems one needs to provide a colormap which is same as the one in the overlay image, and pixel value is extracted by reading the RGB value and corresponds to the colorbar range (see below function getValue from brainsprite.js). Could you please help? Thanks

  let getValue = function (rgb, colorMap) {
  // Extract the value associated with a voxel by looking up in a colormap.
    if (!colorMap) {
      return NaN
    }
    let ind = NaN
    let val = Infinity
    const nbColor = colorMap.canvas.width
    const cv = colorMap.context.getImageData(0, 0, nbColor, 1).data
    for (let xx = 0; xx < nbColor; xx++) {
      const dist = Math.abs(cv[xx * 4] - rgb[0]) + Math.abs(cv[xx * 4 + 1] - rgb[1]) + Math.abs(cv[xx * 4 + 2] - rgb[2])
      if (dist < val) {
        ind = xx
        val = dist
      }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant