Export TIF images from multiwell Tile with dedicated names

Your place to discuss general handling of images and the CZI file format
Post Reply
user-3571
Posts: 2
Joined: Thu Jan 01, 1970 1:00 am

Export TIF images from multiwell Tile with dedicated names

Post by user-3571 »

Hi,

I am doing 96 well plate imaging. I set up the experiment in the way that in each well 5 images will be acquired randomly. After acquisition, ZEN generate 1 czi file. However, I need to export individual TIF images for downstream analysis, and I need each TIF image with its dedicated name so I would know its whereabout, e.g. A5 well position 2. The default TIF export names the file ExperimentXX-XX. Is there any method that I can give the dedicated name automatically? Many thanks.

Xianke
user-8
Posts: 63
Joined: Thu Jan 01, 1970 1:00 am

Post by user-8 »

Hi Xianke,

I am not quite sure, what your desired output should be, but I think you need something like this:

  • Download the appropriate version of normal IronPython (http://ironpython.net/) and install it on your machine
  • place all your CZI (it also works, if there is only one ...) from your wellplate experiments in one folder
  • rename the attached TXT Export Settings file to *.xml instead of *.txt (I could not attach the XML directly ...)
  • place the OME-TIFF export settings template file somewhere and keep the location in mind
  • adapt the OAD macro to your needs - change the file location of the settingsfile
  • run the macro and specify the source and destination folder (the macro can also work without the little dialog, if you do not like it ...)
The macro will export all CZI files inside the source folder as OME-TIFF while splitting it into single scenes ( = wells). Finally the resulting OME-TIFF files will be renamed using the extracted well identifiers.

Good luck, Sebi

Here is the OAD macro:

Code: Select all

[color=#008000]"""[/color]
[color=#008000]Author: SRh[/color]
[color=#008000]Date: 2013_09_10[/color]
[color=#008000]Version: 1.0[/color]

[color=#008000]"""[/color]
[color=#008000]## activate IO library[/color]
[color=#00008b][B]from[/B][/color] System.IO [color=#00008b][B]import[/B][/color] File, Directory, FileInfo
[color=#008000]## path to localy installed python library:[/color]
PythonPath = r[color=#ff00ff]'C:\Program Files (x86)\IronPython 2.7\Lib'[/color]
[color=#00008b][B]import[/B][/color] sys
sys.path.[color=#191970][B]append[/B][/color](PythonPath)
[color=#00008b][B]import[/B][/color] xml.etree.ElementTree [color=#008b8b][B]as[/B][/color] ET

# this older function should also work for the current ZEN 2012 Verison which is out in the field
[color=#0000ff][B]def[/B][/color] [color=#191970][B]GetWellNames_old[/B][/color](image):
    wells = []
    ac = image.Core.[color=#191970][B]CreateAccessor[/B][/color]()
    numwells = ac.Metadata.Information.Image.Dimensions.S.Scenes.Count

    [color=#0000ff][B]for[/B][/color] i [color=#0000ff][B]in[/B][/color] [color=#191970][B]range[/B][/color]([color=#00008b]0[/color],numwells,[color=#00008b]1[/color]):
        well = ac.Metadata.Information.Image.Dimensions.S.Scenes[i].Name
        wells.[color=#191970][B]append[/B][/color](well)
        
    [color=#000080]return[/color] wells

[color=#0000ff][B]def[/B][/color] [color=#191970][B]GetWellNames[/B][/color](image):
    wells = []
    numwells = image.Bounds.SizeS
    [color=#191970][B]print[/B][/color] [color=#ff00ff]'Number of Wells : '[/color], numwells
    [color=#0000ff][B]for[/B][/color] i [color=#0000ff][B]in[/B][/color] [color=#191970][B]range[/B][/color]([color=#00008b]0[/color],numwells,[color=#00008b]1[/color]):
        IDString = r[color=#ff00ff]'Metadata/Information/Image/Dimensions/S/Scenes['[/color] + [color=#191970][B]str[/B][/color](i) + [color=#ff00ff]']/Name'[/color]
        [color=#008000]#print IDString[/color]
        well = image.Metadata.[color=#191970][B]GetMetadataWithPath[/B][/color](IDString)
        wells.[color=#191970][B]append[/B][/color](well)

    return wells


    
[color=#0000ff][B]def[/B][/color] [color=#191970][B]ExtendFileNameWithWell[/B][/color](folder, wellnames):
    [color=#008000]## rename single OME-TIFF files and extend file name with wellplate identifier [/color]
    [color=#0000ff][B]for[/B][/color] i [color=#0000ff][B]in[/B][/color] [color=#191970][B]range[/B][/color]([color=#00008b]0[/color],folder.Length): 
        file = folder[i]
        newfile = file[:-[color=#00008b]11[/color]] + wellnames[i] + [color=#ff00ff]'.ome.tiff'[/color]
        [color=#191970][B]print[/B][/color] [color=#ff00ff]'New Filename : '[/color],newfile
        File.[color=#191970][B]Move[/B][/color](file, newfile);


[color=#008000]## create setup dialog and enter source and destination directory with GUI[/color]
window = [color=#191970][B]ZenWindow[/B][/color]()
Images = Zen.Application.Environment.[color=#191970][B]GetFolderPath[/B][/color](ZenSpecialFolder.Images)
window.[color=#191970][B]AddFolderBrowser[/B][/color]([color=#ff00ff]'sourcedir'[/color],[color=#ff00ff]'Source folder:'[/color],Images)
window.[color=#191970][B]AddFolderBrowser[/B][/color]([color=#ff00ff]'destdir'[/color],[color=#ff00ff]'Destination folder:'[/color],Images)
result=window.[color=#191970][B]Show[/B][/color]()

[color=#008000]## read results[/color]
sd = result.[color=#191970][B]GetValue[/B][/color]([color=#ff00ff]'sourcedir'[/color])
dd = result.[color=#191970][B]GetValue[/B][/color]([color=#ff00ff]'destdir'[/color])

[color=#008000]## read XML settings file template[/color]
settingsfile = r[color=#ff00ff]'C:\Users\M1SRH\Documents\Carl Zeiss\ZEN\Documents\Export_Settings\Export_Wells_from_CZI_as_OME_TIFF.xml'[/color]
tree = ET.[color=#191970][B]ElementTree[/B][/color](file=settingsfile)
root = tree.[color=#191970][B]getroot[/B][/color]()

[color=#008000]## find entry for destination folder[/color]
outfolderXML = tree.[color=#191970][B]find[/B][/color]([color=#ff00ff]'DestFolder'[/color])
[color=#008000]## modify entry according to the input[/color]
outfolderXML.text = dd
[color=#008000]## create XML string[/color]
xmlstr = ET.[color=#191970][B]tostring[/B][/color](root, encoding=[color=#ff00ff]'utf8'[/color], method=[color=#ff00ff]'xml'[/color])

[color=#008000]## check directory for files to export[/color]
files = Directory.[color=#191970][B]GetFiles[/B][/color](sd,[color=#8b0000]"*.czi"[/color])

[color=#008000]## load images and export as OME-TIFF [/color]
[color=#0000ff][B]for[/B][/color] i [color=#0000ff][B]in[/B][/color] [color=#191970][B]range[/B][/color]([color=#00008b]0[/color],files.Length): 
    file = files[i]
    [color=#191970][B]print[/B][/color] [color=#ff00ff]'Exported File : '[/color],file    
    fileInfo = [color=#191970][B]FileInfo[/B][/color](file) 
    PathAndFile = sd + [color=#8b0000]"\\"[/color] + fileInfo.Name
    image = Zen.Application.[color=#191970][B]LoadImage[/B][/color](PathAndFile,[color=#191970][B]False[/B][/color])
    wellnames = [color=#191970][B]GetWellNames_old[/B][/color](image) # use with ZEN 2012 SP1
    #wellnames = [color=#191970][B]GetWellNames[/B][/color](image) # this will work in the future with the upcoming version of ZEN
    [color=#191970][B]print[/B][/color] wellnames
    prefix = image.Name
    Zen.Processing.Utilities.[color=#191970][B]ExportOmeTiff[/B][/color](image, xmlstr, prefix)
    

[color=#008000]## check output directory for files to rename export[/color]
outdir = Directory.[color=#191970][B]GetFiles[/B][/color](dd,[color=#8b0000]"*.ome.tiff"[/color])
[color=#191970][B]ExtendFileNameWithWell[/B][/color](outdir, wellnames)
Attachments
Export_Wells_from_CZI_as_OME_TIFF.txt
(487 Bytes) Downloaded 214 times
user-8
Posts: 63
Joined: Thu Jan 01, 1970 1:00 am

Useful Macro function to split wellplate data

Post by user-8 »

If someone just needs to split a single CZI containing all the wells into singel CZI files - one for every well, then you should play around with

Code: Select all

Zen.Processing.Utilities.[color=#191970][B]SplitScenes[/B][/color](image, outputdirectory, ZenCompressionMethod.[color=#191970][B]None[/B][/color], [color=#191970][B]True[/B][/color])
The option True will append the well container name to every created CZI ... :)

And for more sophisticated stuff, one can embedd this call in a batch loop as well.
user-3571
Posts: 2
Joined: Thu Jan 01, 1970 1:00 am

Post by user-3571 »

Dear Sebi,

Thanks a lot for the quick response. Will try and update.
user-64
Posts: 22
Joined: Thu Jan 01, 1970 1:00 am

Meta Data access

Post by user-64 »

I am receiving an error on this bit

image1.Metadata.GetMetadataWithPath

with the error indicating there is no such "GetMetadataWithPath". The intellisense does not show this as an operator for Metadata either.

Am I missing something?
user-8
Posts: 63
Joined: Thu Jan 01, 1970 1:00 am

Post by user-8 »

Dear Dan,

nope, You did not miss something .... it was my mistake. Sorry for this. I updated the original post. For whatever reasons some parts of the code got lost when I wrote my original post.

Just copy & paste the complete macros and use GetWellNames_old (right now) or GetWellNames (in the near future...).

Please let me know, if that worked for you. My resulting folder looks like this:
The attachment Well_Plate_Experiment_All_in_One_Export_.jpg is no longer available
Cheers, CZ6
Attachments
Well_Plate_Experiment_All_in_One_Export_.jpg
Well_Plate_Experiment_All_in_One_Export_.jpg (26.49 KiB) Viewed 3177 times
user-8
Posts: 63
Joined: Thu Jan 01, 1970 1:00 am

CZI Wellplate Data Handling Tutorial

Post by user-8 »

Since I have heard that we deal a lot with wellplate style experiments using ZEN Blue, I put together a little tutorial.
To be clear, a major problem is not a lack of functionality but rather the fact that this functionality is not really known in the field.

Setting up a well plate style experiment with Tile & Positions in ZEN Blue is very powerful and works well. I would even say, it is much more powerful compared to what I ever have seen before.

The attached document contains the description of a workflow which will allow the user to split the CZI data into single data sets, where the file name already contains the well name. Zen can do a lot of processing and analysis. If you prefer a special kind of analysis that is offered by a different software package the tutorial demonstrates how to combinne ZEN and Fiji. It shows how to split the single data sets into their CZT dimensions and run an optional MaxInt projection on the Z-Dimension.

It is the 1st version of the document, so please do not hesitate to suggest improvements or even report problems.

Happy "Wellplating",

Sebi
Attachments
Export_CZI_WellPlate_MaxInt.zip
(1.89 KiB) Downloaded 201 times
Batch_Well_Export_from_single_CZI_and_Split_Fiji_GUI.zip
(1.82 KiB) Downloaded 202 times
Export_CZI_Wellplate_Data.pdf
(1.26 MiB) Downloaded 270 times
user-6244
Posts: 11
Joined: Thu Jan 01, 1970 1:00 am

Post by user-6244 »

To loop over all individual well images, I would do something like:

Code: Select all

image1 = Zen.Application.Documents.ActiveDocument
imgs = Zen.Processing.Utilities.SplitScenesToArray(image1)
for img in imgs:
    well_name = img.Metadata.GetMetadataStringWithPath('Metadata/Information/Image/Dimensions/S/Scenes[current]/Name')
    print(well_name)
    # Your image processing code goes here
The way to access the well name is quite absurd, but I haven't seen any other way to do it...
Post Reply