|
var helpURL = "http://dev.mri.cnrs.fr/wiki/imagej-macros/Count_Segments"
|
|
|
|
var subtractRadius = 10;
|
|
var filterRadius = 3;
|
|
var minSize = 60;
|
|
|
|
macro "Unused Tool - C037" { }
|
|
|
|
macro "Count Segments Help Action Tool - C000D0fD1fD2eD5cC000C100D00D04D06D07D08D09D0aD0bD0eD14D18D19D1aD1cD1dD1eD20D2cD2dD2fD30D3bD3cD3dD3eD3fD40D41D4bD4cD4dD4eD4fD5aD5bD5dD5eD5fD6aD6bD6cD6dD6eD9eD9fC100C200D01D02D03D05D0cD0dD10D11D12D13D15D16D17D1bD21D22D23D24D29D2aD2bD31D32D33D34D39D3aD42D43D48D4aD50D51D59D60D69D6fD79D7aD7bD7cD7dD7eD7fD8aD8bD8cD8dD8eD8fD9dDaeDafDd9DdaDdbDdfDe0De8De9DeaDebDecDedDeeDefDf8Df9DfaDfcDfdDfeDffC200C300D25D27D47D49D52D56D58D61D62D68D70D78D89D9aD9bD9cDadDbfDd0Dd1Dd7Dd8DdcDddDe1De7Df0Df1Df7DfbC300C400D57D65D66D67D71D72D77D80D81D87D88D90D91D98D99DacDc0Dc1Dc2Dc6Dc7Dc8Dc9DcaDd2Dd6DdeDe2De6Df2C400C500D75D76D82D85D86D92D97Db6Db7Dc5Dd5Df6C500C600D26D95D96DabDb8DbeDcbC600C700D44D53De5C800C900Db5De3Df3Df5C900Ca00Db2DccCa00Cb00D35D93Db0Db1Db9Dd3Cb00Cc00D83Dc3Cc00Cd00Ce00D63Db3Ce00Cf00D28D36D37D38D45D46D54D55D64D73D74D84D94Da0Da1Da2Da3Da4Da5Da6Da7Da8Da9DaaDb4DbaDbbDbcDbdDc4DcdDceDcfDd4De4Df4"{
|
|
run('URL...', 'url='+helpURL);
|
|
}
|
|
|
|
macro "Options Action Tool- C000T4b12o" {
|
|
Dialog.create("Count Segments Options");
|
|
Dialog.addNumber("subtract radius", subtractRadius);
|
|
Dialog.addNumber("filter radius", filterRadius);
|
|
Dialog.addNumber("min. size", minSize);
|
|
Dialog.show();
|
|
subtractRadius = Dialog.getNumber();
|
|
filterRadius = Dialog.getNumber();
|
|
minSize = Dialog.getNumber();
|
|
}
|
|
|
|
macro "Count Segments Action Tool- C000T4b12c" {
|
|
filename = getInfo("image.filename");
|
|
path = getInfo("image.directory");
|
|
title = getTitle();
|
|
setBatchMode(true);
|
|
number = countSegmentsOnCurrentImage(title);
|
|
print(filename + "," + number + "," + path);
|
|
setBatchMode(false);
|
|
run("Enhance Contrast", "saturated=0.35");
|
|
updateDisplay();
|
|
}
|
|
|
|
macro "Count Segments Batch Action Tool- C000T4b12b" {
|
|
|
|
progressTitle = "[Progress]";
|
|
run("Text Window...", "name="+ progressTitle +" width=25 height=2 monospaced");
|
|
|
|
IJ.log("\\Clear");
|
|
print("subtractRadius=" + subtractRadius + ",filterRadius=" + filterRadius + ",minSize=" + minSize);
|
|
print("file,count,path");
|
|
|
|
call("fr.cnrs.mri.macro.io.IOSettings.resetFileLists");
|
|
call("fr.cnrs.mri.macro.io.IOSettings.show");
|
|
waitForUser("Please select the input files using the IOSettings dialog and press ok");
|
|
|
|
list = call("fr.cnrs.mri.macro.io.IOSettings.getFileList");
|
|
files = split(list, ",");
|
|
if (list=="none") {
|
|
IJ.log("No files selected! Macro stopped.");
|
|
return;
|
|
}
|
|
setBatchMode(true);
|
|
length = files.length;
|
|
for (i=0; i<length; i++) {
|
|
print(progressTitle, "\\Update:"+i+"/"+length+" ("+(i*100)/length+"%)\n"+getBar(i, length));
|
|
file = files[i];
|
|
open(file);
|
|
filename = getInfo("image.filename");
|
|
path = getInfo("image.directory");
|
|
title = getTitle();
|
|
number = countSegmentsOnCurrentImage(title);
|
|
inFolder = File.getParent(file);
|
|
outFolder = inFolder + "/control/";
|
|
if (!File.exists(outFolder)) File.makeDirectory(outFolder);
|
|
saveAs("tiff", outFolder + title);
|
|
close();
|
|
print(filename + "," + number + "," + path);
|
|
}
|
|
selectWindow("Log");
|
|
timeStamp = getTimeStamp();
|
|
saveAs("Text", inFolder + "/Results " + timeStamp + ".xls");
|
|
setBatchMode(false);
|
|
print(progressTitle, "\\Close");
|
|
print("FINISHED");
|
|
}
|
|
|
|
function getTimeStamp() {
|
|
getDateAndTime(year, month, dayOfWeek, dayOfMonth, hour, minute, second, msec);
|
|
timeString = "" + year + "-" + ( month+1) + "-" + dayOfMonth + " " + hour +"-" + minute +"-" + second + "-" +msec;
|
|
return timeString;
|
|
}
|
|
|
|
function getBar(p1, p2) {
|
|
n = 20;
|
|
bar1 = "--------------------";
|
|
bar2 = "********************";
|
|
index = round(n*(p1/p2));
|
|
if (index<1) index = 1;
|
|
if (index>n-1) index = n-1;
|
|
return substring(bar2, 0, index) + substring(bar1, index+1, n);
|
|
}
|
|
|
|
function countSegmentsOnCurrentImage(title) {
|
|
run("Set Scale...", "distance=0 known=0 pixel=1 unit=pixel");
|
|
run("8-bit");
|
|
run("Red");
|
|
run("Duplicate...", "title=tmp");
|
|
run("Gaussian Blur...", "sigma=" + subtractRadius);
|
|
imageCalculator("Subtract create", title, "tmp");
|
|
rename("tmp2");
|
|
selectImage("tmp");
|
|
close();
|
|
selectImage("tmp2");
|
|
run("Gaussian Blur...", "sigma=" + filterRadius);
|
|
setAutoThreshold("IsoData dark");
|
|
run("Convert to Mask");
|
|
run("Skeletonize");
|
|
run("Analyze Particles...", "size="+minSize+"-Infinity circularity=0.00-1.00 show=Masks in_situ");
|
|
if (isOpen("Results")) {
|
|
selectWindow("Results");
|
|
run("Close");
|
|
}
|
|
selectImage("tmp2");
|
|
|
|
// find skeleton endpoints
|
|
w = getWidth();
|
|
h = getHeight();
|
|
setKeyDown("shift");
|
|
number = 0;
|
|
showStatus("detecting skeleton end-points");
|
|
for (x=0; x < w; x++) {
|
|
for (y=0; y < h; y++) {
|
|
showProgress((x*h + y) / (w*h));
|
|
if (getPixel(x,y) == 255) {
|
|
count = getPixel(x-1,y-1) +
|
|
getPixel(x,y-1) +
|
|
getPixel(x+1,y-1) +
|
|
getPixel(x-1,y) +
|
|
getPixel(x+1,y) +
|
|
getPixel(x-1,y+1) +
|
|
getPixel(x,y+1) +
|
|
getPixel(x+1,y+1);
|
|
if (count==255) {
|
|
makePoint(x,y);
|
|
number++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
setKeyDown("none");
|
|
selectImage(title);
|
|
run("Restore Selection");
|
|
selectImage("tmp2");
|
|
close();
|
|
result = round(number / 2);
|
|
showStatus("");
|
|
return result;
|
|
}
|