Recording tiled images

Post your acquisition-related questions and macros here
Post Reply
user-4059
Posts: 1
Joined: Thu Jan 01, 1970 1:00 am

Recording tiled images

Post by user-4059 »

Hello everyone,

I have been trying to create a script that, at a given position, will record a 3x3 tiled image and add it to an existing document as a scene.

1) So far I have not been able to figure out how make Zen record the tiled image at the current position. Using ExecuteMultiImages Zen will move the stage to the center coordinate defined in the XML. Is there a way to work around this or will I have to implement a loop for recording the tiles individually?

2) Given a set of tile images (e.g. obtained by ExecuteMultiImages), how do I combine them to a scene? So far I only found the API calls for adding scenes to a document, but not for creating a scene out of tiles.

Any input is appreciated.
user-9
Posts: 82
Joined: Thu Jan 01, 1970 1:00 am

Post by user-9 »

theup wrote:Hello everyone,

I have been trying to create a script that, at a given position, will record a 3x3 tiled image and add it to an existing document as a scene.

1) So far I have not been able to figure out how make Zen record the tiled image at the current position. Using ExecuteMultiImages Zen will move the stage to the center coordinate defined in the XML. Is there a way to work around this or will I have to implement a loop for recording the tiles individually?

2) Given a set of tile images (e.g. obtained by ExecuteMultiImages), how do I combine them to a scene? So far I only found the API calls for adding scenes to a document, but not for creating a scene out of tiles.

Any input is appreciated.
[A multi scene image is generated automatically, if a Tiles experiment (defined with tiles on several positions in ZEN on Acquisition tab) is executed.
You can use SplitScenes (WriteFiles) to extract and save the separate scenes.
Maybe the following macro code could be helpful to execute a MultiImages experiment and display the single scenes (create an experiment with more than 1 scene first).
## Define experiment
exp = ZenExperiment()
## Load experiment
exp.Load('MyScenes.czexp')
##
## Image with all scenes is saved automatically in temp folder of AutoSavePath of Saving tab of Tools/Options menu
## Single scenes are saved, if 'Split Scenes into Separate Files' is activated in the Options of the Tiles Tool in Acquistion tab
##
## execute experiment and get a list of all images (an image including all scenes and single scene images as satellites)
images = Zen.Acquisition.ExecuteMultiImages(exp)
##
## Display the single scene images (0 is the image including all scenes)
im = 0
for image in images:
im = im + 1
if im > 0:
Zen.Application.Documents.Add(image) ]
user-8
Posts: 63
Joined: Thu Jan 01, 1970 1:00 am

Post by user-8 »

Hi guys,

at lear for 1) I have a good solution. All you have to do is to predefine your desired 3x3 Tile experiment. And them you have to:

- move to the desired xy position and focus
- read out the XYZ position via OAD script
- use TileTools.py to modify the XYZ position and run the experiment
- add the result to an image document

Code: Select all

"""
File: TileTools.py
Version: 0.1

This is a collection of little python functions that can be used to modify 
a ZEN Experiment containing one (!) TileRegion yet.
It supposed to be used to automatically adapt a TileRegion to the size of a detected ROI via Image Analysis
inside a RareEvent Detection workflow, but can be used anywhere from a OAD macro

Important : Requires ZEN 2012 SP2 (DVD52)

Example usage from an OAD macro:

import sys
# path to the folder containing tools scripts --> this depends on your machine, but the folder can be placed anywhere ...
scriptfolder = r'C:\Users\...\Documents\Carl Zeiss\ZEN\External_Python_Scripts_for_OAD'
sys.path.append(scriptfolder)

# import the tool script
import TileTools as tt

# load the experiment
exp = Zen.Acquisition.Experiments.GetByName('Tile_Scan.czexp')
tt.ShowTileInfoFromExperiment(exp)
# modify XY(Z) position of the Tile
exp_mod = tt.ModifyXYZ(exp,-4000,-6000, 300)
# modify contour size --> tiles will adapt automatically
exp_mod = tt.ModifyTileSize(exp_mod, 4000, 2000)
# execute the experiment
#Output_Images = Zen.Acquisition.Execute(exp)

"""

# Requirem import stuff
import clr
clr.AddReferenceByPartialName("Zeiss.Micro.Acquisition.Tiles")
from Zeiss.Micro.Acquisition import RegionsSetup, TilesSetup 
clr.AddReferenceByPartialName("Zeiss.Micro.LM.Acquisition")
from Zeiss.Micro.Acquisition import MultiTrackSetup
clr.AddReferenceByPartialName("WindowsBase")
from System.Windows import Point
from System.Windows import Size


