ImagePro Premier macro for intensity measurement of multiple ROIs
Hello,
I am not good at macro scripting in ImagePro Premier. I used such a macro (see below) with ImagePro Plus 7 to obtain a time sequence of total intensity of multiple ROIs, each of which contained a fluorescent spot, created by the manual tag tool.
The macro mainly consists of the following four parts.
(1) Multiple points were selected in the upper half of a sequence (movie).
(2) The xy coordinates of the counterpart points in the lower half of a sequence were calculated (+ 63 pixel (y coordinate)).
(3) Square ROIs (9x9 pixels) were created using the points.
(4) Intensity of the ROIs were calculated and saved in a file.
Could you give me some advice or hopefully write a macro that works for ImagePro Premier?
Thank you in advance.
Option Explicit
Sub fi_counterpart()
Dim i As Integer
Dim frame0 As Long
Dim frame1 As Long
Dim FrLen As Integer
Dim FrStart As Integer
Dim Radius As Integer
Dim filename As String * 255
ret=IpTagShow(1)
'
Dim dlg As UserDialog
Dialog dlg
'
Begin Dialog UserDialog 450, 100, "Title Line"
Text 10, 10, 400, 20, "Do you want to add Title line?"
PushButton 150,60,50,20, "Yes"
PushButton 250,60,50,20, "No"
End Dialog
Dim dlg2 As UserDialog
'
ret = IpSeqGet( SEQ_ACTIVEFRAME, frame0)
ret = IpSeqGet( SEQ_END, frame1)
'
ret = IpStGetInt("Length of Run (Frame)", FrLen, CInt( (frame1 - frame0 + 1) ), 1, CInt( (frame1 - frame0 + 1) ))
If ret = 0 Then End
ret = IpStGetInt("Start Time (Frame)", FrStart, 0, 0, 10000)
If ret = 0 Then End
ret = IpStGetInt("ROI Size to Measure (Pixel)", Radius, 4, 1, 15)
If ret = 0 Then End
Dim SHIFT_X As Integer
Dim SHIFT_Y As Integer
ret = IpStGetInt("SHIFT x (pixel)", SHIFT_X, 0, -640, 640)
If ret = 0 Then End
ret = IpStGetInt("Shift y (pixel)", SHIFT_Y, 63, -480, 480)
If ret = 0 Then End
ret = IpStGetName("Specify filename for output", CurDir$(), "*.dat", filename)
If ret = 0 Then End
'
Dim PtsIndex As Integer
Dim TotalPts As Integer
Dim nPts As Single
Dim lpParam(7) As Single
Dim PtCrd() As RECT
'
Dim PtCrd_counterpart() As RECT
'
ret = IpTagGet( GETNUMPTS, -1, nPts)
TotalPts = nPts
' Total number of tags = nPts
ReDim PtCrd( TotalPts ) As RECT
ReDim PtCrd_counterpart( TotalPts ) As RECT
For PtsIndex = 0 To (TotalPts - 1)
ret = IpTagGet(GETPOINTS, PtsIndex, lpParam(0))
PtCrd( PtsIndex ).Left = CInt(lpParam(0)) - Radius
PtCrd( PtsIndex ).Right = CInt(lpParam(0)) + Radius
PtCrd( PtsIndex ).top = CInt(lpParam(1)) - Radius
PtCrd( PtsIndex ).bottom= CInt(lpParam(1)) + Radius
PtCrd_counterpart( PtsIndex ).Left = CInt(lpParam(0)) - Radius + SHIFT_X
PtCrd_counterpart( PtsIndex ).Right = CInt(lpParam(0)) + Radius + SHIFT_X
PtCrd_counterpart( PtsIndex ).top = CInt(lpParam(1)) - Radius + SHIFT_Y
PtCrd_counterpart( PtsIndex ).bottom= CInt(lpParam(1)) + Radius + SHIFT_Y
Debug.Print PtsIndex
Next PtsIndex
'
Open filename For Append As #1
If ( Dialog(dlg2) = 1 ) Then
Print #1, "Frame Time";
For PtsIndex = 0 To (TotalPts-1)
Print #1, " " ; Format$(PtsIndex, "R000") ;
Next PtsIndex
Print #1, ""
End If
'
For i = 1 To FrLen
Print #1, (FrStart + i - 1) ; " " ; Format( (CSng(FrStart + i - 1) / 30.0), "####0.000") ;
' ret = IpTagUpdate()
Call FiRead_counterpart(TotalPts, PtCrd(), PtCrd_counterpart())
ret = IpSeqPlay(SEQ_NEXT)
Next i
Close #1
End
End Sub
Sub FiRead_counterpart(TotalPts As Integer, PtCrd() As RECT, PtCrd_counterpart() As RECT)
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer
Dim m As Integer
Dim imgbuff() As Integer
Dim fi As Long
Dim fi_counterpart As Long
Dim dx As Integer
Dim dy As Integer
Dim dx_counterpart As Integer
Dim dy_counterpart As Integer
'
dx = PtCrd(0).Right - PtCrd(0).Left + 1
dy = PtCrd(0).bottom - PtCrd(0).top + 1
dx_counterpart = PtCrd_counterpart(0).Right - PtCrd_counterpart(0).Left + 1
dy_counterpart = PtCrd_counterpart(0).bottom - PtCrd_counterpart(0).top + 1
ReDim imgbuff(dx, dy)
'
For i = 0 To (TotalPts-1)
IpDocGetArea( DOCSEL_ACTIVE, PtCrd( i ), imgbuff(0, 0), 0)
fi = 0
For j = 0 To dx
For k = 0 To dy
fi = fi + imgbuff(j, k)
Next k
Next j
IpDocGetArea( DOCSEL_ACTIVE, PtCrd_counterpart( i ), imgbuff(0, 0), 0)
fi_counterpart = 0
For l = 0 To dx_counterpart
For m = 0 To dy_counterpart
fi_counterpart = fi_counterpart + imgbuff(l, m)
Next m
Next l
Print #1, " " ; Format(fi, "######");
Print #1, " " ; Format(fi_counterpart, "######");
Next i
Print #1, Chr$(13);
End Sub
Answers
Getting intensity measurements from multiple ROIs in Image-Pro Premier is much easier than in IPPlus. We have a special tool "Intensity Tracking" (Measure tab) specifically for that (you don't need a macro). You just draw measurement areas on the image and the intensity distributions are reported in data tables and graphs:
Yuri
Yuri,
Thank you for your response and sorry for the delay in writing this comment.
I know the “Intensity Tracking” tool, however, this tool seems not to draw counterpart ROIs automatically.
What I would like to learn is the way how a macro obtains xy coordinates of manual tags and ROIs (the coordinates are displayed in the Data Table and Feature collections etc.) and create new ROIs using these coordinates.
Intensity measurement of multiple ROIs, which I would like to do, may be performed by manual tags and ROIs.
(1) By manual tags
(1-1) Select multiple points (fluorescent spots) by manual tagging containing the fluorescent spots in the upper half of a sequence (movie).
(1-2) The xy coordinates the manual tags are obtained and the counterpart fluorescent spots in the lower half of a sequence are calculated (for example, + 63 pixel (y coordinate)) using the coordinates.
(1-3) Square ROIs are created using the obtained and calculated coordinates as centers.
(1-4) Intensity of the ROIs are measured by the Intensity Tracking tool and saved in a file.
(2) By ROIs
(2-1) Load an roi file containing multiple square ROI collection.
(2-2) Move the ROIs to fluorescent spots in the upper half of a sequence (movie).
(2-3) The xy coordinates of the counterpart fluorescent spots in the lower half of a sequence are calculated (for example,+ 63 pixel (y coordinate)) using the coordinates of the ROIs.
(2-4) Square ROIs for the counterpart fluorescent spots are created using the coordinates.
(2-5) Intensity of the moved and created ROIs are measured by the Intensity Tracking tool and saved in a file.
inexperienced
I have missed your responce and found it only today. Here is what I can recommend:
1. You can get coordinates of measurement objects/tags using GetFeaturePoints function, please check this forum post as an example: http://forums.mediacy.com/discussion/comment/2311#Comment_2311
2. Creation of objects: (ROI, Measurements, Tracking areas) are macro-recordable, so you can just activate macro recording, create a test objects and stop recording, then you can modify the recorded macro to use the coordinates obtained by the step 1.
Yuri
Yuri
Thank you for your reply.
I can get coordinates of measurement tags.
I still have to do to complete my task.
1) Create counterpart tags
2) ROIs or tracking areas are created using the coordinates of tags
3) Intensity of the ROIs or tracking areas are measured
I am glad if you would give some suggestions for them.
inexperienced
All your tasks, from 1 to 3, can be coded based on auto-recorded macros. You just activate macro recording and do these steps, then you can modify the macro to use coordinates of measurement tags.
Yuri