exporting/importing list of image locations from/for a mosaic

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

exporting/importing list of image locations from/for a mosaic

Post by user-5486 »

Hello,

I am fairly new at using the macro programming with Zen Blue, and some advice/direction would be great.

I am working on integrating a external rotation stage onto our microscope. The rotation stage movements are called via python, and I am now trying to collect a mosaic in the same location on the sample at each rotation. I know how to find the eucentric point of the rotation stage on the zeiss x-y stage, and then how to apply the eucentric point to locations on the sample, but I need to apply the change inside the macro. I see two possible ways to do this:

1) rotate the entire mosaic region around the center of mass of the mosaic region inside the zen software (not sure if possible) or

2) extract a list of the tile locations of the mosaic, then apply the transformation around the eucentric point in python for each tile location. Then the x-y locations for the new rotation can be fed into a script and the individual tiles can be collected. I am fine with extracting each individual tile and stitching the images externally (I already have scripts to perform the stitching).

Thanks for any help possible!
Mike
user-9
Posts: 82
Joined: Thu Jan 01, 1970 1:00 am

Post by user-9 »

1) rotate the entire mosaic region around the center of mass of the mosaic region
Zen offers 2 functions for image rotation:
Zen.Processing.Transformation.Geometric.Rotate()
Zen.Processing.Transformation.Geometric.Rotate2D()
2) extract a list of the tile locations of the mosaic, then apply the transformation around the eucentric point in python for each tile location. Then the x-y locations for the new rotation can be fed into a script and the individual tiles can be collected.
You can extract the individual tiles and get the stage positions of the tiles metadata for further calculation.
The 2 macros might be helpful.

Code: Select all

#######################################################
## I M A G E   P R O C E S S I N G 
##
## Macro name: MEF 2013 - Extract individual tile images
## First the scenes are extracted, then the tiles of the scenes.
##
#######################################################
##
## Remove all open images
Zen.Application.Documents.RemoveAll()
##
## Import the system library
import System.DateTime
##
## activate IO library
from System.IO import File, Directory, FileInfo
## 
## create setup dialog
window = ZenWindow()
#Images = Zen.Application.Environment.GetFolderPath(ZenSpecialFolder.Images)
InImages = "C:\\OAD\\Input\\CZI Images"
OutImages = "C:\\OAD\\Output"
window.AddFolderBrowser('sourcefolder','Source folder            ',InImages)
window.AddFolderBrowser('destfolder','Destination folder    ',OutImages)
window.AddDropDown('osval','Output Image type', ['.CZI','.JPEG', '.BMP', '.TIFF'], 0)
##
## do setup
result=window.Show()
## check, if Cancel button was clicked
if result.HasCanceled == True:
    sys.exit('Macro aborted with Cancel!')
## get string name of source/destination folder
path = str(result.GetValue('sourcefolder'))
newPath = str(result.GetValue('destfolder'))
## Check, if path exists
if (Directory.Exists(path)== False):
    strMessage = 'Path: ' + path + ' does not exist!\nRestart macro and select an existing path!'
    sys.exit(strMessage)
## Check, if newPath exists
if (Directory.Exists(newPath)== False):
    strMessage = 'Path: ' + newPath + ' does not exist!\nRestart macro and select an existing path!'
    sys.exit(strMessage)
## get and set file type
itype = '*.CZI'
otype = str(result.GetValue('osval'))
## get files
files = Directory.GetFiles(path,itype) 
## Check, if image type exists
if files.Length == 0: 
    strMessage = 'Images of type : ' + itype + ' do not exist!\nRestart macro and select an existing image type!'
    sys.exit(strMessage)
