Project

General

Profile

Files » Colony_Blob_Count_Tool.txt

Count the number of dark blobs in the image - Volker Baecker, 08/22/2012 11:43 AM

 
/**
* Colony Blob Count Tool
* Collaborators:
* Andrés B. Caicedo
*
* Count the number of dark blobs in the image. The dark blobs are
* bacteria colonies.
*
* (c) 2012, INSERM
* written by Volker Baecker at Montpellier RIO Imaging (www.mri.cnrs.fr)
*
*/

var helpURL = "http://dev.mri.cnrs.fr/wiki/imagej-macros/Colony_Blob_Count_Tool";
var tableName = "colony count";
var useMedianFilter = true;
var radiusMedianFilter = 8;
var useBackgroundSubtraction = true;
var rollingBallRadius=100;
var useGaussianFilter = true;
var sigmaGaussianFilter = 8;
var minSize = 500;
var maxSize = "Infinity";
var excludeOnEdges = true;

macro "Unused Tool - C037" { }

macro "Colony Blob Count Tool Help Action Tool - C000C111C222C333C444C555C666D4cD5bC666D3cD4bC666D6cC666D5aD5cDa6Db4C666D3bC666D59C666D4dDa5C666D3dD49D4aD69Db6C666D39D3aD6bDa4Db5DffC666D5dD85C666D4eD5eD95C666D6aD7cD86D96Dc5DfaC666D48D6dD7aD7bD97Da7Dc6DdfDfeC666D58D93Da3Da8Db8C666D2bD2cDfbDfdC777D68D79C777D94Db3DedDfcC777D0dD4fDa9Dc4C777DcfC777D2dD6eDb7Dc3Df9C777D0eD1eD75D7dD87D99Dc7C777D1dD83C777D98DeeC777D1fD2aD3fDefC777D2eD84Da2Dd5C777D3eD8bC777D0fD2fD92Db2Dd6C777D78DecDf8C777Dc2DddC777D74Db9Dc8DeaC777D0cD76D88C888D1cD57DbfC888DdeC888De9C888D82C888D29D38D77C888D47D5fD89C888D8aDe8C888DebC888Dd4C888D73D91C888Da1Dd9C888DdcC888D1bDc9Dd3Dd7C888Dd8Df7C888D7eD8cC888D66D67C999D1aDb1C999DceC999D0bD15D72D8dD9aC999D04D22Dd2C999DdaDe7C999D14D65C999D10D32D64D6fDaaC999D02D03D05D11D21D81Df0C999D00D06D0aD20De5De6C999D01D28D56C999D16D25D31D37D42Dc1C999D07D09D12D13D19D30D33D41C999D08D23D40D63D90Da0DbaC999D24D45D46D53D62D71D7fC999D17D26D43D50D52D80C999D18D27D34D35D36D51D70CaaaD55D60D61Db0CaaaD44D54D9bDf1Df6CaaaDbeDdbDe4CaaaDcaDcdCaaaD8fDacDafDc0Dd1CaaaD8eDabDadDe2CaaaDbbDbdDccDd0De3CaaaD9dDbcDe0Df5CaaaD9cDe1CaaaD9fDaeDcbDf2Df4CaaaD9eDf3"{
run('URL...', 'url='+helpURL);
}

macro 'select colonies Action Tool - C000T4b12s' {
roiManager("Reset");
run("16-bit");
if (useMedianFilter) run("Median...", "radius=" + radiusMedianFilter);
if (useBackgroundSubtraction) run("Subtract Background...", "rolling="+rollingBallRadius+" light");
if (useGaussianFilter) run("Gaussian Blur...", "sigma=" + sigmaGaussianFilter);
setAutoThreshold("Default");
analyzerOptions = "size="+minSize+"-"+maxSize+" circularity=0.00-1.00 show=Nothing";
if (excludeOnEdges) analyzerOptions = analyzerOptions + " exclude";
analyzerOptions = analyzerOptions + " add";
run("Analyze Particles...", analyzerOptions);
run("Revert");
resetThreshold();
}

macro 'count selected colonies Action Tool - C000T4b12c' {
table = "["+ tableName + "]";
dir = getDirectory("image");
title = getTitle();
number = roiManager("count");

type = selectionType();
getSelectionCoordinates(xCoordinates, yCoordinates);

run("Clear Results");
roiManager("Measure");

areas = newArray(nResults);
for (i=0; i<nResults; i++) {
areas[i] = getResult("Area", i);
}
Array.getStatistics(areas, minArea, maxArea, meanArea, SDArea);
if (!isOpen(tableName)) {
run("Table...", "name="+table+" width=1000 height=300");
print(table, "\\Headings:dir\timage\tcount\tmean area\tSD\tmin. area\tmax. area");
}
print(table, dir + "\t" + title + "\t" + number + "\t" + meanArea + "\t" + SDArea + "\t" + minArea + "\t" + maxArea) ;
resetThreshold();

makeSelection(type, xCoordinates, yCoordinates);
}

macro 'save control image Action Tool - C000D23D24D25D26D27D28D29D2aD2bD2cD2dD33D3dD42D43D4dD52D53D5dD63D67D68D69D6dD73D76D77D79D7aD7dD83D86D8aD8dD93D96D97D99D9aD9dDa3Da7Da8Da9DadDb3DbdDc3DcdDd3DddDe3De4De5De6De7De8De9DeaDebDecDedC000C111C222C333C444C555C666C777C888C999CaaaCbbbCcccCdddCeeeCfff' {
controlImageFolder = "colonies-control-images";
outFolder = getDirectory("image") + controlImageFolder + "/";
title = getTitle();
beep();
run("Select None");
run("Flatten");
run("From ROI Manager");
run("Restore Selection");
if (!File.exists(outFolder)) File.makeDirectory(outFolder);
run("RGB Color");
color = getValue("color.foreground");
red=(color>>16)&0xff;
green=(color>>8)&0xff;
blue=color&0xff;
setForegroundColor(255,255,0);
run("Draw");
setForegroundColor(0,255,255);
roiManager("Draw");
setForegroundColor(red, green, blue);
saveAs("tiff", outFolder + title);
IJ.log("saved image: " + outFolder + title);
close();
roiManager("Show All with labels");
roiManager("Show All");
run("Restore Selection");
}

macro 'select colonies Action Tool Options' {
Dialog.create("select colonies options");
Dialog.addCheckbox("apply median filter", useMedianFilter);
Dialog.addNumber("radius of median filter", radiusMedianFilter);
Dialog.addCheckbox("apply background-subtraction", useBackgroundSubtraction);
Dialog.addNumber("radius for background subtraction", rollingBallRadius);
Dialog.addCheckbox("apply Gaussian filter", useGaussianFilter);
Dialog.addNumber("sigma of Gaussian filter", sigmaGaussianFilter);
Dialog.addNumber("minimum blob size", minSize);
Dialog.addNumber("maximum blob size", maxSize);
Dialog.addCheckbox("exclude on edges", excludeOnEdges);
Dialog.show();
useMedianFilter = Dialog.getCheckbox();
radiusMedianFilter= Dialog.getNumber();
useBackgroundSubtraction = Dialog.getCheckbox();
rollingBallRadius = Dialog.getNumber();
useGaussianFilter = Dialog.getCheckbox();
sigmaGaussianFilter = Dialog.getNumber();
minSize = Dialog.getNumber();
maxSize = Dialog.getNumber();
excludeOnEdges = Dialog.getCheckbox();
}
(2-2/3)