/* Create a calibrated height map floating point image from a height map with know voxxel height PJL 1/26/2022 6:30 PM v220128 only "unclean" function updated Updated functions: 5/16/2022 1:42 PM. Updated stripKnownExtensionFromString function: f6-f7. F8: Removed unused functions. F10: updated function unCleanLabel. */ macroL = "Create_Image_with_Calibrated_Intensities_v220128-f10.ijm"; saveSettings; /* for restoreExit */ oTitle = stripKnownExtensionFromString(getTitle()); scaleFactors = newArray(1,1E-2,1E-3,1E-6,1E-9,1E-12); metricUnits = newArray("m","cm","mm",getInfo("micrometer.abbreviation"),"nm","pm"); Dialog.create("Intensity Calibration"); Dialog.addMessage("Macro: " + macroL); Dialog.addMessage("For DSX images use the ASC-set-scale macro to output the height for each level of intensity"); Dialog.addNumber("Calibrated value corresponding to each level of intensity",0,5,12,""); Dialog.addRadioButtonGroup("Calibrated height units:",metricUnits,3,2,"pm"); Dialog.addRadioButtonGroup("New height units:",metricUnits,3,2,"pm"); Dialog.show; hVal = Dialog.getNumber(); calUnit = Dialog.getRadioButton(); newUnit = Dialog.getRadioButton(); if (calUnit==newUnit) scaleFactor = 1; else { sFOi = indexOfArray(metricUnits, calUnit); sFNi = indexOfArray(metricUnits, newUnit); scaleFactor = scaleFactors[sFOi]/scaleFactors[sFNi]; } scaleFactor *= hVal; nTitle = "" + oTitle + "_HMCal_in_" + newUnit; nTitle = unCleanLabel(nTitle); run("Duplicate...", "title=" + nTitle); run("32-bit"); run("Multiply...", "value=" + scaleFactor); /* End of Calibrated Height Map creation macro */ /* ( 8(|)) ( 8(|)) ( 8(|)) ASC Functions @@@@@:-) @@@@@:-) @@@@@:-) */ function indexOfArray(array, value) { /* v181003 v190417 stops on first index discovery */ index = -1; for (i=0; i0){ 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