Created
October 3, 2024 13:02
-
-
Save lacan/7952c5b495328706b437a56c4402ba00 to your computer and use it in GitHub Desktop.
[Operetta Importer with Grid/Collection Stitching and Pyramid Export] Using the Operetta Importer with scripting and using the results on the fly to perform stitching #fiji #operetta #groovy #stitching
This file contains hidden or 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
#@ File idFile ( label="'Index.idx.xml' file" ) | |
#@ File saveFolder ( label="Save Folder", style="directory" ) | |
// Define stitching parameters. Nothing here is flexible but feel free to try | |
def params = new mpicbg.stitching.StitchingParameters() | |
params.channel1 = 0; | |
params.channel2 = 0; | |
params.timeSelect = 0; | |
params.checkPeaks = 5; | |
params.fusionMethod = 0 | |
params.regThreshold = 0.3 | |
params.relativeThreshold = 2.5 | |
params.absoluteThreshold = 3.5 | |
def opm = new OperettaManager.Builder() | |
.setId( idFile ) | |
.build() | |
def allWells = opm.getAvailableWells( ).take( 1 ) | |
allWells.each{ well -> | |
def fields = opm.getAvailableFields( well ) | |
// Not really used but important to initialise stitching properly | |
def positionsFile = new File( saveFolder, opm.getFinalWellImageName( well ) + "_bestZ.txt" ) | |
// Prepare the data for stitching | |
def elements = fields.withIndex().collect{ field, idx -> | |
// Load the field | |
def fieldImage = opm.getFieldImage( field ) | |
// Get the position of the field in pixels | |
def pos = opm.getUncalibratedCoordinates( field ) | |
// Build the ImageCollectionElement needed for stitching | |
def element = new mpicbg.stitching.ImageCollectionElement( positionsFile, idx ) | |
element.setImagePlus( fieldImage ) | |
if( fieldImage.getNSlices() > 1 ) { | |
element.setDimensionality( 3 ) | |
element.setModel( new mpicbg.models.TranslationModel3D() ) | |
element.setOffset( [ pos.getLongPosition( 0 ), pos.getLongPosition( 1 ), 0.0 ] as float[] ) | |
} else { | |
element.setDimensionality( 2 ) | |
element.setModel( new mpicbg.models.TranslationModel2D() ) | |
element.setOffset( [ pos.getLongPosition( 0 ), pos.getLongPosition( 1 ) ] as float[] ) | |
} | |
return element | |
} | |
params.dimensionality = elements[0].getDimensionality() | |
// Align tiles | |
def optimized = mpicbg.stitching.CollectionStitchingImgLib.stitchCollection( elements, params ) | |
//Prepare for fusion | |
def images = optimized.collect{ it.getImagePlus() } | |
def models = optimized.collect{ it.getModel() } | |
// Fuse tiles | |
def fused = mpicbg.stitching.fusion.Fusion.fuse( new net.imglib2.type.numeric.integer.UnsignedShortType(), images, models, params.dimensionality, false, 0, null, false, false, false ) | |
// Fused image loses the calibration, so re-add it here | |
fused.setCalibration( images[0].getCalibration() ) | |
fused.setTitle( opm.getFinalWellImageName( well )) | |
// Use KHEOPS to save a pyramid image | |
ch.epfl.biop.ImagePlusToOMETiff.writeToOMETiff( fused, positionsFile , "LZW", null ) | |
//ij.IJ.saveAs( fused, "tiff", new File( saveFolder, opm.getFinalWellImageName( well ) +"_bestZ" ).getAbsolutePath() ) | |
fused.close() | |
images.each{ it.close() } | |
} | |
import ch.epfl.biop.operetta.* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment