// PurpSeg Macro // Histology GAG Analysis // Quantify the area of GAGs in Cervical Os epithelium (dark purple) from stromal tissue and returns Purple Area and total tissue area in square pixels for each image. // This runs on a single open image at a time. // Written be Wilson R Adams | Vanderbilt Biophotonics Center | 25 Jan 2021 start = getTitle(); PurpSeg(start); function PurpSeg(img) { roiManager("reset"); // Segment out purpple stuff in image. quantify area. selectWindow(img); run("Duplicate...", " "); wrkimg = getTitle(); // Split channels to RGB - Keep red channel run("Split Channels"); close(wrkimg+" (green)"); close(wrkimg+" (blue)"); red = wrkimg+" (red)"; selectWindow(red); // Threshold image with huang threshold method - no erosion/dilation //setAutoThreshold("Otsu"); setThreshold(0, 146); setOption("BlackBackground", false); run("Convert to Mask"); // Get ROI // 'Create Selection' doesnt have size exculsion // 'Analyze Particles' does. So i used that to get the main big ROI run("Analyze Particles...", "size=1000-Infinity add"); if (roiManager("count") > 1) { // Always condense to 1 ROI count = roiManager("count"); sel = newArray(count); for (i = 0; i < count; i++) { sel[i] = i; } roiManager("select", sel); roiManager("combine"); roiManager("add"); roiManager("select", sel); roiManager("delete"); } // Run 'Analyze Particles' against AND('Create Selection') output // to keep voids in mask run("Create Selection"); roiManager("add"); roiManager("select", newArray(0, 1)); roiManager("and"); roiManager("add"); roiManager("select", newArray(0, 1)); roiManager("delete"); TotalTissue(img); // Measure area of ROI in pixels on original image run("Set Measurements...", "area mean integrated redirect=None decimal=6"); selectWindow(img); roiManager("show all"); roiManager("Measure"); // Measured values are Area, Intensity Mean, and Integrated Density close("\\Others"); } function TotalTissue(img1) { // Segment whole tissue and return ROI selectWindow(img1); run("Duplicate...", " "); wrkimg = getTitle(); run("Split Channels"); close(wrkimg+" (blue)"); close(wrkimg+" (red)"); green = wrkimg+" (green)"; setThreshold(0, 210); setOption("BlackBackground", false); run("Convert to Mask"); run("Fill Holes"); run("Create Selection"); roiManager("Add"); close(green); selectWindow(img1); roiManager("show all"); }