Altering channel names in M9

Quick scripting question.

Users can alter the names of channels directly in the Brightness/Contrast window (double click), or drag a text file on to them to apply name changes to all of the channels in a row, but after digging through the videos and my old emails a bit, I’m still not sure how to apply channel name changes through a script.

imageData = getCurrentImageData()
server = imageData.getServer()
metaData = server.getMetadata()
print metaData
//describe(metaData)
//here I find out getChannels needs to be fed into a List

List channels
channels = metaData.getChannels()
describe(channels[0])

//Not sure how to do this.
//channels[0].setName()

I’ve gotten this far, but when describing a channel through the metaData, there isn’t a setName option.

Digging around a bit more I came up with the following, which changes the channel name… but it isn’t updated in the brightness and contrast window, even when I close and reopen the window. Not sure how to work in what I assume is the table.refresh() that would do that.

import qupath.lib.images.servers.ImageServerMetadata;
import qupath.lib.images.servers.ImageChannel

imageData = getCurrentImageData()
server = imageData.getServer()
metadata = server.getMetadata()
print metadata
//describe(metaData)
List channels
channels = metadata.getChannels()
//n = metaData.getnChannels()
//describe(channels[0])
//channels[0].setName()
print channels
channels.set(0, ImageChannel.getInstance("hi", channels[0].getColor()));
metadata2 = new ImageServerMetadata.Builder(metadata).channels(channels).build();

imageData.updateServerMetadata(metadata2);

image

It’s a lot simpler now… see https://github.com/petebankhead/qupath/pull/37#issuecomment-586469880

Still need to add it to the documentation. In general, I’d like to avoid any need to work with things like ImageMetadata directly (or at least only to read it, not modify it), since it’s rather complicated and can make scripts more brittle. Over time, more and more things that have previously required lengthy scripts should be reduced to at most one or two lines.

1 Like

Gah, thanks, I didn’t check issues.

Not just issues, a closed pull request my own fork… properly obscure :slight_smile: It’ll go in the documentation when I find the time to add it, likely after m10…

For anyone else that stumbles across this:


Fill in all channel names as comma separated strings, and you are set.

*And I’m about 95% sure it was used as a script in the LJI presentations, I just couldn’t find it :frowning: