0

After some image processing using ImgaeJ macro, I have a ‘Results’ tab which contains 2 columns A and B. Lets’s say I have 50 rows of data.

Now I want to subtract the value of last row from all other 49 rows above in column B.

After this, I want to write all the values in “.csv” file (column A, B and C with 49 values each).

Below is the part of the code. I think the only problem is fetching the values from arrays that the script can write to the csv file.

Array.getStatistics command only exports the mean, std values for a given column. I'm interested in fetching all 49 values.

directory = getDirectory("Choose a Directory");
resultFilename = directory + Dialog.getString() + ".csv";

A = newArray(nResults() - 1);
B = newArray(nResults() - 1);

D = getResult("B", nResults() - 1);
    
for (i = 0; i < nResults() - 2; i++) {
    A[i] = getResult("A", i);
    B[i] = getResult("B", i);
    C[i] = A[i] - D;
}

Any idea about what is the command to get the values of A[i], B[i] and C[i]?

Looking forward for some help here.

Thank you.

1 Answers1

0

One solution is to write to the file as you do the calculations. I have modified your example (untested) to show how this works.

directory = getDirectory("Choose a Directory");
resultFilename = directory + Dialog.getString() + ".csv";
f = File.open(resultFilename);

A = newArray(nResults() - 1);
B = newArray(nResults() - 1);
// no C array is made so:
C = newArray(nResults() - 1);
D = getResult("B", nResults() - 1);
    
for (i = 0; i < nResults() - 2; i++) {
    A[i] = getResult("A", i);
    B[i] = getResult("B", i);
    C[i] = A[i] - D;
    // should the line above should be C[i] = B[i] - D;
    print(f, d2s(A[i],6) + "  \t" + d2s(B[i],6) + " \t" + d2s(C[i],6));
}
File.close(f);

Note that you don't need to make the arrays at all and can just write to the file (again this is untested):

directory = getDirectory("Choose a Directory");
resultFilename = directory + Dialog.getString() + ".csv";
f = File.open(resultFilename);

D = getResult("B", nResults() - 1);
    
for (i = 0; i < nResults() - 2; i++) {
    ai = getResult("A", i);
    bi = getResult("B", i);
    ci = ai - D;
    // should the line above should be ci = bi - D;
    print(f, d2s(ai,6) + "  \t" + d2s(bi,6) + " \t" + d2s(ci,6));
}
File.close(f);

I have used " \t" (tab character) as a separator not comma.

quantixed
  • 287
  • 3
  • 12
  • Hey @quantixed, thank you for helping out. I tried both the solutions suggested by you but now the script doesn't open the images to be analyzed and just creates an empty result file. – Novice_123 Mar 09 '21 at 19:34
  • @Novice_123 the code you posted doesn't give any clues as to why that might be the case. Your question is better suited to https://forum.image.sc rather than SO – quantixed Mar 10 '21 at 15:52
  • thank you for the other link. I have asked the question there and hope to get some feedback soon. Thank you again for your help. – Novice_123 Mar 11 '21 at 07:39