Skip to content

Instantly share code, notes, and snippets.

@zktuong
Created March 22, 2017 03:25
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/2b281aed13a089abb1de2b03a177754d to your computer and use it in GitHub Desktop.
Save zktuong/2b281aed13a089abb1de2b03a177754d to your computer and use it in GitHub Desktop.
Basic imagej macro to count DAB positively stained nuclei from IHC experiments
// To run this script, you need to first save screen grab of your tiff.
// This script is set up for 50-66% zoom in OliVia.
// Then click Run when you're ready and wait for prompts. =)
// splits images to other colors
run("Set Measurements...", "area limit redirect=None decimal=3");
run("Colour Deconvolution", "vectors=[H DAB]");
waitForUser("Image selection", "Please select the brown image as have it as the front image. Then Click 'OK'.")
// change brown image to b/w
run("8-bit");
run("Invert");
setTool("polygon");
waitForUser("Exluding areas you don't want", "Please draw around the area you want to exlude. Then Click 'OK'.")
roiManager("Add")
run("Clear", "slice");
roiManager("Deselect")
run("Select All");
run("Subtract...", "value=50");
setAutoThreshold("Default dark");
// Thresholding. Try and cover as much as you can, to the point of over estimating.
run("Threshold...");
setOption("BlackBackground", false);
waitForUser("Thresholding", "Please drag the red threshold until you have covered the objects you want to include as precise as you can. Then Click 'OK'.")
// Convert to binary and fill holes + split cells.
run("Convert to Mask");
run("Close-");
run("Fill Holes");
run("Watershed");
// You may need to adjust the "size=..." value if you use a differently sized image. It is currently set up for 66% zoom.
// If you want to use a lower magnification image, you can decrease the min size accordingly
run("Analyze Particles...", "size=100-3000 show=[Overlay Masks] display exclude clear summarize");
// Check your original image with the overlay.
// If you're not happy, redo the thresholding, or adjust the size in the script.
// Count number of cells in field of analysis, exlcuding the region excluded earlier
waitForUser("Select blue channel", "Please and select the blue channel NOW. Click 'OK' when ready.")
run("8-bit");
run("Invert");
run("Subtract...", "value=20");
roiManager("Select", 0);
setBackgroundColor(0, 0, 0);
run("Clear", "slice");
roiManager("Deselect");
run("Select All");
setAutoThreshold("Default dark");
run("Threshold...");
waitForUser("Threshold the nuclei", "Drag the red threshold until you have covered the nuclei as precise as you can. Click 'OK' when ready.")
run("Convert to Mask");
run("Close-");
run("Fill Holes");
run("Watershed");
run("Set Measurements...", "limit redirect=None decimal=3");
run("Analyze Particles...", "size=100-3000 show=[Overlay Masks] display exclude summarize");
// Copy the resulting table to excel and ta-da you have your results.
waitForUser("Last", "Cross check with original image and ammend the cell count accordingly. Copy results table to spreadsheet. Click 'OK' to close all. Seeya and thank you!")
run("Close All");
roiManager("Delete");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment