Created
September 11, 2019 16:33
-
-
Save ctrueden/5318fe5239d2b6457e8b628aa7d1765a to your computer and use it in GitHub Desktop.
Create a vertical stack of images, each horizontally centered
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#@ ImageJ ij | |
#@ File[] imageFiles | |
#@ File(style = "save") outFile | |
#@ boolean showStack | |
import java.util.Arrays | |
import net.imglib2.FinalInterval | |
import net.imglib2.type.numeric.integer.UnsignedByteType | |
import net.imglib2.util.Intervals | |
whiteValue = new UnsignedByteType(255) | |
centerHorizontal = { image, newWidth -> | |
dims = Intervals.dimensionsAsLongArray(image) | |
dims[0] = newWidth | |
extended = ij.op().transform().extendValueView(image, whiteValue) | |
return ij.op().transform().intervalView(extended, new FinalInterval(dims)) | |
} | |
images = Arrays.stream(imageFiles).map{file -> ij.io().open(file.getAbsolutePath())}.collect() | |
maxWidth = images.stream().map{image -> image.dimension(0)}.collect().max() | |
centeredImages = images.stream().map{image -> centerHorizontal(image, maxWidth)}.collect() | |
stacked = ij.op().transform().concatenateView(centeredImages, 1) | |
if (showStack) ij.ui().show(stacked) | |
ij.io().save(stacked, outFile.getAbsolutePath()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment