Thank you for your assistance. I am trying to run the new code with your adjustments to see whether the variables from the two result tables can be presented in a new table. Unfortunately the code is not producing any output table. Did it work with you?
Date: Tue, 13 Oct 2015 02:14:36 -0700
From:
[hidden email]To:
[hidden email]Subject: Re: Modify (or create) results table
Hi, I tried your macro and made some adjustments:
The "Auto Local Threshold" didn't work so I replaced it with "setAutoThreshold". You may have to check if it corresponds to your needs.
You will find modifications in //comments// that you can delete or edit.
You have access to all CustomTabStatFromResults functions as I copied/pasted it below "tab functions" from Gilles Carpentier's macro.
Tell me if it works for you.
____________________________________________________________________
// tab variables
var windowTabName="Stat Results Table",nameOfStatTab="["+windowTabName+"]",label="",undoErease="";
// stat variables
var nbPerim=0,TheTotalArea=0,meanPerim=0,meanObject=0;
dir1 = getDirectory("Choose Source Directory ");
// Do you use it after?//dir2 = getDirectory("Choose Destination Directory ");
list = getFileList(dir1);
setBatchMode(true);
for (i=1; i<list.length; i++) {
showProgress(i+1, list.length);
open(dir1+list[i]);
run("Min...", "value=140");
run("8-bit");
// Changed to AutoThreshold// run("Auto Local Threshold", "method=Median radius=15 parameter_1=0 parameter_2=0 white");
setAutoThreshold("Mean");
setOption("BlackBackground", false);
run("Set Scale...", "distance=1617 known=21.8 pixel=1 unit=cm");
run("Set Measurements...", "area perimeter shape feret's display redirect=None decimal=2");
run("Analyze Particles...", "size=0.05-Infinity circularity=0.2-1.00 show=[Overlay Outlines] display include summary record in_situ");
makeStatFromResults ();
//removed //if (i==1) TabWindow (0); else
TabWindow (1);
selectWindow("Results");
run("Close");
run("Gaussian Blur...", "sigma=50");
run("Make Binary");
run("Analyze Particles...", "size=0.05-Infinity circularity=0.20-1.00 show=[Overlay Outlines] display include in_situ");
makeStatFromResults ();
//removed //if (i==1) TabWindow (0); else
TabWindow (1);
selectWindow("Results");
run("Close");
}
// --------------- tab functions ---------------//
//CustomTabStatFromResults
// Author : Gilles Carpentier
// Faculte des Sciences et Technologies,
// Universite Paris 12 Val de Marne, France.
// function making stats from ImageJ Results Table values
function makeStatFromResults () {
sumObject=0;sumPerim=0;TheTotalArea=0;meanObject=0;meanPerim=0;
// extraction from data from the Result Table:
if (nResults() > 0 && isOpen("Results")) {
if (columnLabelList ("Label") >=0) {label=getResultLabel (0);} else {label="unknown";}
if (columnLabelList ("Area") >= 0) {sumObject=sumColumnTab ("Area"); } else {exit ("No \"Area\" measurements in this Result Table");}
if (columnLabelList ("Perim.") >= 0) {sumPerim=sumColumnTab ("Perim."); } else {exit ("No \"Perim\.\" measurements in this Result Table");}
} else {exit ("No result table");}
// Stat calculations:
TheTotalArea = sumObject;
if (nResults() != 0) meanObject = TheTotalArea/nResults();
if (nResults() != 0) meanPerim=sumPerim/nResults();
}
// function getting the sum of the value from the column name contained in kind
function sumColumnTab (kind) {
sum=0;
if (columnLabelList (kind) >=0) {
for (a=0; a<nResults(); a++) {
sum=sum+getResult(kind,a);
}
return sum;
}
// function returning the number of the column which name is contained in kind. return -1 if doesn't exists
function columnLabelList (kind) {
columnNumber=-1;
if (nResults() > 0 && isOpen("Results")) {
selectWindow("Results");
results = getInfo();
lines = split(results, "\n");
headings = lines[0];
titlesofcolumns = split(headings, ",\t");
for (a=0; a<titlesofcolumns.length; a++) {if (titlesofcolumns[a] == kind) columnNumber=a;}
}
return columnNumber;
}
// function building/managing a table window
function TabWindow (addLine) {
undoErease = "";
if (! isOpen(windowTabName)) {
run("New... ", "name="+nameOfStatTab+" type=Table");
print(nameOfStatTab, "\\Headings:Slice Name\tCount Objects\tTotal Area\tAverage Size\tMean Perim.");
}
if (addLine == 0) {print(nameOfStatTab, "\\Clear");}
print(nameOfStatTab, label+ "\t" + nResults() + "\t" + TheTotalArea + "\t" + d2s(meanObject,2) + "\t" + d2s(meanPerim,2));
}
// function removing the last line of the tab
function rmLastLine () {
if ( isOpen (windowTabName)) {
selectWindow (windowTabName);
tabContent = getInfo();
linesInTab = split(tabContent, "\n");
if (linesInTab[linesInTab.length-1] > 0) {
print(nameOfStatTab, "\\Clear");
resteLines="";
for (i=1; i < (linesInTab.length -1); i++) {
resteLines=resteLines+linesInTab[i] +"\n";
}
if (linesInTab.length > 2) print (nameOfStatTab,resteLines);
if (linesInTab.length > 1) undoErease=linesInTab[linesInTab.length-1];
}
}
}
// function restoring the last ereased line in the table
function undormLastLine () {
if (undoErease != "") print(nameOfStatTab,undoErease);
undoErease="";
}
// saving a tab as excel type file
function saveTab (path) {
if (isOpen(windowTabName)) {
if (path == "") {
selectWindow (windowTabName);
run("Input/Output...", "jpeg=75 gif=-1 file=.xls");
saveAs("Text");
}
if (path != "") {
selectWindow(windowTabName);
saveAs("Text", path+windowTabName+".xls");
}
}
}
function openTab (path,name) {
undoErease="";windowTabName=name;
lines=split(File.openAsString(path), "\n");
if (lines.length < 2) { exit ("This file doesn't seam to contain data");}
headings = lines[0];
titlesOfColumns = split(headings, ",\t");
nameOfStatTab="["+windowTabName+"]";
if (isOpen(windowTabName)) {selectWindow(windowTabName) ;run("Close");}
firstLine="";
for (i=0; i < (titlesOfColumns.length ); i++) {
firstLine=firstLine+ titlesOfColumns [i];
if ( i < (titlesOfColumns.length )-1) {firstLine=firstLine+ "\t";}
}
toPrint="";
for (i=1; i < (lines.length ); i++) {
toPrint=toPrint+lines[i]+"\n";
}
run("New... ", "name="+nameOfStatTab+" type=Table");
print(nameOfStatTab, "\\Headings:"+firstLine+"");
print(nameOfStatTab,toPrint);
}
To unsubscribe from Modify (or create) results table,
click here.
NAML