def GetTileSetups(TileExp):

    # get the first experiment block
    firstblock = TileExp.Core.ExperimentBlocks[0]
    # get the RegionsSetup
    regionssetup = firstblock.GetDimensionSetup(RegionsSetup)
    # get all tracks
    tilessetup = regionssetup.GetDimensionSetup(TilesSetup)
    multiTrackSetup = tilessetup.GetDimensionSetup(MultiTrackSetup)
    # get number of Tile Regions and Tiles
    NumberTileRegions = regionssetup.SampleHolder.TileRegions.Count
    NumberTiles = regionssetup.SampleHolder.TilesCount
    
    return firstblock, regionssetup, tilessetup, NumberTileRegions, NumberTiles

# Show the tile information using the tileregion object
def ShowTileInfo(tileregion):
    
    #print 'Tile Center Position XYZ : ', tileregion.Contour, tileregion.CenterPosition.Y, tileregion.Z
    print 'Tile Center Position XYZ : ', tileregion.CenterPosition.X, tileregion.CenterPosition.Y, tileregion.Z
    print 'Tile Contour Size        : ', tileregion.ContourSize.Width, tileregion.ContourSize.Height
    print 'Tile Size XY             : ', tileregion.Columns, ' x ', tileregion.Rows

# Show tile information using the ZEN experiment file    
def ShowTileInfoFromExperiment(TileExp):

    [firstblock, regionssetup, tilessetup, NumberTileRegions, NumberTiles] = GetTileSetups(TileExp)
    
    # show information
    for i in range(0,NumberTileRegions,1):

        tileregion = regionssetup.SampleHolder.TileRegions[i]
        print 'Tile Information'
        ShowTileInfo(tileregion)

# modify Tile XYZ Position
def ModifyXYZ (*args):

    TileExp    = args[0] # 1st argument must be the Tile Experiment 
    NewX    = args[1] # 2nd argument must be new X-Position
    NewY    = args[2] # 3nd argument must be new Y-Position
    # the Z-Position of the Tile is optional
    if len(args)==4:
        NewZ    = args[3] # 4th argument can be the new Z-Position; if not used, the Z is not modified

    [firstblock, regionssetup, tilessetup, NumberTileRegions, NumberTiles] = GetTileSetups(TileExp)

    # change the XYZ position of the tile region
    for i in range(0,NumberTileRegions,1):

        tileregion = regionssetup.SampleHolder.TileRegions[i]
        tileregion.CenterPosition = Point(NewX, NewY)
        
        # set the new z-Value for the current tile region
        if len(args) == 4:
            tileregion.Z = NewZ
        # show new XYZ positions
        print 'New Tile Information'
        ShowTileInfo(tileregion)

    return TileExp
    
    
def ModifyTileSize (TileExp, NewSizeX, NewSizeY):

    [firstblock, regionssetup, tilessetup, NumberTileRegions, NumberTiles] = GetTileSetups(TileExp)

    # change the Contour --> Tile Number will be adapted automatically
    for i in range(0,NumberTileRegions,1):

        tileregion = regionssetup.SampleHolder.TileRegions[i]    
        # modify the contour size
        tileregion.ContourSize = Size(NewSizeX, NewSizeY) 
        # show updated tile information
        print 'New Tile Information'
        ShowTileInfo(tileregion)

    return TileExp
Save the file as TileTools.py

Cheers,

CZ6
user-5572
Posts: 9
Joined: Thu Jan 01, 1970 1:00 am

Post by user-5572 »

Hi everyone,

is there a way to use a focus plane, instead of just defining just one Z value per tile-image.
Or was it possibele to modify the Z-value of single tiles of the image independentley?

Best regards,
Alexander
user-9
Posts: 82
Joined: Thu Jan 01, 1970 1:00 am

Post by user-9 »

A focus plane can be defined in the Focus Strategy tool (Use Focus Surface/Z Values Defined by Tiles Setup).
Please verify the Support points in the Focus Surface section of the Tiles tool.
user-5572
Posts: 9
Joined: Thu Jan 01, 1970 1:00 am

Post by user-5572 »

Thank you for your fast response

if one defines support points like this:

Code: Select all

regionssetup.SampleHolder.TileRegions[0].SupportPoints[index].Z = newZ
when does ZEN use the focus plane as Z values an when does it use this Z value:

Code: Select all

tileregion.Z = NewZ
is it possible from an OAD macro to choose wich of both options should be used ?

I have found this line in the experiment-file :

Code: Select all

 <PreferSupportPointsZ>false</PreferSupportPointsZ>
can this be changed using a Zen method?

by the way, does anyone know the purpose of this line in the experiment file:

Code: Select all

<IsProtected>false</IsProtected>
best regards,
Alexander
Post Reply