general > RE: Ability to use custom atlas labels
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

Threaded View

TitleAuthorDate
Austen Casey May 14, 2023
Gergely Csucs May 15, 2023
Austen Casey Jun 16, 2023
Austen Casey Jun 17, 2023
RE: Ability to use custom atlas labels
Gergely Csucs Jun 20, 2023