Last active
March 10, 2022 15:01
-
-
Save mutterer/51021eb24d117bb9d4f43e5f020b6bb8 to your computer and use it in GitHub Desktop.
ImageJ Menu Tool that provides commands to create a LUT from a line selection or multipoints selection, store and restore LUT in/from Prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cmd = newMenu( "LUT Utils Menu Tool", | |
newArray( "LUT from RGB Points", "LUT from ROI", "Store LUT in Prefs", "Restore LUT from Prefs" ) ); | |
macro "LUT Utils Menu Tool - C037T0b12LT6b10uTbb10T" { | |
cmd = getArgument( ); | |
if ( cmd == "Store LUT in Prefs" ) { | |
getLut( reds, greens, blues ); | |
r = reds [ 0 ]; | |
g = greens [ 0 ]; | |
b = blues [ 0 ]; | |
for ( i = 1; i < reds.length; i ++ ) { | |
r = '' + r + ',' + reds [ i ]; | |
g = '' + g + ',' + greens [ i ]; | |
b = '' + b + ',' + blues [ i ]; | |
} | |
call( "ij.Prefs.set", "storedLUT.reds", r ); | |
call( "ij.Prefs.set", "storedLUT.greens", g ); | |
call( "ij.Prefs.set", "storedLUT.blues", b ); | |
} else if ( cmd == "Restore LUT from Prefs" ) { | |
reds = split( call( "ij.Prefs.get", "storedLUT.reds", "0,1" ), "," ); | |
greens = split( call( "ij.Prefs.get", "storedLUT.greens", "0,1" ), "," ); | |
blues = split( call( "ij.Prefs.get", "storedLUT.blues", "0,1" ), "," ); | |
setLut( reds, greens, blues ); | |
} else if ( cmd == "LUT from ROI" ) { | |
if (selectionType<0) { | |
w=getWidth; | |
h=getHeight; | |
makeLine(w/10, h/10, w/2, h/2, w/10, 9*h/10); | |
run("Fit Spline"); | |
} | |
s=256; | |
setRGBWeights(1, 0, 0); | |
r=getProfile(); | |
setRGBWeights(0, 1, 0); | |
g=getProfile(); | |
setRGBWeights(0, 0, 1); | |
b=getProfile(); | |
r=Array.resample(r, s); | |
g=Array.resample(g, s); | |
b=Array.resample(b, s); | |
newImage("LUT", "8-bit ramp", s, 30, 1); | |
setLut(r, g, b); | |
} else if ( cmd == "LUT from RGB Points" ) { | |
if (selectionType!=10) exit("Multipoint ROI needed"); | |
Roi.getCoordinates(x, y); | |
if (x.length<2) exit("Multipoint ROI with at least 2 points needed"); | |
r=newArray(); | |
g=newArray(); | |
b=newArray(); | |
for (i=0;i<x.length;i++) { | |
v=getPixel(x[i],y[i]); | |
r[i]=(0xffffff&v)>>16; | |
g[i]=(0xffff&v)>>8; | |
b[i]=(0xff&v); | |
} | |
newImage("Untitled", "8-bit ramp", 256, 32, 1); | |
Color.setLut(Array.resample(r,256), Array.resample(g,256), Array.resample(b,256)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment