Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Which LUTs is my image using?
#@ LUTService lut
#@ DatasetView dv
#@ boolean verbose
def printColorTable = { t ->
if (t == null) {
println(" null")
return
}
for (comp = 0; comp < t.getComponentCount(); comp++) {
for (bin = 0; bin < t.getLength(); bin++) {
print(" " + t.get(comp, bin))
}
println()
}
}
def colorTablesEqual = { t1, t2, inverted ->
if (t1 == null && t2 == null) return true
if (t1 == null || t2 == null) return false
if (t1.getComponentCount() != t2.getComponentCount()) return false
if (t1.getLength() != t2.getLength()) return false
for (comp = 0; comp < t1.getComponentCount(); comp++) {
for (bin = 0; bin < t1.getLength(); bin++) {
index = inverted ? t1.getLength() - bin - 1 : bin
if (t1.get(comp, bin) != t2.get(comp, index)) return false
}
}
return true
}
// Load color tables
colorTables = [:]
for (entry in lut.findLUTs().entrySet()) {
colorTables[entry.getKey()] = lut.loadLUT(entry.getValue())
}
println("== Available color tables ==")
for (entry in colorTables.entrySet()) {
name = entry.getKey()
colorTable = entry.getValue()
println(name)
if (verbose) printColorTable(colorTable)
}
println()
println("== Active image color tables ==")
channelTables = dv.getColorTables()
for (c = 0; c < channelTables.size(); c++) {
print("Channel #${c}")
if (verbose) {
println()
printColorTable(channelTables[c])
}
for (entry in colorTables.entrySet()) {
name = entry.getKey()
colorTable = entry.getValue()
if (colorTablesEqual(channelTables[c], colorTable, false)) {
println(" --> MATCH: ${name}")
}
else if (colorTablesEqual(channelTables[c], colorTable, true)) {
println(" --> MATCH: ${name} (inverted)")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment