general > Ability to use custom atlas labels
Showing 1-8 of 8 posts
Display:
Results per page:
May 14, 2023  10:05 PM | Austen Casey - Stanford University
Ability to use custom atlas labels
I've been using QuickNII followed by Visualign to register 2D brain slices and quantify fluorescence in specific atlas labels using a custom FIJI macro. It works fairly well with ABA_Mouse_CCFv3_2017_25um, but I am having a hang up with the atlas outputs. Visualign gives 2 registered atlas images for each 2D slice (*.nl.png and *.nl_rbw.png). The *.nl.png files has ABA RGB values but at a low level of anatomical granularity (e.g., the whole midbrain has the same RGB value, ad the thalamus only have 2 or 3 different RGB values). in contrast, the *.nl_rbw.png files depict higher levels of anatomical, allowing for fluorescence quantification of discreet subregions of the midbrain and thalamus needed for my work. however, a given region in the *.nl_rbw.png files have different RGB values across different registered brain stacks, making it cumbersome to automatically pull ROI details across many brains (I need to manually identify the RGB for each brain before grabbing ROI details. 

Thus, I want to have VisuAlign output one of the following: 1) ABA labels at higher level of granularity, or 2) assign intensity values to specific brain regions such that the label intensity for each ROI is the same across brains. Is there any way to accomplish this by swapping out or editing the install files, or some other route of action?

Thank you for your time!
May 15, 2023  06:05 AM | Gergely Csucs
RE: Ability to use custom atlas labels
Yes, those simply are the official colors from Allen. Like here: http://atlas.brain-map.org/atlas?atlas=1&plate=100960264#atlas=1&plate=100960264&resolution=11.97&x=5400.032784598215&y=3807.9077849217824&zoom=-3 - colors are just reused countless times.
However it may be worth pointing out here that the two kinds of PNG sets are more meant for a quick view than for further processing. For the latter purpose the ".flat" files may still be a better choice even with their weirdness, https://www.nitrc.org/plugins/mwiki/index.php?title=visualign:Flat_file_format

