Last active
April 15, 2021 18:26
-
-
Save kwolbachia/fb64422dd69851e6b9d106a74edafa1b to your computer and use it in GitHub Desktop.
imageJ Fiji Splitview macro
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
/*---------------------------------------------------------------------------------------------------------------------- | |
For multichannel visualization, 5 channel max | |
This macro will generate a montage of composite and splited channels in one RGB Image | |
You can still navigate through slices or frames. | |
Note : the Splitview image size can be heavy on big hyperstacks due to RGB conversion | |
Advice : draw a selection before running Spliview, the produced montage will be croped | |
The new version can ask tu user channel labels and add it in the Splitview with color corresponding to each LUTs. | |
----------------------------------------------------------------------------------------------------------------------*/ | |
var ChLabels = newArray("GFP","RFP","fRFP","DAPI","Brightfield"); | |
var fontS = 30; | |
var Ch = newArray(1); | |
var chan = 1; | |
//This one will give a colored linear montage with labels : | |
macro "Splitview color [S]" {SplitView(1,0,1);} | |
/*---------------------------------------------------------------------------------------------------------------------- | |
main Splitview function : aguments works as follow : | |
color : 0 = grayscale , 1 = color | |
style : 0 = linear montage , 1 = squared montage , 2 = vertical montage | |
labels : 0 = no , 1 = yes. | |
----------------------------------------------------------------------------------------------------------------------*/ | |
function SplitView(color,style,labels) { | |
setBatchMode(true); | |
title = getTitle(); | |
Setup_Splitview(color,labels);//up until split | |
if(style==1) squareView(); | |
if(style==0) linearView(); | |
if(style==2) verticalView(); | |
rename(title + " Splitview"); | |
setBatchMode("exit and display"); | |
} | |
function Setup_Splitview(color,labels){ | |
getDimensions(w, h, ch, Z, T); | |
if (ch == 1) exit("only one channel"); | |
if (ch > 5) exit("5 channels max"); | |
run("Duplicate...", "title=image duplicate"); | |
if ((Z>1)&&(T==1)) {T=Z; Z=1; Stack.setDimensions(ch,Z,T); } | |
Ch = newArray(ch); chan = ch; | |
getDimensions(w,h,ch,Z,T); | |
fontS = h/9; | |
run("Duplicate...", "title=split duplicate"); | |
run("Split Channels"); | |
selectWindow("image"); | |
Stack.setDisplayMode("composite"); | |
if (labels) { | |
getLabels(); | |
setColor("white"); | |
setFont("SansSerif", fontS, "bold antialiased"); | |
Overlay.drawString("Merge",h/20,fontS); | |
Overlay.show; | |
run("Flatten","stack"); | |
rename("overlay"); Ch[0] = getTitle(); | |
close("image"); | |
for (i = 1; i <= chan; i++) { | |
selectWindow("C"+i+"-split"); | |
id = getImageID(); | |
getLut(r, g, b); | |
setColor(r[255], g[255], b[255]); | |
if (!color) run("Grays"); | |
Overlay.drawString(ChLabels[i-1],h/20,fontS); Overlay.show; | |
if (Z*T>1) run("Flatten","stack"); | |
else { run("Flatten"); selectImage(id); close(); } | |
Ch[i]=getTitle(); | |
} | |
} | |
else { | |
run("RGB Color", "frames"); | |
rename("overlay"); Ch[0] = getTitle(); | |
close("image"); | |
for (i = 1; i <= chan; i++) { | |
selectWindow("C"+i+"-split"); | |
if(!color)run("Grays"); | |
run("RGB Color", "slices"); | |
Ch[i]=getTitle(); | |
} | |
} | |
} | |
function getSpVpref(){ | |
Dialog.createNonBlocking("Labeled Prefs"); | |
Dialog.addMessage("choose your weapon!"); | |
Dialog.addRadioButtonGroup("Color style", newArray("Colored","Grayscale"), 1, 3, "Colored"); | |
Dialog.addRadioButtonGroup("Montage style", newArray("Linear","Square","Vertical"), 1, 3, "Linear"); | |
Dialog.show(); | |
color = Dialog.getRadioButton(); | |
style = Dialog.getRadioButton(); | |
if (color=="Colored" &&style=="Linear") SplitView(1,0,1); | |
else if(color=="Grayscale"&&style=="Linear") SplitView(0,0,1); | |
else if(color=="Colored" &&style=="Square") SplitView(1,1,1); | |
else if(color=="Grayscale"&&style=="Square") SplitView(0,1,1); | |
else if(color=="Colored" &&style=="Vertical") SplitView(1,2,1); | |
else if(color=="Grayscale"&&style=="Vertical") SplitView(0,2,1); | |
} | |
function getLabels(){ | |
Dialog.createNonBlocking("Provide channel names"); | |
for (a = 0; a < 5; a++) Dialog.addString("Channel "+a+1, ChLabels[a],12); | |
Dialog.addNumber("Font size", fontS); | |
Dialog.show(); | |
for (k = 0; k < 5; k++) {ChLabels[k] = Dialog.getString();} | |
fontS = Dialog.getNumber(); | |
} | |
function squareView(){ | |
C1_C2 = Combine_Hor(Ch[1],Ch[2]); | |
if (chan==2||chan==4)C1_C2_Ov = Combine_Hor(C1_C2,Ch[0]); | |
if (chan==3){ C3_Ov = Combine_Hor(Ch[3],Ch[0]); Combine_Ver(C1_C2,C3_Ov);} | |
if (chan>=4) C3_C4 = Combine_Hor(Ch[3],Ch[4]); | |
if (chan==4) Combine_Ver(C1_C2_Ov,C3_C4); | |
if (chan==5){ C1234 = Combine_Ver(C1_C2,C3_C4); C5_Ov = Combine_Ver(Ch[5],Ch[0]); Combine_Hor(C1234,C5_Ov);} | |
} | |
function linearView(){ | |
C1_C2 = Combine_Hor(Ch[1],Ch[2]); | |
if (chan==2) Combine_Hor(C1_C2,Ch[0]); | |
if (chan==3){ C3_Ov = Combine_Hor(Ch[3],Ch[0]); Combine_Hor(C1_C2,C3_Ov);} | |
if (chan>=4){ C3_C4 = Combine_Hor(Ch[3],Ch[4]); C1234 = Combine_Hor(C1_C2,C3_C4);} | |
if (chan==4) Combine_Hor(C1234,Ch[0]); | |
if (chan==5){ C5_Ov = Combine_Hor(Ch[5],Ch[0]); Combine_Hor(C1234,C5_Ov);} | |
} | |
function verticalView(){ | |
C1_C2 = Combine_Ver(Ch[1],Ch[2]); | |
if (chan==2) Combine_Ver(C1_C2,Ch[0]); | |
if (chan==3){ C3_Ov = Combine_Ver(Ch[3],Ch[0]); Combine_Ver(C1_C2,C3_Ov);} | |
if (chan>=4){ C3_C4 = Combine_Ver(Ch[3],Ch[4]);C1234= Combine_Ver(C1_C2,C3_C4);} | |
if (chan==4) Combine_Ver(C1234,Ch[0]); | |
if (chan==5){ C5_Ov = Combine_Ver(Ch[5],Ch[0]); Combine_Ver(C1234,C5_Ov);} | |
} | |
function Combine_Hor(stack1,stack2){ //returns result image title *.* | |
run("Combine...", "stack1=&stack1 stack2=&stack2"); | |
rename(stack1+"_"+stack2); | |
return getTitle(); | |
} | |
function Combine_Ver(stack1,stack2){ | |
run("Combine...", "stack1=&stack1 stack2=&stack2 combine"); //vertically | |
rename(stack1+"_"+stack2); | |
return getTitle(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment