getting access to pixel data of a special region
Hi guys,
when working on the data() structure by using your code in the forum disscussion "image buffer reading/writing":
How do I have to select a region to get the data-matrix?
Thx,
Svenja
when working on the data() structure by using your code in the forum disscussion "image buffer reading/writing":
Dim ra As McRegionAccess=im.CreateRegionAccess() ra.RegionMask=im.Aoi Dim data(,) As Object ra.GetArea(data)I always get the whole image in my data-matrix, but I just want to get a special Region.
How do I have to select a region to get the data-matrix?
Thx,
Svenja
0
Answers
You should open Region Access only for a specified area using aditional parameters of the function, here is the example:
Yuri
and then:
If ra Is Nothing Then Exit Sub ' wenn es keine ROI gibt, dann raus. Dim data(,) As Object Dim W,O,C,K,AGV,AGVS,M As Integer Dim GRAD As Double 'get 2D array of pixel data ra.GetArea(data) M=0 AGVS=0 tbBreite.Text=CStr(data.GetUpperBound(0)) tbHoehe.Text=CStr(data.GetUpperBound(1)) ' Durchlaufe Array For x As Integer = 0 To data.GetUpperBound(0) For y As Integer = 0 To data.GetUpperBound(1) lbOut.Items.Add("Data("+CStr(x)+","+CStr(y)+")="+CStr(data(x,y))) Next Next
Unfortunately my parameter (mean gradient value) is still calculated of the whole image instead of my rectangle ROI. It seems that ROI and image are completely separated objects. Could you please help us again?Kind regards, Svenja
How do you calculate "mean gradient value"? Can you post the macro?
Yuri
here the complete macro for the grey-scale parameters mean gradient value and contrast:
I converted your code to a macro and it works correctly for me.
Here is the macro:
Public Sub btnGradient_Click() Dim im As McImage=ThisApplication.ActiveImage If im Is Nothing Then Exit Sub ' Gradienten bestimmen ' Region ins Array 'Dim ra As McRegionAccess=im.CreateRegionAccess() 'ra.RegionMask=im.Aoi'process only active ROI 'lbOut.Items.Clear 'lbwock.Items.Clear ' Dim LOx,LOy,RUx,RUy As Integer ' LOx = CInt(tbLOx.Text) ' LOy = CInt(tbLOy.Text) ' RUx = CInt(tbRUx.Text) ' RUy = CInt(tbRUy.Text) Dim R As Mediacy.IQL.ObjectManager.SINGLERECT=im.Aoi.BoundingRect'get ROI bounding box 'open only ROI area Dim ra As McRegionAccess=im.CreateRegionAccess(,,,R.left,R.top,R.right,R.bottom) If ra Is Nothing Then Exit Sub ' wenn es keine ROI gibt, dann raus. Dim data(,) As Object Dim W,O,C,K,AGV,AGVS,M As Integer Dim GRAD As Double 'get 2D array of pixel data ra.GetArea(data) M=0 AGVS=0 'tbBreite.Text=CStr(data.GetUpperBound(0)) 'tbHoehe.Text=CStr(data.GetUpperBound(1)) ' Durchlaufe Array For x As Integer = 0 To data.GetUpperBound(0) For y As Integer = 0 To data.GetUpperBound(1) ' lbOut.Items.Add("Data("+CStr(x)+","+CStr(y)+")="+CStr(data(x,y))) Next Next Dim i,j As Integer For i = 3 To data.GetUpperBound(0)-2 For j = 3 To data.GetUpperBound(1)-2 ' Bestimme W,O,C,K K=data(i,j-2) W=data(i+2,j) O=data(i,j+2) C=data(i-2,j) ' Berechne AGV (Wurzel aus (W-C)² + (O-K)² AGV=((W-C)^2+(O-K)^2)^(1/2) ' neu von Svenja und Fritz ' AGV=(((W-C)^2)^(1/2))+(O-K)^2 ' Alt von Papa Andi ' Addiere AGV zur AGV-Summe AGVS=AGVS+AGV 'Kontrollausgabe 'tbAGV.Text = CStr(AGV) 'tbSumAGV.Text = CStr(AGVS) ' Zähle M hoch M=M+1 ' lbwock.Items.Add("M:"+CStr(M)+"-> "+CStr(data(i,j))+ _ ' " C:"+CStr(C)+" O:"+CStr(O)+ _ ' " W:"+CStr(W)+" K:"+CStr(K)+ _ ' " AGV:"+CStr(AGV)) ' tbM.Text = CStr(M) Next Next GRAD = AGVS / M ' tbGrad.Text = CStr(GRAD) ThisApplication.Output.Show ThisApplication.Output.PrintMessage(String.Format("ROI({0},{1},{2},{3}), Gradient = {4}", R.left,R.top,R.right,R.bottom,GRAD)) ' For i = 1 To data.GetUpperBound(0) ' For j = 1 To data.GetUpperBound(1) ' data(i,j). ' Next ' Next ' ra.PutArea(data) End Sub
When I move ROI around the image and execute the macro, I get different results:
Please test it with my macro.
Yuri
could you please give me a download file for your complete macro so I can load it in my Premier? Copy/paste dont work reliable.
Svenja
that works perfectly. Thank you very much for your help! It is now possible to read out the data of a ROI :-)