diff --git a/README.md b/README.md index c9f6405d64905c1f66da01023413f3be15093593..a2b95c6e4e4d546ad0d2f7ef7943a10888e86d05 100644 --- a/README.md +++ b/README.md @@ -19,3 +19,5 @@ Grid/Collection Stiching version: 1.2 [issue](https://forum.image.sc/t/converting-16-bit-signed-tiffs-to-16-bit-unsigned/5847/3) signed vs unsigned 16 bit images +## Microscopy Image Stitching Tool (MIST) +[MIST](https://github.com/USNISTGOV/MIST/wiki/Install-Guide) \ No newline at end of file diff --git a/ScanImageStitching.ijm b/ScanImageStitching.ijm index a9936b2ede47a4108ee7bfb962c37a65bdccf45a..94e7db5a18b5b94c6bf96e8b373df86bc2fcd049 100644 --- a/ScanImageStitching.ijm +++ b/ScanImageStitching.ijm @@ -50,40 +50,63 @@ function checkPathSeparator(path) } +/* convert signed to unsigned 16bit + * scales between min and max value + * requires open stack + */ +function convertSignedToUnsigned16bit() +{ + run("32-bit"); + for (s = 1; s <= nSlices; s++) { + setSlice(s); + getStatistics(area, mean, pixelMin, pixelMax); + run("Subtract...", "value=" + pixelMin); + setMinAndMax(0, 65535); + } + + run("16-bit"); + for (s = 1; s <= nSlices; s++) { + setSlice(s); + getStatistics(area, mean, pixelMin, pixelMax); + setMinAndMax(pixelMin, pixelMax); + } +} + + +/* export each image from a stack + * prepends stack index to filename + * @param export path + */ +function exportStackToImages(path) +{ + path = checkPathSeparator(path); + run("Stack to Images"); + for (i = nImages; 0 < i; i--) { + fileName = getTitle(); + fileTag = substring(fileName, 0, lastIndexOf(fileName, "-")); + fileOut = path + "S" + i + "_" + fileTag + ".tif"; + saveAs("Tiff", fileOut); + close(); + } +} + /* get all files from direcotry * @param: output directory * @param: list of files */ - function preprocessStacks(path, files) +function preprocessStacks(path, files) { - path = checkPathSeparator(path); for(f = 0; f < files.length; f++) { showProgress(f, files.length); fileIn = files[f]; fileName = File.getName(fileIn); - fileTag = substring(fileName, 0, lastIndexOf(fileName, ".")); - fileOut = path + fileName; + run("Bio-Formats Windowless Importer", "open="+fileIn); - - getMinAndMax(min, max); - setMinAndMax(0, max - min); - print("min: " + min); - print("max: " + max); - - getMinAndMax(min, max); - print("new min: " + min); - print("new max: " + max); - - //run("Stack to Images"); - //selectWindow(fileTag + "-0002"); - //saveAs("Tiff", fileOut); - //close(); - //closeImageByTitle(fileTag + "-0001"); - break; + convertSignedToUnsigned16bit(); + exportStackToImages(path); + //break; } - - } macro "ScanImageStitching" @@ -99,7 +122,7 @@ macro "ScanImageStitching" filesList = getFileListWithExtension(pathInput, ".tif"); // pre-process - setBatchMode(false); + setBatchMode(true); preprocessStacks(pathTemp, filesList); setBatchMode(false);