ij-macro-programming-workshop

Previous            Exercise            Next

Exercise 17.1 - Sort the rois and the result table by the values in a given column

Aim:

Open the image in images/17 with ImageJ! Manually use the Threshold-Adjuster and the Particle-Analyzer to add the rois of the nuclei to the roi-manager! Measure the rois in the roi-manager!

Complete the macro below, that will sort rois and results by the values in a given column.

FEATURE = "Mean";
REVERSE = true;

column = Table.getColumn(FEATURE);
positions = Array.rankPositions(column);
if (REVERSE) Array.reverse(positions);
ranks = Array.rankPositions(positions);

Your code starts after this line

for (i=0; i<roiManager("count"); i++) {
	roiManager("select", i);
	roiManager("Rename", IJ.pad(ranks[i], 4)); 
}
roiManager("Deselect");
roiManager("Sort");
close("Results");
roiManager("Show None");
roiManager("Show All");
roiManager("Measure");

Your code ends before this line

The code below is for automatically checking the result. Please ignore it!

ok = (nResults>1);
for(i=0; i<nResults-1; i++) {
	value = getResult(FEATURE,i);
	nextValue = getResult(FEATURE,i+1);
	ok = ok && (value>nextValue);
}
if (ok)
	showMessage("That's right. Great, you did it!");
else 
	showMessage("Your result is wrong! Please check your macro and try again!");

Previous            Exercise            Next