oganm / brainspriter Goto Github PK
View Code? Open in Web Editor NEWShiny widget for brainsprite
Home Page: https://oganm.github.io/brainspriteR/demo
License: MIT License
Shiny widget for brainsprite
Home Page: https://oganm.github.io/brainspriteR/demo
License: MIT License
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.
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
}
}
Also implement crossair
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.