Skip to content

Instantly share code, notes, and snippets.

@jandoG
Created January 24, 2023 12:19
Show Gist options
  • Save jandoG/5bb3ae682043877c313e100e1c042547 to your computer and use it in GitHub Desktop.
Save jandoG/5bb3ae682043877c313e100e1c042547 to your computer and use it in GitHub Desktop.
Open images using bio-formats API (run with FIJI)
from ij import IJ, ImagePlus
from loci.plugins import BF
from loci.formats import ImageReader, FilePattern
from loci.formats import MetadataTools
from loci.plugins.prefs import OptionsList
from loci.plugins.in import ImporterOptions
def openImageWithBF(path, virtual= True, groupfiles = False, seriesdata = False, openseries = 1):
"""
set options to open image using bio-formats- use virtual for quick loading
params:
path to file
virtual: bool set True to load image as virtual stack (for big data)
groupfiles: bool set True to load images from folder having similar name pattern (stored in the metadata of first image)
seriesdata: bool set True if image contains series
openseries: int series ID no to be opened
returns:
imp: ImagePlus
"""
options = ImporterOptions()
options.setColorMode(ImporterOptions.COLOR_MODE_DEFAULT)
options.setAutoscale(True)
options.setStackFormat("Hyperstack")
options.setVirtual(virtual)
options.setGroupFiles(groupfiles)
if seriesdata:
reader = ImageReader()
reader.setId(path)
seriesCount = reader.getSeriesCount()
reader.close()
print "Found series data. Image series count =", seriesCount
print "Reading series ID ", openseries, "\n"
options.setOpenAllSeries(True)
options.setId(path)
allimps = BF.openImagePlus(options)
if seriesdata:
imp = allimps[openseries - 1]
else:
imp = allimps[0]
return imp
imagepath = "C:\Users\Gaya\test.czi"
imp = openImageWithBF(imagepath, virtual= True)
imp.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment