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

colorbar key for antsrSurf #376

Open
ptsii opened this issue Dec 7, 2022 · 6 comments
Open

colorbar key for antsrSurf #376

ptsii opened this issue Dec 7, 2022 · 6 comments

Comments

@ptsii
Copy link

ptsii commented Dec 7, 2022

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
Copy link
Member

stnava commented Dec 7, 2022

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
Copy link
Member

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
Copy link
Member

stnava commented Dec 7, 2022

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
Copy link
Author

ptsii commented Apr 3, 2023

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
Copy link
Member

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
Copy link
Author

ptsii commented Apr 3, 2023

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

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

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

3 participants