0

after hours of trying and searching related topics, I don't get further. I am trying to create a small ImageJ script that splits channels of a picture, saves on .tif version with enhanced contrast (this part works) AND creates a histogram and saves it values as .csv (this part does not work, it doesn't save anything). I have no idea why it doesn't work so here is my whole code.

input = getDirectory("Input directory");
output = getDirectory("Output directory");

Dialog.create("File type");
Dialog.addString("File suffix: ", ".tif", 5);
Dialog.show();
suffix = Dialog.getString();

processFolder(input);

function processFolder(input) {
    list = getFileList(input);
    for (i = 0; i < list.length; i++) {
        if(File.isDirectory(list[i]))
            processFolder("" + input + list[i]);
        if(endsWith(list[i], suffix))
            processFile(input, output, list[i]);
    }
}

function processFile(input, output, filename) {
    print("Processing: " + input + filename);
    open(input + filename);
    run("Split Channels");
    selectWindow(filename+" (blue)");
    close();
    selectWindow(filename+" (green)");
    close();
    selectWindow(filename+" (red)");
    run("Histogram");
    getHistogram(values, counts, 256);
    saveAs("Results", output + "Histogram of " + filename + ".csv");
    close();
    saveAs("TIFF", output+ "processed_" + filename);
    selectWindow("processed_" + filename);
    close();

}

I appreciate every input. Cheers!

1 Answers1

0

not sure you can save it as a csv file using the IJ macro language. However here is some code to do the same thing but save it as a txt file (this example only takes the value from 255)

getStatistics(mean, min, max, std, histogram); 
white=histogram[255];
// list2 is the list of images in a for loop - adds image name to results
print(white,",", list2[j]+" smi31");

selectWindow("Log");
saveAs("txt", file1+"Result");

Hope this is helpful :-)

mikew
  • 31
  • 7