##
## get time START
start = System.DateTime.Now
print 'Start time: ', start
##
## IMAGES
## start loop over all CZI IMAGES in the folder
count = 0
for image in range(0,files.Length):
    ## Check if files are corrupted
    try:
        file = files[image] 
        fileInfo = FileInfo(file) 
        PathAndFile = path + "\\" + fileInfo.Name
        ## Load an image automatically
        ## Display the image
        image = Zen.Application.LoadImage(PathAndFile,False) 
        Zen.Application.Documents.Add(image)
        ## Extract file name without extension
        OrgFileNameWE = image.Name.Substring(0,image.Name.Length-4)
        ##
        ## SCENES
        ## start loop over all scenes
        for scene in range(0,image.Bounds.SizeS):
            if image.Bounds.IsMultiScene:
                ## Separate and show scene
                s = "S(" + str(scene+1) + ")"
                sceneImage = Zen.Processing.Utilities.CreateSubset(image, s)
                #Zen.Application.Documents.Add(sceneImage)
                ## Extract scene name
                SceneName = OrgFileNameWE + '-Scene-' + str(scene+1)
                sceneImage.Name = SceneName
            else:
                sceneImage = image
                SceneName = OrgFileNameWE 
            ##
            ## TILES
            ## check, if image is tile image
            if sceneImage.Bounds.IsTiles == True:
                ##
                ## M works only, if image has no pyramid!!!
                #for tile in range(0,image.Bounds.SizeM):
                    #m = "M(" + str(tile+1) + ")"
                    #tileImage = Zen.Processing.Utilities.CreateSubset(image, m)
                    ##tileImage = image.CreateSubImage(m)
                ##
                ## start loop over all tiles
                startM = sceneImage.Bounds.StartM
                sizeM = sceneImage.Bounds.SizeM
                for tile in range(startM,sizeM):
                    ## Separate and show tile
                    tileImage = ZenImage()
                    b = ZenBounds()
                    b.StartM = tile
                    b.SizeM = 1
                    ## to separate the channels
                    #b.StartC = image.Bounds.StartC
                    #b.SizeC = image.Bounds.SizeC
                    #print tile
                    tileImage.AddSubset(sceneImage, b)
                    #Zen.Application.Documents.Add(tileImage)
                    ## Extract tile name
                    TileName =  SceneName  + '-Tile-' + str(tile+1)
                    tileImage.Name = TileName 
                    newPathAndFile = newPath + "\\" +  TileName + otype
                    ## Save TILE image
                    ## Save with compression of org image for CZI and without for non-CZI
                    if otype == '.CZI':
                        Zen.Application.Save(tileImage,newPathAndFile,70,ZenSaveCompressionMode.AsIs)
                    elif otype != '.CZI':
                        Zen.Application.Save(tileImage,newPathAndFile)
                    count = count + 1
                    ##
                    ## Close tile image (otherwise it cannot be deleted in explorer)
                    tileImage.Close()
                    ## 
                    ## Prevent to put tile images to D:\SWAP\Zeiss
                    sceneImage.MakeSpace()
                ##
                ## end of loop over all tiles
                ## TILES
            ##
            ## Close scene image (otherwise it cannot be deleted in explorer)
            sceneImage.Close()
        ## end of loop over all scenes
        ## SCENES
        ##
        ## Close image (otherwise it cannot be deleted in explorer)
        image.Close()
    ##
    ## Give message, if files are corrupted
    except Exception,ex:
       print "Fatal error in:   " + PathAndFile
       print "Message: " + ex.message
    ##
    ## end of loop over all images
    ## IMAGES
##
## get time END
end = System.DateTime.Now
print 'End time: ', end
##
## Calculate and show duration
duration = end - start
print 'Duration: ',duration
##
## Show message
strMessage = str(count) + ' Single TILE images are saved in: ' + newPath
Zen.Application.Pause(strMessage)
##
#######################################################

Code: Select all

######################################################
## M I C R O S C O P E 
##
## Macro name: Get and set stage position
##
#######################################################
##
## Remove all open images
Zen.Application.Documents.RemoveAll()
##
## Get current stage position
## Show stage position 
posX = Zen.Devices.Stage.ActualPositionX
posY = Zen.Devices.Stage.ActualPositionY
stageinfo = 'Stage Pos X: ' + str(posX) + '\nStagePos Y: ' + str(posY) 
Zen.Windows.Show(stageinfo)
##
## Set stage position
## Show new stage position 
Zen.Devices.Stage.MoveTo(100,50)
## an alternative to set the position
#Zen.Devices.Stage.TargetPositionX = 200
#Zen.Devices.Stage.TargetPositionY = 150
#Zen.Devices.Stage.Apply()
stageinfo = 'New Stage Pos X: ' + str(Zen.Devices.Stage.ActualPositionX) + '\nNew Stage Pos Y: ' + str(Zen.Devices.Stage.ActualPositionY) 
Zen.Windows.Show(stageinfo)
##
#######################################################
Post Reply