Plaque Channel Extraction

This ImageJ script extracts the ABETA channel from multi-channel TIFF images and assigns each image a random alphanumeric code for blinded plaque annotation.

true

This script is written in the ImageJ Macro Language (IJM).

macro "ABETA Channel Extraction" {

    setBatchMode(true);

    input = getDirectory("Choose input data folder.");
    files = getFileList(input);
    // Array.show(files);

    dir = "<insert your directory here>";
    datadir = dir + "Data/2 - Channel Extraction/Plaque/";


    ////////////////////////////////////////////////////////////
    /////  FUNCTION FOR RANDOM ID
    ////////////////////////////////////////////////////////////
    
    function randomString(length, chars) {
        result = "";
        for (i = 0; i < length; i++) {
            maxlen = lengthOf(chars)-1;
            rand = round(random * maxlen);
            result +=  substring(chars, rand, rand+1);
        }
        return result;
    }
    

    ////////////////////////////////////////////////////////////
    /////  ITERATE OVER IMAGES
    ////////////////////////////////////////////////////////////
    
    for (f = 0; f < files.length; f++) {

        open(input + files[f]);
        Roi.remove; // remove active selection, if any
    
        ////////////////////////////////////////////////////////////
        /////  LOAD IMAGE + DEFINE MARKERS
        ////////////////////////////////////////////////////////////
        
        image = getTitle(); // get crop title
        selectImage(image); // shift focus to the selected crop
        filename = substring(image, 0, indexOf(image, "_Reordered.tif"));
        
        splitname = split(filename, "_");   
        sample = splitname[0];
        layer = splitname[1];
        crop = splitname[2];
        crop = substring(crop, 4);
        
        if (sample == "1190" || sample == "1301" || sample == "1619" || sample == "2169" || sample == "2191" || sample == "2250" || sample == "2274") {
            condition = "CTRL";
        } else {
            condition = "AD";
        }
        
        print(filename);

        ////////////////////////////////////////////////////////////
        /////  RANDOMIZE CROP
        ////////////////////////////////////////////////////////////

        id = randomString(6, "0123456789abcdefghijklmnopqrstuvwxyz");
        // print(id);

        Table.set("ID", f, id);
        Table.set("Sample", f, sample);
        Table.set("Layer", f, layer);
        Table.set("Crop", f, crop);
        Table.set("Condition", f, condition);
        Table.set("File", f, filename);
        Table.update();
        
        ////////////////////////////////////////////////////////////
        /////  SAVE ABETA CHANNEL
        ////////////////////////////////////////////////////////////
        
        // duplicate ABETA channel
        selectImage(image); // shift focus to original
        run("Duplicate...", "title=ABETA duplicate channels=16");
        
        selectWindow("ABETA"); // shift focus to original
        saveAs("Png", datadir + condition + "/" + id + ".png");
        close();

        selectImage(image);
        close();
    
    }

    // save table with mappings
    Table.save(datadir + "ID Mappings.csv")

}

Corrections

If you see mistakes or want to suggest changes, please create an issue on the source repository.