Save object stage positions in text file

Share your programming ideas for various measurement and analysis tasks here
Post Reply
user-9
Posts: 82
Joined: Thu Jan 01, 1970 1:00 am

Save object stage positions in text file

Post by user-9 »

Code: Select all

#######################################################
## M E A S U R E M E N T   A N D   A N A L Y S I S
##
## Macro name: Save object stage positions in text file
## Required files: Move measured object to image center.czias
## Required hardware: AxioCam camera
##
## SNAP IMAGE, ANALYSE IMAGE, GET VALUES OF DATA LIST,
## CALCULATE OBJECT STAGE POSITION, SAVE POSITIONS IN TEXT FILE
## 
#######################################################
##
##
## Remove all open images
Zen.Application.Documents.RemoveAll()
##
##
## ACQUISITION
## Show live image
Zen.Acquisition.StartLive()
## Set exposure time (AutoExposure)
Zen.Acquisition.AutoExposure()
Zen.Application.Pause("Search field of interest and focus image!")
## Snap image
image = Zen.Acquisition.AcquireImage()
Zen.Application.Documents.Add(image)
## Close live image
Zen.Acquisition.StopLive()
##
## ANALYSIS
## Load analysis setting
ias = ZenImageAnalysisSetting()
ias.Load('Move measured object to image center')
## Analyze the image 
Zen.Application.Pause("Do setup for segmentation")
Zen.Analyzing.AnalyzeInteractive(image,ias)
## Create data list with results for all regions
regsTable = Zen.Analyzing.CreateRegionsTable(image)
#Zen.Application.Documents.Add(regsTable)
## Create data list with results for each region
regTable = Zen.Analyzing.CreateRegionTable(image)
#Zen.Application.Documents.Add(regTable)
##
## CREATE TEXT FILE
## Get stage posXY and scaleXY (regions table)
stagePosX = regsTable.GetValue(0,0)
stagePosY = regsTable.GetValue(0,1)
scaleX = regsTable.GetValue(0,2)
scaleY = regsTable.GetValue(0,3)
## Get of image centerXY (meta data)
width2 = int(image.Metadata.Width)/2
height2 = int(image.Metadata.Height)/2
## Get boundbox center positions of each object (region table)
## Calculate stage pos XY of each object
## Write postions to text file
### Note! Stage directions are not taken into account!
for row in xrange(regTable.RowCount):
    ## Calculate object stage coordinates
    id = regTable.GetValue(row,0)
    left = regTable.GetValue(row,1)
    top = regTable.GetValue(row,2)
    ## Move object into image center 
    objectStagePosX = stagePosX + (left - (width2 * scaleX))
    objectStagePosY = stagePosY + (top - (height2 * scaleY))
    ## CREATE TEXT FILE
    ## Write header
    if row == 0: 
        wFile = open('C:\\OAD\\Output\\ObjectStageCoordinates.txt','w')
        wFile.write ('XY Stage coordinates of analyzed objects\n')
        wFile.write('\n')
    ## Write object XY stage coordinate values
    wFile.write ('.\t {:6.1f}'.format(float(objectStagePosX)))
    wFile.write (', {:6.1f}'.format(float(objectStagePosY)))
    wFile.write ('\n')
##
## Close text file
wFile.close()
## Close image
image.Close()
## Show where coordinate list is saved
Zen.Application.Pause("ObjectStageCoordinates.txt is saved in folder: C:\\OAD\\Output")   
##
#######################################################
Michael Finn
Posts: 1
Joined: Thu Jun 08, 2023 12:52 pm

Re: Save object stage positions in text file

Post by Michael Finn »

While completing my programming report I provide a relevant code for this issue. I wrote multiple project documents If you want to connect with a report writing service then contact me. I would love to resolve your request.
Ecom Buzz
Posts: 1
Joined: Fri Jul 14, 2023 10:09 am

Re: Save object stage positions in text file

Post by Ecom Buzz »

We are an Affordable SEO Company based in India, offering high-quality SEO services to businesses of all sizes. Let us help you rank higher and attract more customers.
Post Reply