Code: Select all
#######################################################
## M I S C E L L A N E O U S
##
## Macro name: Morphology of cell nuclei and data transfer to Excel
## Required files: 018 - morphology of nuclei.zvi
##
## LOAD IMAGE, SEGMENT NUCLEI, MEASURE SIZE OF NUCLEI
## SEND DATA TO EXCEL AND GENERATE DATALIST AND CHART
##
#######################################################
##
##
#import clr
clr.AddReferenceByName('Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c')
from Microsoft.Office.Interop import Excel
excel = Excel.ApplicationClass()
#######################################################
# 1 Demo
# 0 work
demo = 0
#######################################################
## LOAD IMAGE, SEGMENT NUCLEI, MEASURE SIZE OF NUCLEI
##
## UC 34 - Morphology of cell nuclei
#######################################################
##
##
## Remove all open images
Zen.Application.Documents.RemoveAll()
##
## Load the image automatically (example image of DVD 36)
## Display the image
image = Zen.Application.LoadImage ('C:\\OAD\\Input\\ZVI Images\\018 - morphology of nuclei.zvi')
#-----------------------------------------
if demo == 1:
Zen.Application.Documents.Add(image)
#-----------------------------------------
## Set channel color for DAPI
image.SetChannelColor(0,ZenColors.Blue)
##
## Load measurement program
## Measure automatically (Run Silent)
## Show results in Analysis view
ias=ZenImageAnalysisSetting()
ias.Load("UseCase 03 - Morphology of cell nuclei.czias")
Zen.Analyzing.Analyze(image,ias)
##
## Create data list with results
regTable = Zen.Analyzing.CreateRegionTable(image)
#-----------------------------------------
if demo == 1:
Zen.Application.Documents.Add(regTable)
#-----------------------------------------
##
## Save data list automatically
regTableName = regTable.Name
#-----------------------------------------
if demo == 1:
regTable.Save("C:\\OAD\\Output\\CSV Tables\\" + regTable.Name + ".csv")
#-----------------------------------------
##
## Save measured image automatically
if demo == 1:
fileNameWE = image.Name.Substring(0,image.Name.Length-4)
newFileName = fileNameWE + '.czi'
imageName = "C:\\OAD\\Output\\CZI Images\\" + newFileName
image.Save(imageName)
##
#######################################################
#######################################################
## Transfer Data to Excel
##
#######################################################
##
if demo == 1:
excel.Visible = True
excel.DisplayAlerts = False
workbook = excel.Workbooks.Add()
worksheet = workbook.Worksheets[1]
excel.Cells(1,1).Value = "Region ID"
excel.Cells(1,2).Value = "Area[µm²]"
excel.Cells(1,3).Value = "Form Cicle"
excel.Cells(1,4).Value = "FeretRatio"
excel.Cells(1,5).Value = "Ellipse Angle[°]"
excel.Cells(1,6).Value = "Ellipse Major[µm²]"
excel.Cells(1,7).Value = "Ellipse Minor[µm²]"
for Row in range(0,regTable.RowCount):
for Col in range(0,regTable.ColumnCount):
excel.Cells(Row+2,Col+1).Value = regTable.GetValue(Row,Col)
xlLine = 4
msoFalse = 0
msoScaleFromTopLeft = 0
excel.Cells.Select()
excel.Cells.EntireColumn.AutoFit()
excel.Rows("1:1").Select()
excel.Selection.Font.Bold = True
excel.Range("A1").Select
excel.ActiveSheet.Shapes.AddChart().Select()
excel.ActiveChart.ChartType = xlLine
excel.ActiveChart.SetSourceData(excel.Range("Sheet1!$A$1:$G$32"))
ActiveShape = excel.ActiveSheet.Shapes(excel.ActiveSheet.Shapes.Count)
ActiveShape.Left = 500
ActiveShape.Top =50
ActiveShape.ScaleWidth(1.4416666667, msoFalse, msoScaleFromTopLeft)
ActiveShape.ScaleHeight(1.8420140712, msoFalse, msoScaleFromTopLeft)
excel.Range("A1").Select()
if demo == 0:
excel.Visible = True
##
#######################################################