Home Image-Pro Automation (Macros, Apps, Reports)
Options

How to extract outline coordinates of an object

I need to extract the outline coordinates of an object into a data table, but there are some limitations. First, using the polygon bounden points is not ideal because they are not regularly spaced which would make the outline analysis more difficult.

I thought about extracting the radii measurement and using some basic trig to get the end points, but this would only give me 32 outline points and I may need more. Is it possible to change the radii measurement to adjust the number of measurements?

Another way of doing this would be to extract a specified number of equidistant points around the outline, how could I do this?

Finally, is there an easy way to display those point coordinates in the measurements data table to make it easy to export along with other measurements of the objects?

Best Answer

  • Options
    Answer ✓
    Hi David,

    Here is a macro that sets new Number Of Angles for Radii measurement (128) and prints it in the debug window. Run this macro after the Count operation.

        Public Sub PrintRadii()
            Dim im As McImage=ThisApplication.ActiveImage
            If im Is Nothing Then Exit Sub
            Dim md As McMMData=im.MeasurementsData
            If md.Count=0 Then Exit Sub
            Dim rgns As MediaCy.IQL.Features.McRegions=md(0).MainSubFeature.GetFeatures()
            If rgns Is Nothing Then Exit Sub'it's not regions
    
            rgns.maRgnRadii.NumAngles=128'define new number of angles
            'the measurements will be recalculated automatically
            'and all 128 Radii values can be shown in Object Window
    
            'print it, if we want to get low-level access
            Dim mRadii As New MeasEntry(eMeasures.aRgnRadii,mcmmStatField.Values)'get all values
            For Each sf As McMMSubFeature In md.SubFeatures
                Dim vals As Double()=sf.Value(mRadii)'get array of Radii values
                'print array of values
                Debug.Print sf.Name & " = " &   ThisApplication.GlobalTools.McToText(vals).Value
            Next
        End Sub
    
    Note, that you can also get all Radii values in the Object window.

    Regards,

    Yuri

Answers

  • Options
    Sorry for bringing up such an old discussion topic, but it seems most applicable to my application. I am using Image Pro 10, working with the "SPOTS.TIF" image, and I have used a count/size operation to detect each of the spots. What i want to do is output the caliper length at 1 degree increments for each feature (spot). I am having trouble adapting the code above. Can you help me?  Ultimately I want to summarize the angle at which the minimum and maximum caliper lengths for each spot occurred but I should be able to easily get that once I have the raw caliper data. 
  • Options
    Hi Sean,

    Here is the version of the macro that prints Calipers with 1 degree step (180 calipers):

        Public Sub PrintCalipers()
            Dim im As McImage=ThisApplication.ActiveImage
            If im Is Nothing Then Exit Sub
            Dim md As McMMData=im.MeasurementsData
            If md.Count=0 Then Exit Sub
            Dim rgns As MediaCy.IQL.Features.McRegions=md(0).MainSubFeature.GetFeatures()
            If rgns Is Nothing Then Exit Sub'it's not regions
    
            rgns.maRgnCalipers.NumAngles=180'define new number of angles, it's eqivalent to 1 degree step
            'the measurements will be recalculated automatically
            'and all 180 Caliper values can be shown in Object Window
    
            'print it, if we want to get low-level access
            Dim mRadii As New MeasEntry(eMeasures.aRgnCalipers,mcmmStatField.Values)'get all values
            ThisApplication.Output.Show
            ThisApplication.Output.Clear
            Dim header As String=""
            For Each sf As McMMSubFeature In md.SubFeatures
                Dim vals As Double()=sf.Value(mRadii)'get array of Caliper values
                If header="" Then
                    header="Calipers" & vbTab
                    For i As Integer=0 To vals.GetUpperBound(0)
                        header+=String.Format("{0}",i) + vbTab'tabseparated
                    Next
                    ThisApplication.Output.PrintMessage(header)
                End If
                Dim s As String=sf.Name & vbTab
                For Each v As Double In vals
                    s+=String.Format("{0:F2}",v) + vbTab'tabseparated
                Next
                ThisApplication.Output.PrintMessage(s)
            Next
        End Sub
    
    I've also attached an IPX file with this macro.

    Just load the project, create some measurements on the active image and run PrintCalipers macro


    You can also export the data from the Output window to Excel using the context menu.

    Regards,

    Yuri
  • Options
    Yuri - Thanks for the quick response. It worked great. Only problem is no matter what I changed "numAngles" to (tried 10 and 180) it always remained the same - 32. Funny thing is when I changed from "maRgnCalipers" to "maRgnRadii", it worked as expected. Is the increments for calipers locked to 32? 
  • Options
    Sean,

    You may need to execute Count again after you executed the macro as the measurements have been created with previous number of angles (default is 32). Then you run the macro again.

    Yuri

  • Options
    Yuri

    Thanks for response
    So I ran Caliper then Diameter then Caliper again back to back to back using numAngles of 360 for both cases. Worked for Diameter. Did not work for Caliper. Also executed Count again, reran,  and got same results. Appears there may be an issue with the Caliper command? FYI - Running 10.0.13.

    Sean
  • Options
    Sean,

    Try to update to the latest version 10.0.15 - https://my.mediacy.com/support/updates

    Yuri
Sign In or Register to comment.