But, the request is doable too, it's already there: VisuAlign has its atlas data in its "cutlas" folders, ABA_Mouse_CCFv3_2017_25um.cutlas may be the one in use here. Inside the folder there is a NIfTI file with the actual segmentation and a text file with the label descriptors (there is a short summary about the structure at the beginning of the file). Technically it's an ITK label file, just there are some labels with extreme high values, which ITK Snap usually refuses to load (but I haven't tried recently).

I hope this helps, best regards,
Gergely Csucs
Jun 16, 2023  10:06 PM | Austen Casey - Stanford University
RE: Ability to use custom atlas labels

Hi Gergely,

Thank you for your reply. I looked into the .flat file link you provided and installed the pyflat package. However, I could not figure out how to use pyflat.py to output a greyscale filetype with ABA greyscale values so I could use quantify fluorescence based on label intensity. I tried running the following line from the terminal within the directory containing visualign outputs:

python *\pyflat.py flat=4728114R_RGB_0000_nl.flat output=Grayscale.png

Even though the code ran without an error, no "Greyscale.png" output was produced. 

Ultimately, I envision a Numpy script where I can use the Visualigned atlas labels to mask each brain region and quantify fluorescence values, cell counts, etc in the original fluorescence image. The impedement to this is obtaining consistent greyscale visualigned atlas labels of high anatomical granularity to serve as the mask. I think I can achieve this by manually modifying all RGB values in the labels.txt file such that *_nl.png outputs have higher anatomical granularity and give appropriate and consistent grey values when converted to 16 bit images. Although, this approach requires me to manually change each of the 500+ RGB values in labels.txt file. Do you know of an easier way for me to accomplish this goal?

Visualign performs really well for registration, and I'm not aware of any other program that does so well (current apporach is Deepslice -> QuickNII -> Visualign -> custom FIJI macros to quantify fluorescence). Any advice would be greatly appreciated.

Kind regards,

Austen

Jun 17, 2023  12:06 AM | Austen Casey - Stanford University
RE: Ability to use custom atlas labels

I figured out how to change the RGB values using copy/paste from excel files I already had for each ABA label (attached), but I guess I didn't think it through entirely. Even though I now get ABA RGB values at a high level of anatomical granularity for the Visualign *nl.png outputs, the greyscale version doesn't match ABA labels (which is my goal here). Any tips on getting the visualign outputs to give me .png images with atlas labels instead of RGB values?

Thanks!

Attachment: labels.txt
Jun 20, 2023  12:06 PM | Gergely Csucs
RE: Ability to use custom atlas labels

A simple thing is throwing away the eye candy part and just make all colors unique, for a computer, not necessarily to the human eye. And then based on the capabilities/needs of further software in use, either look up labels from the altered color table, or use a direct decoding approach.


This piece of code expects three parameters: label=somelabels.txt is the input, so the original label file taken from a "cutlas" folder of VisuAlign for example. valabel=someotherfile.txt is an output, preserving the identifiers, but applying the replacement of the colors. The third parameter is decode=yetanotherfile.txt, provides a decoding aid, may or may not be useful.


import sys,re

args={}
for arg in sys.argv[1:]:
pair=arg.split("=")
args[pair[0]]=pair[1]

header=[]
palette=[]
with open(args["label"]) as f:
with open(args["valabel"],"w") as lva:
with open(args["decode"],"w") as ldec:
idx=0
for line in f:
lbl=re.match(r'\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(.*)',line)
if not lbl:
lva.write(line)
ldec.write(line)
else:
lva.write(f'{lbl[1]}\t{idx & 255}\t{idx >> 8}\t0\t{lbl[5]}\n')
ldec.write(f'{idx}\t{idx & 255}\t{idx >> 8}\t0\t{lbl[5]}\n')
idx+=1

I called it relabel.py, and an example run is


python.exe relabel.py label=labels.txt valabel=valabel.txt decode=declabel.txt


Here valabel.txt is the one preserving identifiers, but replacing colors, practically it starts with R=G=B=0, then increases R from 0 to 255, then increases G to 1, and starts over from R=0. With this file you can overwrite labels.txt in the corresponding cutlas folder of VisuAlign (of course it's a good idea to keep a copy of the original), do an export, and then all colors are going to be unique, though not very pleasing to the eye.


Then whatever software is used next, may be able to look up labeling from this modified label file already.


The other output (declabel.txt) may come handy if custom software is used. As the RGB color components form a single, continuous index now (well, B is 0), that index can be decoded directly, index=R+G*256. This label file contains such numbers, ranging from "clear label" with R=G=B=index=0, to "retina" with R=47, G=5, (B=0), id=1327, which happens to be 5*256+47.


I hope this helps, best regards,


Gergely


 

Attachment: labelthing.zip
Aug 5, 2024  07:08 PM | Aaron Sathyanesan - University of Dayton
RE: Ability to use custom atlas labels

Hello Gergely


I tried using a modified python code to read the flat file, however, the output is a low-res PNG. What would I need to do in order to get a high-res PNG similar to what is the final output images using NUTIL? I am specifically interested in extracting the distinct cerebellar nuclei. If each of these nuclei have different colors, I can use fiji to extract ROI based on color information. However, currently the labeling in the final output of NUTIL yields the same color for all cerebellar nuclei.

 

However, since I do not need object counts, I just obtained the high-res color images using empty segmentation images in the NUTIL workflow. I got the high res maps but the distinct nuclei do not show up. I tried using one of your answers to relabel the label.txt file, but I am unsure how to proceed from here. Because the json file which was exported from Visualign does not open up in visualign itself. So, how would I go about getting only the high-resolution PNGs with each of the cerebellar nuclei (fastigial nucleus, interposed nucleus, and dentate nucleus) distinctly labeled?

 

Best

Aaron
Aug 6, 2024  11:08 AM | Gergely Csucs
RE: Ability to use custom atlas labels

Hi Aaron,



I tried using a modified python code to read the flat file, however, the output is a low-res PNG. What would I need to do in order to get a high-res PNG similar to what is the final output images using NUTIL?


Nutil gets that low-resolution image too, then scales it up to the desired resolution (of the image coming from Ilastik - typically). ImageJ/Fiji can do this too: Image menu, "Scale...", then type the needed resolution and set Interpolation to None.


I am specifically interested in extracting the distinct cerebellar nuclei. If each of these nuclei have different colors, I can use fiji to extract ROI based on color information. However, currently the labeling in the final output of NUTIL yields the same color for all cerebellar nuclei.


Yes, this issue comes up from time to time. A workaround is provided at https://www.nesys.uio.no/VisuAlign/relab... - it's a small tool that creates a label file with distinct colors (not necessarily for the human eye, but for programs like Fiji), that can be used with VisuAlign.

I hope this helps.


Best regards,
Gergely

Aug 20, 2024  05:08 PM | Aaron Sathyanesan - University of Dayton
RE: Ability to use custom atlas labels

Hi Gergely


Attached is the traceback. Also, I looked into your other solutions regarding upscaling the images, but for some reason, the downscaled images and the hi-res segmentations have different sizes and lengthXwidth ratios? Not sure what is going on here. I attached an example of this.


Appreciate your help on this matter very much.


Best
Aaron