Script to rename channels and adjust brightness&contrast

Hello,

I am trying to get a script to rename channels and adjust the min/max values to display for each channel. I have tried the code below to adjust the channels that I took from here but it doesn’t change any of the images of my project:

Thank you!
Pasquale

//From https://github.com/qupath/qupath/issues/191
//https://groups.google.com/forum/#!searchin/qupath-users/viewer%7Csort:date/qupath-users/uBMxJ_3JnBM/GkDahJw7EAAJ
// Get access to the display info for each channel
//0.1.2 
//For 0.2.0 use viewer.getImageDisplay().availableChannels()

def viewer = getCurrentViewer()
def channels = viewer.getImageDisplay().availableChannels()


// Set the range for the first two channels
channels[0].setMinDisplay(0)
channels[0].setMaxDisplay(100)
channels[1].setMinDisplay(0)
channels[1].setMaxDisplay(500)
channels[2].setMinDisplay(0)
channels[2].setMaxDisplay(100)
channels[3].setMinDisplay(0)
channels[3].setMaxDisplay(500)

// Ensure the updates are visible
viewer.repaintEntireImage()

// Usually a good idea to print something, so we know it finished
print 'Done!'

This code works for me for the current viewer. I don’t think it should work when run for project as there is not a current viewer. If you have changed the current viewer, however, and have
image
Keep settings checked, those settings should be kept for any other image you open as well.

1 Like

As I wrote yesterday, that method of setting channel display ranges is an old hack-y approach that is not supported. Did you try the alternative that I posted?

There is a counterpart for setting channel names, i.e.

setChannelNames('Something', 'Something else')

Sorry, missed the key bit – the new method for the display range is

setChannelDisplayRange(channel, minValue, maxValue)

where channel can be a String name or a number.

So basically there are methods for all the following

setChannelColor
setChannelNames
setChannelDisplayRange

and they are the ‘new’ ways to do things, avoiding the getImageDisplay().availableChannels() stuff.

1 Like