/* # Overlay_Manager Very simple overlay selection manager: PJL NHMFL v180828: 1st version. v180829: Added move. v190222: Now shows slice number and does not restore old selections unless unless shown in original. v190222b: Added wildcard delete string. v200130: Shows only ranges of overlays to better handle long lists. v230221: Added more information and corrected number of overlays. v230713: Added crop-n-save option. v230718: Deactivated non-working 'rename' operation. v230803: Replaced getDir for 1.54g10. F4: updated function unCleanLabel. v240817: Fixes mislabelling of height at width in dialog. Added bounding coordinates. */ macroL = "Overlay_manager_v240817b.ijm"; requires("1.53d"); sliceNumber = getSliceNumber(); slices = nSlices; selEType = selectionType; overlayCount = Overlay.size; maxLines = round(screenHeight/40); if (Overlay.size<1) exit("Sorry, no overlays available"); sWidth = screenWidth(); fS = File.separator; /* The following list adapted from https://imagej.net//macros/Sort-Selections-in-Overlays.txt */ overlayColors = newArray(overlayCount); overlayGroups = newArray(overlayCount); overlayHeights = newArray(overlayCount); overlayInfo = newArray(overlayCount); overlayNames = newArray(overlayCount); overlayPoints = newArray(overlayCount); overlaySlices = newArray(overlayCount); overlayStrokeWidths = newArray(overlayCount); overlayTypes = newArray(overlayCount); overlayWidths = newArray(overlayCount); overlayXs = newArray(overlayCount); overlayYs = newArray(overlayCount); for (i=0; i1){ for (i=0; i1) sliceNumber = Dialog.getNumber; oRStart = Dialog.getNumber-1; oREnd = Dialog.getNumber-1; } else { oRStart = 0; oREnd = overlayCount; } setSlice(sliceNumber); /* Returns to first slice but list of overlays is for all slices */ Dialog.create("Manage Current Overlay Selections \(" + macroL + "\)"); Dialog.addMessage("Current slice: " + sliceNumber + " out of " + slices + " slices.\nBut overlays for ALL slices are listed."); Dialog.addMessage("Select overlay selections and operation"); Dialog.addRadioButtonGroup("Choose operation", newArray("Delete", "Add to ROI Manager", "Move", "Crop-n-save All"), 1, 4, "Delete"); /* Operations: 'Rename' not currently working */ Dialog.addCheckbox("Select all?",false); for (i=oRStart; i=0) Overlay.removeSelection(i); } } run("Select None"); if (selEType>=0) run("Restore Selection"); if (listElements) run("List Elements"); /* ( 8(|) ( 8(|) ASC Function @@@@@:-) @@@@@:-) */ function convertTypeToString(type, lowercase) { /* v230221 uses array v231013 added "lowercase" boolean flag and added point type to expand use to selections, and expanded some strings to reflect selection descriptions */ if(type>10 || type<0) exit("Sorry, " + type + " must be from 0 to 10"); shapeTypes = newArray("Rectangle", "Oval", "Polygon", "Freehand", "Traced", "Straight Line", "Segmented PolyLine", "Freehand Line", "Angle", "Composite", "Point"); if (lowercase) return toLowerCase(shapeTypes[parseInt(type)]); else return shapeTypes[parseInt(type)]; } function stripKnownExtensionFromString(string) { /* Note: Do not use on path as it may change the directory names v210924: Tries to make sure string stays as string. v211014: Adds some additional cleanup. v211025: fixes multiple 'known's issue. v211101: Added ".Ext_" removal. v211104: Restricts cleanup to end of string to reduce risk of corrupting path. v211112: Tries to fix trapped extension before channel listing. Adds xlsx extension. v220615: Tries to fix the fix for the trapped extensions ... v230504: Protects directory path if included in string. Only removes doubled spaces and lines. v230505: Unwanted dupes replaced by unusefulCombos. v230607: Quick fix for infinite loop on one of while statements. v230614: Added AVI. v230905: Better fix for infinite loop. v230914: Added BMP and "_transp" and rearranged */ fS = File.separator; string = "" + string; protectedPathEnd = lastIndexOf(string,fS)+1; if (protectedPathEnd>0){ protectedPath = substring(string,0,protectedPathEnd); string = substring(string,protectedPathEnd); } unusefulCombos = newArray("-", "_"," "); for (i=0; i=0) string = replace(string,combo,unusefulCombos[i]); } } if (lastIndexOf(string, ".")>0 || lastIndexOf(string, "_lzw")>0) { knownExts = newArray(".avi", ".csv", ".bmp", ".dsx", ".gif", ".jpg", ".jpeg", ".jp2", ".png", ".tif", ".txt", ".xlsx"); knownExts = Array.concat(knownExts,knownExts,"_transp","_lzw"); kEL = knownExts.length; for (i=0; i0){ preChan = substring(string,0,iChanLabels); postChan = substring(string,iChanLabels); while (indexOf(preChan,knownExts[i])>0){ preChan = replace(preChan,knownExts[i],""); string = preChan + postChan; } } } while (endsWith(string,knownExts[i])) string = "" + substring(string, 0, lastIndexOf(string, knownExts[i])); } } unwantedSuffixes = newArray(" ", "_","-"); for (i=0; i0){ if(!endsWith(protectedPath,fS)) protectedPath += fS; string = protectedPath + string; } return string; } function unCleanLabel(string) { /* v161104 This function replaces special characters with standard characters for file system compatible filenames. + 041117b to remove spaces as well. + v220126 added getInfo("micrometer.abbreviation"). + v220128 add loops that allow removal of multiple duplication. + v220131 fixed so that suffix cleanup works even if extensions are included. + v220616 Minor index range fix that does not seem to have an impact if macro is working as planned. v220715 added 8-bit to unwanted dupes. v220812 minor changes to micron and Ångström handling + v231005 Replaced superscript abbreviations that did not work. + v240124 Replace _+_ with +. */ /* Remove bad characters */ string = string.replace(fromCharCode(178), "sup2"); /* superscript 2 */ string = string.replace(fromCharCode(179), "sup3"); /* superscript 3 UTF-16 (decimal) */ string = string.replace(fromCharCode(0xFE63) + fromCharCode(185), "sup-1"); /* Small hyphen substituted for superscript minus as 0x207B does not display in table */ string = string.replace(fromCharCode(0xFE63) + fromCharCode(178), "sup-2"); /* Small hyphen substituted for superscript minus as 0x207B does not display in table */ string = string.replace(fromCharCode(181) + "m", "um"); /* micron units */ string = string.replace(getInfo("micrometer.abbreviation"), "um"); /* micron units */ string = string.replace(fromCharCode(197), "Angstrom"); /* Ångström unit symbol */ string = string.replace(fromCharCode(0x212B), "Angstrom"); /* the other Ångström unit symbol */ string = string.replace(fromCharCode(0x2009) + fromCharCode(0x00B0), "deg"); /* replace thin spaces degrees combination */ string = string.replace(fromCharCode(0x2009), "_"); /* Replace thin spaces */ string = string.replace("%", "pc"); /* % causes issues with html listing */ string = string.replace(" ", "_"); /* Replace spaces - these can be a problem with image combination */ /* Remove duplicate strings */ unwantedDupes = newArray("8bit", "8-bit", "lzw"); for (i=0; i=0) { string = string.substring(0, iFirst) + string.substring(string, iFirst + lengthOf(unwantedDbls[i]) / 2); i = -1; /* check again */ } } string = string.replace("_\\+", "\\+"); /* Clean up autofilenames */ string = string.replace("\\+_", "\\+"); /* Clean up autofilenames */ /* cleanup suffixes */ unwantedSuffixes = newArray(" ", "_", "-", "\\+"); /* things you don't wasn't to end a filename with */ extStart = lastIndexOf(string, "."); sL = lengthOf(string); if (sL-extStart<=4 && extStart>0) extIncl = true; else extIncl = false; if (extIncl){ preString = substring(string, 0, extStart); extString = substring(string, extStart); } else { preString = string; extString = ""; } for (i=0; i