ANTsR
ANTsR copied to clipboard
colorbar key for antsrSurf
I can make lovely 3D surface renderings with functional overlay using antsrSurf. I'd like to use these for a publication. Is there a way to include (or create in some other way) a key legend for the rendering that shows approximately what colors correspond to which values? If this function isn't available from antsrSurf, is there a way (perhaps using a different function) to just plot a bar without numbers that illustrates the color range matching what I used for my rendering (e.g., the "jet" color scheme), which I could then easily enough add numbers indicating the range using powerpoint or some other software?
Thanks for any thoughts or suggestions about this!
-Tom
yes -- the "plot a color bar" then add numbers on your own approach is good. antsSurf
just uses standard color maps. you can google color bars for the standard maps and then amend those. @ntustison - do you agree?
Yeah, agreed. Whenever I need to make custom color bars, I create my own using convertScalarImageToRGB
but, correct me if I'm wrong, I don't think that functionality is available in the ANTsR package.
pretty sure convertScalarImageToRGB
is wrapped in some way within R
... I know it's called directly ... anyway this entire pipeline of functionality is very powerful but could be greatly improved -- probably a useful thing to target for our recent funding.
I see from calling convertScalarImageToRGB that it requires an input image. What's an easy way to create a 2D image that has, say, 10 pixels in the x dimension and 100 in the y dimension, with the y values going from 1 to 100? If I understand correctly, convertScalarImageToRGB would translate that into an appropriate colorbar matching the colormap I use?
One easy solution off the top of my head:
colorbarImage <- as.antsImage( rbind( 1:100, 1:100, 1:100, 1:100, 1:100, 1:100, 1:100, 1:100, 1:100, 1:100 ) )
Thank you for the hint! For future reference to anyone else needing the same thing, here is what I got to work:
- created two files in ANTsR, one the image to be colored, the other a mask, and wrote them to disk:
> colorbarImage <- as.antsImage( rbind( 100:1, 100:1, 100:1, 100:1, 100:1, 100:1, 100:1, 100:1, 100:1, 100:1 ) )
> antsImageWrite(colorbarImage,"colorbarImage.nii")
> colorbarImageMask <- makeImage( c(10,100),1)
> antsImageWrite(colorbarImageMask,"colorbarImageMask.nii")
NOTE: The ordering of numbers "100:1" in the rbind command above puts the highest values at the top of the image, and lowest values at the bottom, which is typically what you want for colorbar legends
- on the command line (outside of R), using ANTS' convertScalarImageToRGB:
ConvertScalarImageToRGB 2 colorbarImage.nii colorbarImageJet.jpg colorbarImageMask.nii jet
This creates a jpg of a bar with the range of colors matching, in this case, the "jet" colormap. Reading this into whatever you use to create figures (e.g., powerpoint) allows you to add text indicating values for different parts of the range.