macro "Analyze Particles [F2]" { /* v220921: Replaced unnecessary restoreExit with exit v231018-9: Added ROI-by-ROI option v240104: Exit if border issue is now optional. */ macroL = "Analyze_objects_v240104.ijm"; orID = getImageID(); /* get id of image and title */ t = getTitle(); tPath = getDirectory("image"); if (tPath=="") tPath = File.directory; if (indexOf(tPath, "AutoRun")>=0) tPath = ""; getPixelSize(unit, pixelWidth, pixelHeight); /* Check to see if there is a location already set for analysis */ selType = selectionType; if ((selType>=0 && selType<4) || selType==9) { getSelectionBounds(selPosStartX, selPosStartY, originalSelEWidth, originalSelEHeight); /* smallest rectangle that can completely contain the current selection */ areaSelectionExists = true; } else areaSelectionExists = false; run("Select None"); if (!is("binary")) { binaryChoice = getBoolean("Binary image required for F2 shortcut analysis; apply default auto-threshold and continue?"); if(binaryChoice) { /* Quick-n-dirty threshold if not previously thresholded */ getThreshold(t1,t2); if (t1==-1){ run("Auto Threshold", "method=Default"); setOption("BlackBackground", false); run("Make Binary"); } } else exit("Goodbye"); } if (is("Inverting LUT")) run("Invert LUT"); setThreshold(0, 127); setOption("BlackBackground", false); /* Make sure black objects on white background for consistency */ yMax = Image.height-1; xMax = Image.width-1; cornerPixels = newArray(getPixel(0,0),getPixel(1,1),getPixel(0,yMax),getPixel(xMax,0),getPixel(xMax,yMax),getPixel(xMax-1,yMax-1)); Array.getStatistics(cornerPixels, cornerMin, cornerMax, cornerMean, cornerStdDev); if (cornerMax!=cornerMin){ exitNow = getBoolean("There are different pixel intensities at the corners; do you want to exit now?"); /* Sometimes the outline procedure will leave a pixel border around the outside - this next step checks for this. i.e. the corner 4 pixels should now be all black, if not, we have a "border issue". */ if (exitNow) exit("Goodbye " + macroL); invertNow = getBoolean("Invert current image contrast?"); if (invertNow) run("Invert"); } else if (cornerMean<1) run("Invert"); nROIs = roiManager("count"); analyzeByROI = false; analyzeBySelection = false; replaceROIs = false; restrictHow = "Analyze entire image"; if (nROIs>0 || areaSelectionExists){ Dialog.create("Restrict analysis area \(" + macroL + "\)"); restrictionOptions = newArray(restrictHow); if (areaSelectionExists) restrictionOptions = Array.concat(restrictionOptions, "Restrict analysis to current selection"); if (nROIs>0){ if (nROIs==1) restrictionOptions = Array.concat(restrictionOptions, "Restrict analysis to ROI"); else { restrictionOptions = Array.concat(restrictionOptions, "Restrict analysis to combined ROIs"); restrictionOptions = Array.concat(restrictionOptions, "Analyze each ROI one by one"); } } Dialog.addRadioButtonGroup("Analysis region:", restrictionOptions, restrictionOptions.length, 1, restrictionOptions[0]); Dialog.show; restrictHow = Dialog.getRadioButton(); roiManager("deselect"); } if (nROIs>0){ orROINames = newArray(""); for (i=0; i0) Dialog.addCheckbox("If adding ROIs delete original ROIs at end", true); Dialog.addCheckbox("Batchmode off", false); Dialog.show; analyzeString = "size=" + Dialog.getString; if (!startsWith(toLowerCase(unit), "pix")){ if (Dialog.getCheckbox) analyzeString += " pixel "; } analyzeString += " circularity=" + Dialog.getString(); if (Dialog.getCheckbox()) analyzeString += " show=Overlay"; createMask = Dialog.getCheckbox(); if (Dialog.getCheckbox()) analyzeString += " display"; if (Dialog.getCheckbox()) analyzeString += " exclude"; clearResults = Dialog.getCheckbox(); addROI = Dialog.getCheckbox(); if (addROI) analyzeString += " add"; holeOption = Dialog.getRadioButton(); if (holeOption=="Fill holes") analyzeString += " include"; else if (startsWith(holeOption, "Create composite")) analyzeString += " composite"; replaceROIs = Dialog.getCheckbox(); batchmodeOff = Dialog.getCheckbox(); if (!batchmodeOff) setBatchMode(true); if (clearResults) run("Clear Results"); if (restrictHow=="Restrict analysis to current selection"){ if (addROI && replaceROIs) roiManager("reset"); run("Restore Selection"); run("Analyze Particles...", analyzeString); } else { for (i=0; i