Skip to content

Instantly share code, notes, and snippets.

@zktuong
Created September 8, 2021 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zktuong/a474abfe75772d5a28c2b44af01fe408 to your computer and use it in GitHub Desktop.
Save zktuong/a474abfe75772d5a28c2b44af01fe408 to your computer and use it in GitHub Desktop.
name=getTitle;
dir = getDirectory("image");
path=dir+name
Final2 = path+"_final"
run("Set Measurements...", "area limit redirect=None decimal=3");
Stack.setDisplayMode("color");
Stack.setChannel(2);
resetMinAndMax();
Stack.setChannel(3);
resetMinAndMax();
Stack.setChannel(4);
resetMinAndMax();
run("8-bit");
run("Set Scale...", "distance=0 known=0 pixel=1 unit=pixel");
makeRectangle(528, 581, 250, 250);
waitForUser("MOVE THE SQUARE", "Please move the square to cover the cell you want to crop. Then Click 'OK'.")
run("Crop");
setLocation(0,0)
run("Duplicate...", "title=Analysis duplicate channels=2-4");
selectWindow("Analysis")
setLocation(255,0)
run("Duplicate...", "title=Analysis.1 duplicate");
selectWindow("Analysis.1")
setLocation(510,0)
selectWindow("Analysis")
Stack.setChannel(1);
run("Blue");
Stack.setChannel(2);
run("Green");
Stack.setChannel(3);
run("Red");
run("Split Channels");
selectWindow("C1-Analysis")
setLocation(255,0)
selectWindow("C2-Analysis")
setLocation(255,320)
selectWindow("C3-Analysis")
setLocation(255,640)
selectWindow("Analysis.1")
Stack.setChannel(1);
run("Blue");
Stack.setChannel(2);
run("Green");
Stack.setChannel(3);
run("Red");
run("Split Channels");
selectWindow("C1-Analysis.1")
setLocation(255,0)
selectWindow("C2-Analysis.1")
setLocation(255,320)
selectWindow("C3-Analysis.1")
setLocation(255,640)
// making masks for blue channel
selectWindow("C1-Analysis")
run("Grays");
run("Threshold...");
selectWindow("Threshold")
setLocation(1520,350)
selectWindow("C1-Analysis")
setAutoThreshold("Shanbhag dark");
selectWindow("Threshold")
waitForUser("Blue Channel Threshold", "Adjust Threshold for Blue Channel. Click 'OK' when ready.")
run("Set Scale...", "distance=0 known=0 pixel=1 unit=pixel");
for(i=1; i<nSlices+1; i++) {
    setSlice(i);
run("Measure");
}
selectWindow("Results")
setLocation(1520,110)
selectWindow("C1-Analysis")
run("Convert to Mask", "method=Default background=Dark list");
run("Duplicate...", "title=CD8a duplicate");
selectWindow("CD8a")
setLocation(255,0)
selectWindow("C1-Analysis")
run("Divide...", "value=255 stack");
imageCalculator("Multiply create stack", "C1-Analysis.1","C1-Analysis");
selectWindow("Result of C1-Analysis.1")
setLocation(255,0)
// making masks for green channel
selectWindow("C2-Analysis")
run("Grays");
setAutoThreshold("Shanbhag dark");
selectWindow("Threshold")
waitForUser("Green Channel Threshold", "Adjust Threshold for Green Channel. Click 'OK' when ready.")
run("Set Scale...", "distance=0 known=0 pixel=1 unit=pixel");
for(i=1; i<nSlices+1; i++) {
    setSlice(i);
run("Measure");
}
run("Convert to Mask", "method=Default background=Dark list");
run("Duplicate...", "title=CD8b duplicate");
selectWindow("CD8b")
setLocation(255,320)
selectWindow("C2-Analysis")
run("Divide...", "value=255 stack");
imageCalculator("Multiply create stack", "C2-Analysis.1","C2-Analysis");
selectWindow("Result of C2-Analysis.1")
setLocation(255,320)
// making masks for red channel
selectWindow("C3-Analysis")
run("Grays");
setAutoThreshold("Shanbhag dark");
selectWindow("Threshold")
waitForUser("Red Channel Threshold", "Adjust Threshold for Red Channel. Click 'OK' when ready.")
run("Set Scale...", "distance=0 known=0 pixel=1 unit=pixel");
for(i=1; i<nSlices+1; i++) {
    setSlice(i);
run("Measure");
}
run("Convert to Mask", "method=Default background=Dark list");
run("Duplicate...", "title=CD4 duplicate");
selectWindow("CD4")
setLocation(255,640)
selectWindow("C3-Analysis")
run("Divide...", "value=255 stack");
imageCalculator("Multiply create stack", "C3-Analysis.1","C3-Analysis");
selectWindow("Result of C3-Analysis.1")
setLocation(255,640)
// count for dimers
imageCalculator("Multiply create stack", "Result of C2-Analysis.1","C1-Analysis");
selectWindow("Result of Result of C2-Analysis.1")
rename("CD8ab Dimer")
setLocation(510,0)
run("Duplicate...", "title=CD8ab_duplicate duplicate");
selectWindow("CD8ab_duplicate")
setLocation(510,0)
run("Threshold...");
selectWindow("Threshold")
setAutoThreshold("Shanbhag dark");
setThreshold(1, 255);
run("Set Scale...", "distance=0 known=0 pixel=1 unit=pixel");
for(i=1; i<nSlices+1; i++) {
    setSlice(i);
run("Measure");
}
// count for trimers
selectWindow("CD8ab_duplicate")
run("Convert to Mask", "method=Default background=Dark list");
run("Divide...", "value=255 stack");
imageCalculator("Multiply create stack", "Result of C3-Analysis.1","CD8ab_duplicate");
selectWindow("Result of Result of C3-Analysis.1")
setLocation(510,320)
rename("Trimer")
run("Threshold...");
setThreshold(1, 255);
run("Set Scale...", "distance=0 known=0 pixel=1 unit=pixel");
for(i=1; i<nSlices+1; i++) {
    setSlice(i);
run("Measure");
}
// CD8aCD4
selectWindow("Result of C3-Analysis.1")
selectWindow("CD4")
run("Divide...", "value=255 stack");
imageCalculator("Subtract create stack", "Result of C1-Analysis.1","CD8b");
selectWindow("Result of Result of C1-Analysis.1")
setLocation(510,640)
imageCalculator("Multiply create stack", "Result of Result of C1-Analysis.1","CD4");
selectWindow("Result of Result of Result of C1-Analysis.1")
rename("CD8a CD4")
setLocation(510,640)
run("Threshold...");
setThreshold(1, 255);
run("Set Scale...", "distance=0 known=0 pixel=1 unit=pixel");
for(i=1; i<nSlices+1; i++) {
    setSlice(i);
run("Measure");
}
// CD8bCD4
imageCalculator("Subtract create stack", "Result of C2-Analysis.1","CD8a");
rename("CD8b only")
setLocation(765,640)
imageCalculator("Multiply create stack", "CD8b only","CD4");
setLocation(765,640)
rename("CD8b CD4")
run("Threshold...");
setThreshold(1, 255);
run("Set Scale...", "distance=0 known=0 pixel=1 unit=pixel");
for(i=1; i<nSlices+1; i++) {
    setSlice(i);
run("Measure");
}
selectWindow("CD8ab Dimer")
run("Cyan");
selectWindow("Result of C1-Analysis.1")
rename("CD8a Total")
selectWindow("Result of C2-Analysis.1")
rename("CD8b Total")
selectWindow("Result of C3-Analysis.1")
rename("CD4 Total")
selectWindow("Trimer")
run("Grays");
selectWindow("CD8a CD4")
run("Magenta");
selectWindow("CD8b CD4")
run("Yellow");
selectWindow("Threshold")
run("Close")
run("Merge Channels...", "c1=[CD4 Total] c2=[CD8b Total] c3=[CD8a Total] c4=Trimer c5=[CD8ab Dimer] c6=[CD8a CD4] c7=[CD8b CD4] create keep");
selectWindow("Composite")
setLocation(765,320)
rename(name)
waitForUser("Ready to Save and Close?", "When ready to save and close, click 'OK' to close.")
saveAs("Tiff");
selectWindow("Results");
saveAs("Text", path);
selectWindow("Results");
run("Close");
run("Close All")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment