Last active
May 8, 2018 22:29
-
-
Save sbesson/42bcb21dc30f3644c17aabb6f5a1d917 to your computer and use it in GitHub Desktop.
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
#@UIService uiService | |
#@LogService log | |
# read in and display ImagePlus object(s) | |
from loci.plugins import BF | |
from loci.common import Region | |
from loci.plugins.in import ImporterOptions | |
from loci.plugins.util import LociPrefs | |
from ij import Prefs | |
from loci.formats import ImageReader | |
from loci.formats import MetadataTools | |
from ij import IJ | |
from ome.units import UNITS | |
# ZEISS STUFF | |
from loci.formats.in import ZeissCZIReader | |
from loci.formats.in import DynamicMetadataOptions | |
def getImageSeries(imps, series): | |
imp = imps[series] | |
# get the stack | |
imgstack = imp.getImageStack() | |
slices = imgstack.getSize() | |
width = imgstack.getWidth() | |
height = imgstack.getHeight() | |
log.info("Show Series # : " + str(series)) | |
log.info("ImgStack.getSize() : " + str(slices)) | |
log.info("ImgStack.getWidth() : " + str(width)) | |
log.info("ImgStack.getHeight() : " + str(height)) | |
return imp | |
def getCZIinfo(imagefile, | |
showimage=False, | |
setflatres=False, | |
setreslevel=0, | |
openallseries=True, | |
showomexml=False, | |
stitchtiles=False, | |
setconcat=False): | |
CZIinfo = {} | |
options = DynamicMetadataOptions() | |
options.setBoolean("zeissczi.autostitch", stitchtiles) | |
options.setBoolean("zeissczi.attachments", False) | |
czireader = ZeissCZIReader() | |
czireader.setFlattenedResolutions(setflatres) | |
czireader.setMetadataOptions(options) | |
czireader.setId(imagefile) | |
#czireader.setResolution(setreslevel) | |
CZIinfo['rescount'] = czireader.getResolutionCount() | |
CZIinfo['seriesCount'] = czireader.getSeriesCount() | |
CZIinfo['flatres'] = czireader.hasFlattenedResolutions() | |
CZIinfo['getreslevel'] = czireader.getResolution() | |
# Dimensions | |
CZIinfo['SizeT'] = czireader.getSizeT() | |
CZIinfo['SizeZ'] = czireader.getSizeZ() | |
CZIinfo['SizeC'] = czireader.getSizeC() | |
CZIinfo['SizeX'] = czireader.getSizeX() | |
CZIinfo['SizeY'] = czireader.getSizeX() | |
# check for autostitching and possibility to read attchmenst | |
CZIinfo['AllowAutoStitching'] = czireader.allowAutostitching() | |
CZIinfo['CanReadAttachments'] = czireader.canReadAttachments() | |
# get OME data | |
omeMeta = MetadataTools.createOMEXMLMetadata() | |
CZIinfo['imageCount_OME'] = omeMeta.getImageCount() | |
log.info("Current Image File : " + imagefile) | |
log.info("Get Resolution Count : " + str(CZIinfo['rescount'])) | |
log.info("Get Resolution Level : " + str(CZIinfo['getreslevel'])) | |
log.info("hasFlattenedResolution : " + str(CZIinfo['flatres'])) | |
log.info("# of Series (CZIReader) : " + str(CZIinfo['seriesCount'])) | |
log.info("# of Images (OMEMeta) : " + str(CZIinfo['imageCount_OME'])) | |
log.info("SizeT : " + str(CZIinfo['SizeT'])) | |
log.info("SizeZ : " + str(CZIinfo['SizeZ'])) | |
log.info("SizeC : " + str(CZIinfo['SizeC'])) | |
log.info("SizeX : " + str(CZIinfo['SizeX'])) | |
log.info("SizeY : " + str(CZIinfo['SizeY'])) | |
log.info("AllowAutoStitching : " + str(CZIinfo['AllowAutoStitching'])) | |
log.info("CanReadAttachments : " + str(CZIinfo['CanReadAttachments'])) | |
# Set the preferences in the ImageJ plugin | |
Prefs.set("bioformats.zeissczi.allow.autostitch", str(stitchtiles).lower()) | |
Prefs.set("bioformats.zeissczi.include.attachments", str(True).lower()) | |
if showimage: | |
# read in and display ImagePlus(es) with arguments | |
options = ImporterOptions() | |
options.setOpenAllSeries(openallseries) | |
options.setShowOMEXML(showomexml) | |
options.setConcatenate(setconcat) | |
options.setId(imagefile) | |
log.info("setOpenAllSeries : " + str(openallseries)) | |
log.info("setShowOMEXML : " + str(showomexml)) | |
log.info("setConcatenate : " + str(setconcat)) | |
# open the ImgPlus | |
imps = BF.openImagePlus(options) | |
for series in range(0, CZIinfo['seriesCount']): | |
imp = getImageSeries(imps, series) | |
imp.show() | |
czireader.close() | |
return CZIinfo | |
# clear the console automatically when not in headless mode | |
uiService.getDefaultUI().getConsolePane().clear() | |
# define testfile | |
imagefile = r'/tmp/OverViewScan.czi' | |
#imagefile = r'c:\Users\m1srh\Documents\Testdata_Zeiss\Castor\EMBL\96well\testwell96_woatt.czi' | |
info = getCZIinfo(imagefile, | |
showimage=True, | |
setflatres=False, | |
setreslevel=0, | |
openallseries=True, | |
showomexml=False, | |
stitchtiles=False, | |
setconcat=False) | |
#for x in info.keys(): | |
# print str(x) +" => " + str(info[x]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I have tried to use your code with my own axioscan data, but I still end up not getting the files I need. As you mentioned : "Bio-Formats ImageJ API (BF.openImagePlus) only supports flattened resolutions", which means that even if I can get the series count with the setFlattenedResolutions=False it will simply open the files that correspond to the 0-series count limit of the flattened list not the actual unflattened one.
I was using a macro in imagej that was skipping the in between lower levels of the pyramid, but that only works if the number of levels is consistent between each series and between slides. Do you by chance have any input on how I could solve this problem? If I could find a way to get the number of levels for each series I could use that to loop through and grab only the ones I need, but I could not find a function that would report that.
Thanks, Brigida