/** * MRI Adipocyte Tools * * The Adipocytes Tools help to analyze fat cells in images from histological sections. * * (c) 2020, INSERM * written by Volker Baecker at Montpellier Ressources Imagerie, Biocampus Montpellier, INSERM, CNRS, University of Montpellier (www.mri.cnrs.fr) * * in collaboration with Matthieu Lacroix and Patricia Cavelier */ var helpURL = "https://github.com/MontpellierRessourcesImagerie/imagej_macros_and_scripts/wiki/Adipocytes-Tools" // Preprocessing options var preMinSize = 80; var preMaxSize = 20000; var preThresholdMethod = "Percentile"; var preNumberOfDilates = 10; var preRemoveScale = true; // Simple segmentation options var simpleMinSize = 40; var simpleMaxSize = 6000; var simpleThresholdMethod = "Huang"; var simpleUseBinaryWatershed = true; var simpleFindEdges = true; var simpleClearBackground = true; var simpleRemoveScale = true // Watershed segmentation options var waterMinSize = 50; var waterMaxSize = 20000; var waterSigma = 4; var waterFindEdges = true; var waterClearBackground = true; var waterRemoveScale = true; // Large magnification segmentation options var largeMinSize = 10000; var largeMaxSize = "Infinity"; var largeRemoveScale = true; var largeNumberOfErodes = 3; // Internal variables to set and reset the colors var oldForeground; var oldBackground; // run a function here: exit(); // Main functions start //
- preprocessing clear background
function preProcessImage() {
roiManager("reset");
storeColors();
setWhiteOnBlack();
if (preRemoveScale) run("Set Scale...", "distance=0 known=0 pixel=1 unit=pixel");
clearBackground(preMinSize, preMaxSize, preThresholdMethod, preNumberOfDilates, false);
resetColors();
setBatchMode("exit and display");
}
function clearBackground(minSize, maxSize, thresholdMethod, numberOfDilates, keepSelection) {
run("Duplicate...", " ");
saveSettings();
setOption("black background", false);
run("Find Edges");
run("8-bit");
run("Smooth");
setAutoThreshold(thresholdMethod);
run("Analyze Particles...", "size="+minSize+"-"+maxSize+" circularity=0.00-1.00 show=Masks exclude in_situ");
run("Create Selection");
run("Enlarge...", "enlarge=" + numberOfDilates + " pixel");
roiManager("Add");
close();
roiManager("select", 0);
run("Clear Outside");
roiManager("reset");
if (!keepSelection) run("Select None");
restoreSettings();
}
// - simple adipocytes segmentation
function simpleSegmentation() {
run("Duplicate...", " ");
run("ROI Manager...");
roiManager("Show All with labels");
setBatchMode(true);
roiManager("reset");
storeColors();
setWhiteOnBlack();
if (simpleRemoveScale) run("Set Scale...", "distance=0 known=0 pixel=1 unit=pixel");
if (simpleUseBinaryWatershed && simpleClearBackground) clearBackground(preMinSize, preMaxSize, preThresholdMethod, preNumberOfDilates, true);
if (simpleRemoveScale) run("Set Scale...", "distance=0 known=0 pixel=1 unit=pixel");
if (simpleFindEdges) run("Find Edges");
run("8-bit");
if (simpleFindEdges) {
run("Smooth");
run("Invert");
}
setAutoThreshold(simpleThresholdMethod+ " dark");
run("Convert to Mask");
if (simpleUseBinaryWatershed) run("Watershed");
run("Clear Results");
run("Analyze Particles...", "size="+simpleMinSize+"-"+simpleMaxSize+" circularity=0.00-1.00 show=Nothing add exclude");
close();
if (simpleRemoveScale) run("Set Scale...", "distance=0 known=0 pixel=1 unit=pixel");
resetColors();
setBatchMode("exit and display");
if (isOpen("Results")) {
selectWindow("Results");
run("Close");
}
roiManager("Show All with labels");
}
//