ANTsX / ANTsR

R interface to the ANTs biomedical image processing library
https://antsx.github.io/ANTsR
Apache License 2.0
127 stars 35 forks source link

colorbar key for antsrSurf #376

Open ptsii opened 1 year ago

ptsii commented 1 year ago

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

stnava commented 1 year ago

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?

ntustison commented 1 year ago

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.

stnava commented 1 year ago

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.

ptsii commented 1 year ago

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?

ntustison commented 1 year ago

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 ) )
ptsii commented 1 year ago

Thank you for the hint! For future reference to anyone else needing the same thing, here is what I got to work:

1) 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

2) 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.