// ImageJ script used for PSAT1 phenotyping. Calculates the area of growth of pinned spots on SD omniplates. // Pinned spots from a 96-well format solid media plate. // Date: 2019-09-16 // Points to where image analysis result file will be created topdir = "/Users/russelllo/Desktop/ImageJ_Pinning_Quantification/Condition_Name_Replicate/"; outfile = topdir + "Results.csv" // Patch region set up np_w = 12; //number of patches across the width np_h = 8; //number of patches by height np = np_w * np_h; //total number of patches // This will make sure ImageJ will make the measurements we want run("Set Measurements...", "area mean centroid integrated display redirect=None decimal=3"); // List of row and column labels and what order they'll be used in. row_labels = newArray("A", "B", "C", "D", "E", "F", "G", "H"); col_labels = newArray("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"); files = getFileList(topdir); x=newArray(1); y=newArray(1); for (f_i=0;f_i < files.length; f_i++) { if (endsWith(files[f_i], ".jpg") || endsWith(files[f_i], ".JPG")) { open(topdir+files[f_i]); // Locating the region of the omniplate image, encompassing all 96 pinned spots. Change coordinates as needed. makeRectangle(849, 457, 2571, 1697); run("Crop"); image_name = getTitle(); run("8-bit"); run("Duplicate...", "title=mask"); setAutoThreshold("Moments dark"); setOption("BlackBackground", false); run("Make Binary"); run("Erode"); run("Dilate"); //run("Fill Holes"); run("32-bit"); run("Invert LUT"); setAutoThreshold("Moments dark"); run("NaN Background"); imageCalculator("Multiply create 32-bit", image_name, "mask"); selectWindow("mask"); close(); selectWindow(image_name); close(); selectWindow("Result of "+image_name); if (x.length == 4) { makeSelection('polygon', x, y); } else { setTool("rectangle"); title = "Set bounds"; msg = "Create polyline selection of \nA01, A12, H12, H01, then click \"OK\"."; waitForUser(title, msg); } getSelectionCoordinates(x, y); if (x.length == 4) { //setBatchMode("hide"); for (i=0; i < 4; i++) { c_dx = ( ( (x[1]-x[0]) + (x[2]-x[3]) )/2) / (np_w-1); c_dy = ( ( (y[1]-y[0]) + (y[2]-y[3]) )/2) / (np_w-1); r_dx = ( ( (x[3]-x[0]) + (x[2]-x[1]) )/2) / (np_h-1); r_dy = ( ( (y[3]-y[0]) + (y[2]-y[1]) )/2) / (np_h-1); } hw = ( r_dx + c_dx) /2.5; //half-width hh = ( r_dy + c_dy) /2.5; //half-height getSelectionCoordinates(x, y); for (col = 0; col < np_w; col++) { for (row = 0; row < np_h; row++) { n = nResults; ul_x = x[0] + c_dx*col + r_dx*row - hw;//upper left X ul_y = y[0] + c_dy*col + r_dy*row - hh;//upper left Y makeOval(ul_x, ul_y, 2*hw, 2*hh); //wait(250); run("Measure"); run("Select None"); if (nResults - n == 1) { name=substring(files[f_i],0,lengthOf(files[f_i])-4); identifiers = split(name, "_"); condition = identifiers[2]; setResult("Label", nResults-1, row_labels[row]+col_labels[col]); setResult("Condition", nResults-1, condition); setResult("Plate", nResults-1, identifiers[1]); setResult("Replicate", nResults-1, identifiers[2]); l_t = lengthOf(topdir); setResult("Time", nResults-1, "Day3"); setResult("Image", nResults-1, files[f_i]); } n = nResults; } } updateResults(); //waitForUser("Blah", "Press OK to proceed"); saveAs("Tiff", topdir+"segmented/" + substring(files[f_i],0,lengthOf(files[f_i])-4) + ".tif"); close(); //setBatchMode(false); } else { Dialog.create("Wrong!"); Dialog.addChoice("Try again?", newArray("Yes", "No")); Dialog.show(); retry = Dialog.getChoice(); close(); if (retry == "Yes") { f_i--; } } } } //saveAs("Results", topdir+"IntegratedDensity.csv"); saveAs("Results", outfile);