Snippets

Dave Mason Count thresholded pixels (https://forum.image.sc/t/macro-for-batch-saving-of-histogram-results/20153)

Created by Dave Mason

File pixelCounts.ijm Added

  • Ignore whitespace
  • Hide word diff
+dir1 = getDirectory("Choose Source Directory ");
+dir2 = getDirectory("Choose Destination Directory ");
+list = getFileList(dir1);
+setBatchMode(true);
+//nBins = 256;
+
+//-- open a file for output and write a header
+f = File.open(dir2+File.separator+"output.txt");
+print(f, "Filename\tPixels");
+
+//-- make sure this is correct otherwise you'll be measuring the wrong thing!
+setOption("BlackBackground", false);
+
+//-- Loop the file list
+for (i=0; i<list.length; i++) {
+showProgress(i+1, list.length);
+open(dir1+list[i]);
+title=getTitle();
+List.setMeasurements;
+print(f, title+"\t"+d2s(List.getValue("RawIntDen")/255,0));
+//-- close the current file
+close(title);
+}
+//-- Close the output
+File.close(f);
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.