How to automatically analyze results obtained from a batch macro

I have a plugin which I want to run for several images at a time using batch macro codes and then want to take an average of total number of positive pixels of all the images. I dont know how to extract the result and add up after the plugin runs for each image. I want to write the codes in the same batch file to make the batch macro fully automated. Is it possible? If not please suggest some alternative.

The current code which runs plugin for each image looks like this. Please check if the codes are right:

dir1 = getDirectory("Choose Source Directory ");
format = getFormat();
dir2 = getDirectory("Choose Destination Directory ");
list = getFileList(dir1);
for (i=0; i<list.length; i++) {
 showProgress(i+1, list.length);

run("IHC Profiler", "mode=[Cytoplasmic Stained Image] vectors=[H DAB]");

 if (format=="8-bit TIFF" || format=="GIF")
 saveAs(format, dir2+list[i]);
function getFormat() {
 formats = newArray("TIFF", "8-bit TIFF", "JPEG", "GIF", "PNG",
 "PGM", "BMP", "FITS", "Text Image", "ZIP", "Raw");
 Dialog.create("Batch Convert");
 Dialog.addChoice("Convert to: ", formats, "TIFF");;
 return Dialog.getChoice();
function convertTo8Bit() {
 if (bitDepth==24)
 run("8-bit Color", "number=256");


Sorry - I don’t have time at the moment to go through your code… but I do have an example here that accumulates a single results table from measurements from multiple images (simply segmenting nuclei and doing measurements on those regions). Perhaps you can use that as a base for fixing your issue in your own code?