Created
April 1, 2020 13:37
-
-
Save NicoKiaru/6c7a994b331af3163ae533b59faa3de3 to your computer and use it in GitHub Desktop.
Script which displays files in big dataviewer and then output a slice as an imageplus
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
import ch.epfl.biop.bdv.bioformats.command.OpenFilesWithBigdataviewerBioformatsBridgeCommand | |
import ch.epfl.biop.bdv.bioformats.command.BioformatsBigdataviewerBridgeDatasetCommand | |
import sc.fiji.bdvpg.services.SourceAndConverterServices | |
import bdv.viewer.SourceAndConverter | |
import ij.gui.WaitForUserDialog | |
import ch.epfl.biop.scijava.command.BdvViewToImagePlusExportCommand | |
import sc.fiji.bdvpg.scijava.command.bdv.BdvSourcesAdderCommand | |
/** | |
* author : Nicolas Chiaruttini | |
* EPFL 2020 | |
* Script which displays files in big dataviewer and then output a slice as an imageplus | |
* Needs the bdv playground update site to work : https://biop.epfl.ch/Fiji-Bdv-Playground/ | |
* | |
*/ | |
// bdvh = reference to an active bdv window | |
#@BdvHandle bdvh | |
#@CommandService cs | |
// To open one file : | |
#@File f | |
def openProperties = BioformatsBigdataviewerBridgeDatasetCommand.getDefaultParameters() | |
/*openProperties.put("switchZandC","FALSE"); // "TRUE" "FALSE" or "AUTO":depends on the file format | |
openProperties.put("unit", "MILLIMETER"); | |
openProperties.put("splitRGBChannels",false); | |
openProperties.put("positionIsCenter","AUTO"); | |
openProperties.put("switchZandC","AUTO"); | |
openProperties.put("flipPositionX","AUTO"); | |
openProperties.put("flipPositionY","AUTO"); | |
openProperties.put("flipPositionZ","AUTO"); | |
openProperties.put("useBioFormatsCacheBlockSize",true); | |
openProperties.put("cacheSizeX",512); | |
openProperties.put("cacheSizeY",512); | |
openProperties.put("cacheSizeZ",1); | |
openProperties.put("refFrameSizeInUnitLocation",1); | |
openProperties.put("refFrameSizeInUnitVoxSize",1);*/ | |
openProperties.put("files", [f] as File[]) | |
// To open several files : | |
//diese_arobase File[] f | |
//openProperties = BioformatsBigdataviewerBridgeDatasetCommand.getDefaultParameters() | |
//openProperties.put("files", f) | |
// Opens and put it in the service holding source -> not displayed yet | |
task = cs.run(OpenFilesWithBigdataviewerBioformatsBridgeCommand.class,true,openProperties) | |
dataset = task.get().getOutput("spimData") | |
// Holds the source | |
def sourceService = SourceAndConverterServices.getSourceAndConverterService() | |
// Holds the displays | |
def displayService = SourceAndConverterServices.getSourceAndConverterDisplayService() | |
datasetSourceList = sourceService.getSourceAndConverterFromSpimdata(dataset) as SourceAndConverter[] | |
// Display sources in the bdv window | |
cs.run(BdvSourcesAdderCommand.class, true, | |
"bdvh", bdvh, | |
"sacs", datasetSourceList, | |
"autoContrast", true, | |
"adjustViewOnSource", true).get() | |
//displayService.show(bdvh, datasetSourceList) : other option, but no autocontrast | |
(new WaitForUserDialog("Choose the right orientation")).show() | |
// Export ImagePlus | |
task = cs.run(BdvViewToImagePlusExportCommand.class, true, | |
"bdv_h", bdvh, | |
"sacs", datasetSourceList, | |
"allSources", false, | |
//"mipmapLevel", 0, | |
"matchWindowSize", false, | |
"xSize", 100, | |
"ySize", 100, | |
"zSize", 0, // = 1 slice | |
"timepoint", bdvh.getViewerPanel().state().getCurrentTimepoint(), // current active timepoint of the bdv | |
"samplingXYInPhysicalUnit", 0.2, | |
"samplingZInPhysicalUnit", 0.2, | |
"interpolate", false, | |
"wrapMultichannelParallel", true, | |
"ignoreSourceLut", false) | |
resultingImagePlus = task.get().getOutput("imp") | |
(new WaitForUserDialog("Click to remove current dataset")).show() | |
// Removes all sources at the end | |
for (source in datasetSourceList) | |
sourceService.remove(source) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment