// This macro calculates the average mean intensity of all ROIs from each category, image by image from a txt/xls/csv file obtained using the "Measure Intensities" macro. // Overall MI (Mean Intensity) is the Summed ID divided by the Summed Area (or Lenght for line ROIs) - treating ROIs of one category like part of one big object. // Average MI (Mean Intensity) is the average of the mean intensities for each ROI - treating each ROI as a separate object. // If background-corrected MIs have been output by the "Measure Intensities" macro, they will be used rather than raw MIs. macro "Calculate by Image" { SplitCond = true; // DefCats = newArray("Default", "Axon", "AIS", "Distal Axon", "Dendrite", "Synapse1", "Synapse2", "Axon (NT)", "AIS (NT)", "Distal Axon (NT)", "Dendrite (NT)", "Synapse 1 (NT)", "Synapse 2 (NT)", "Primary", "Secondary", "Tertiary", "Cat0", "Cat1", "Cat2", "Cat3", "Cat4", "Cat5", "Cat6", "Cat7"); // not useful anymore as we can process any category name Path = File.openDialog("Choose Results table"); // Define separator depending on format if (endsWith(Path, ".csv")) sep = ","; else sep = "\t"; Results = File.openAsString(Path); RName = File.getNameWithoutExtension(Path); // Retrieve the Labels column, the mean intenisty column and the area column IMAGENAMES = getColumn(Results,"Slice", sep); TYPES = getColumn(Results,"ROI type#", sep); CATS = getColumn(Results,"ROI type", sep); if (IMAGENAMES[0] == -1 || TYPES[0] == -1 || CATS[0] == -1) exit("One of the required column doesn't exist!"); // Mean intensity used is the background-corrected mean (output by the "Measure Intensities" macro) or if no corrected mean column is found, the raw mean intensity. CORRMEAN = getColumn(Results,"Corr Mean", sep); if (CORRMEAN[0] == -1) CORRMEAN = getColumn(Results,"Raw Mean", sep); if (CORRMEAN[0] == -1) exit ("Mean intensity column doesn't exist!"); AREA = getColumn(Results, "Area/Length", sep); if (AREA[0] == -1) exit ("Area/Length column doesn't exist!"); // Get an array with each image name and the number of images (defines the per-image arrays length) UIM = getUniqueA(IMAGENAMES); U = UIM.length; // Get an array with each categories and categories numbers UCATS = getUniqueA(CATS); UTYPES = getUniqueA(TYPES); // Array.print(UCATS); // Array.print(UTYPES); // Generate the Results table title1 = RName + " by Image"; title2 = "[" + title1 + "]"; f = title2; if (isOpen(title1)) print(f, "\\Clear"); else run("New... ", "name="+title2+" type=Table"); Headings = "\\Headings:n\tImage\tROI Type #\tRoi Type\tSummed ID\tSummed Area/Length\tOverall MI\tSummed MI\tNumber\tAverage MI"; print(f, Headings); t = 0; // loop on all unique categories for (c= 0; c < UCATS.length; c++ ) { CatNum = UCATS[c]; INum = getIndex(UCATS, CatNum); TypeNum = UTYPES[INum]; Names = newArray(U); SumTypeA = newArray(U); LenTypeA = newArray(U); MoyA = newArray(U); TypeA = newArray(U); NTypeA = newArray(U); NMoyA = newArray(U); // Initialization for i = 0 (first Results Table line) Names[0] = IMAGENAMES[0]; // Stores values in the first per-image slot if the ROI in the current line is #A if (TYPES[0] == TypeNum){ LenTypeA[0] = 0 + AREA[0]; SumTypeA[0] = 0 + CORRMEAN[0] * AREA[0]; TypeA[0] = 0 + CORRMEAN[0]; NTypeA[0] = 1; typeflag = 1; } // Loop on all following Results Table lines UIndex = 0; for (j = 1; j < IMAGENAMES.length; j++) { // This detects if it's a new image (new averages) and iterates UIndex to store in the next slot in the per-images array if (IMAGENAMES[j] != IMAGENAMES[j - 1]) { UIndex = UIndex+1; Names[UIndex] = IMAGENAMES[j]; } // Stores values in the current per-image slot if the ROI in the current line is #A if (TYPES[j] == TypeNum) { LenTypeA[UIndex] = LenTypeA[UIndex] + AREA[j]; SumTypeA[UIndex] = SumTypeA[UIndex] + CORRMEAN[j] * AREA[j]; TypeA[UIndex] = TypeA[UIndex] + CORRMEAN[j]; NTypeA[UIndex] = NTypeA[UIndex] + 1; } } // Loops on all per-image slots for (j=0; j