Home Image-Pro General Discussions

How to extract raw x and y coordinates from the outline of counted objects?

Hi, I'm new to using Image-Pro Premier so there's probably an easy solution to this, although I can't seem to see it..

After counting objects, I am able to right-click and then create a mean centroid point of an object, which has x,y coordinates displayed in the measurement table. However, is there an easy way to extract corresponding x,y coordinates for all of the points that bound the outline of the object?

Thanks,
Chris

Answers

  • Hi Chris,

    Extracting outline points is not exposed in the UI, though you can get the coordinates using a macro:

    Imports MediaCy.Addins.Measurements
    Imports MediaCy.IQL.ObjectManager
    
    ...
        Public Sub PrintOutlineCoordinates
            Dim im As McImage=ThisApplication.ActiveImage
            If im Is Nothing Then Exit Sub'no image
            Dim md As McMMData=im.MeasurementsData
            ThisApplication.Output.Show
            For Each sf As McMMSubFeature In md.SubFeatures
                Dim s As String=sf.Name
                Dim points() As SINGLEPOINT=Nothing
                sf.GetFeatures.GetFeaturePoints(sf.FeatureIndex,points)
                For Each p As SINGLEPOINT In points
                    s+=" {" & p.x.ToString("F2") & "," & p.y.ToString("F2") & "}"
                Next
                ThisApplication.Output.PrintMessage(s)
            Next
        End Sub

    Regards,

    Yuri
  • Thanks for the quick response Yuri. I'm afraid I'm not savvy with macros though (sorry!), so I'm not even sure how to go about doing this. Is it easy to implement/where do I go to write the macro?
  • Ok, then I will make it easy for you. Just download the attached project, double click on it - it will be opened in Premier, then open Project explorer (on the Automate tab) and from there run SampleOutline|Module1|PrintOutlineCoordinates macro (be sure that the active image has some measurements).

    BTW, what are you going to do with the coordinates? You get them printed in the output window - what next?

    Maybe be I am overcomplicating your task and you want to do something much simpler?

    Yuri

  • 2017-03-03-111454

    All --

    I would like to work with BOUNDARY POINTS from an AREA / REGION.

    The DISCUSSION above seems to be right on point about how to access this information within PREMIER.

    I downloaded

        SampleOutline.ipx

    and attempted to run it within

        PREMIER V9.1.4

    The ERROR MESSAGE (below TOP) was generated and then LINE 37 of the CODE (below BOTTOM) was highlighted.

    It seems that

        sf.FeatureIndex
        or
        points

    is not set up properly.

    Since this IPX FILE was supplied by Yuri, I would think it was working when it was posted.

    Can someone direct me to the correction that needs to be made?

    Thanks.

    -- Matt

    *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-


  • Hi Matt,

    The project had old flag Optimizer Off. I've switched it to on and attached the new version.

    Please try this,

    Yuri

  • 2017-03-03-122156

    Yuri --

    Thank you for your prompt response.

    I downloaded the ZIP file . . . Put it in a new folder . . . Extracted the IPX file from within . . . Added the Project to the WORKBENCH . . . then I tied to run the SUBROUTINE.

    I received the same error.

    I shut down PREMIER 9.1.4 . . . moved the IPX file (to clear any memory of it from PREMIER) . . . Restarted PREMIER 9.1.4 . . . Added the Project to the WORKBENCH . . . then I tried to run the SUBROUTINE.

    I received the same error.

    I did the same as above with PREMIER 3D V9.3 and the routine works properly.

    Any suggestions on why it is having a problem with 9.1.4?

    Thanks.

    -- Matt
  • Matt,

    I thought you are using 9.3. Please check in 9.3 and let me know the results.

    Yuri
  • 2017-03-03-125120

    Yuri --

    Thank you for your prompt response.

    Here are my results

    PREMIER 9.1.4 = ERROR
    PREMIER 9.2 = WORKS
    PREMIER 3D 9.3 = WORKS

    I have queried the user to learn exactly which PREMIER he is using.

    Any suggestions to make it VERSION INDEPENDENT?

    Thanks.

    -- Matt
  • They are supposed to be version independent, but something got slightly changed in 9.1.4, which broke this macro. But the next versions, including the current handle it properly. 

    Yuri

  • You could try declaring the GetFeaturePoints [out] argument as Object rather than SINGLEPOINT().  The returned Object will still be an array of SINGLEPOINT so you are going to need to access points(vertexIndex).x and y eventually in your macro.
  • 2017-03-03-135940

    Yuri and Craig --

    Thank you for the additional information.

    I thought he was a long time PREMIER CUSTOMER but it seems he just recently purchased PREMIER so he probably has 9.2 (we are checking) so the EXAMPLE CODE may run fine.

    I appreciate your assistance.

    -- Matt

  • edited March 2017
    2017-03-03-171451

    All --

    I have been working on this project with PREMIER (2D) V9.2 and I thought I had it tackled but this glitch has appeared again.

    In the first image below, you will see that a modified version of 

        PrintOutlineCoordinates

    named

        PrintOutlineCoordinates2

    handles the BOUNDARY POINTS as intended (see first image below).

    The problem is that I have created a CLEAN SHEET APP and I have a BUTTON within it that calls the same CODE.

        Private Sub button_SaveRegionBoundaryPoints_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles button_SaveRegionBoundaryPoints.Click
    
            'Handle NO IMAGE
            If ThisApplication.ActiveImage Is Nothing Then Exit Sub
    
            'Connect with the ACTIVE IMAGE
            Dim im As McImage =  ThisApplication.ActiveImage
    
            'Connect with the MEASUREMENT DATA in the ACTIVE IMAGE
            Dim md As McMMData = im.MeasurementsData
    
            'Show and clear the OUTPUT WINDOW
            ThisApplication.Output.Show
            ThisApplication.Output.Clear
    
            'Loop through the FEATURES in the ACTIVE IMAGE
            For Each sf As McMMSubFeature In md.SubFeatures
    
                    'Learn and output the NAME for the FEATURE
                    Dim s As String = _
                        sf.Name
                    ThisApplication.Output.PrintMessage(s)
    
                    'Output the COLUMN HEADERS
                    s = _
                        "X" & vbTab & _
                        "Y"
                    ThisApplication.Output.PrintMessage(s)
    
                    'Create an ARRAY to hold the BOUNDARY POINTS
                    Dim points() As SINGLEPOINT=Nothing
    
                    'Fill the ARRAY with the BOUNDARY POINTS
                    sf.GetFeatures.GetFeaturePoints(sf.FeatureIndex,points)
    
                    'Loop through the BOUNDARY POINTS
                    For Each p As SINGLEPOINT In points
    
                            'Output the CURRENT BOUDARY POINT
                            s = _
                                p.x.ToString("F2") & vbTab & _
                                p.y.ToString("F2")
                            ThisApplication.Output.PrintMessage(s)
    
                        Next
    
                Next
        End Sub

    When I trigger this function (see second image below), the ERROR

       

    appears.

    I tried to implement Craig's suggestion about replacing SINGLEPOINT with OBJECT in the DIM POINTS STATEMENT but it did not resolve the problem.

    Your assistance with this resolving this issue would be much appreciated.

    -- Matt

    *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

    RUNNING PrintOutlineCoordinates2


    RUNNING button_SaveRegionBoundaryPoints_Click


  • Matt,

    Do you have all Imports (at the top of VB file) as in my project?

    Yuri
  • 2017-03-03-175702

    Yuri --

    Thank you for your prompt response.

    Yes . . . to the best of my ability I have IMPORTED the right things.

    Please see below.

    I have also performed an EXPORT REFERENCES from the EXAMPLE PROJECT and performed an IMPORT REFERENCES in my PROJECT.

    -- Matt

    *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-



  • Ok, then I need to look at the details. Can you please post your project? Are you testing it in Premier 9.3?

    Thanks,

    Yuri

  • 2017-03-04-172151

    Yuri --

    Thank you for your response.

    Per your request, I created and attached

        Save Boundary Points Project V1A -- 2017-03-04-172040.ipx
        and
        black-dot.tif

    so you will be able to run the software with the same image that I am using.

    I have been doing the recent DEVELOPMENT and TESTING with PREMIER 9.2.  I do not have PREMIER 9.3 on my computer.

    When I try to load the PROJECT (via FILES or IPX FILE) I get the error shown in the SCREEN CAPTURE shown below.

    Thank you for your assistance.

    -- Matt

    *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-


  • HI Matt,

    I checked your project and here are my notes:

    1. Premier 9.3 is a free upgrade to Premier 9.2, so please download and install it, so we are on the same page. (http://www.mediacy.com/support/productupdates )
    2. Your IPX file looks strange, it looks like you just zipped the folder with IPP project and renamed it to IPX. If yes, then it's not the way you create IPX files. You have to use the Package menu item in the  project workbench.
    3. Your project had Optimizer Off - this was used with old projects, all new projects in 9.2 and above  use "Optimizer On", you can change it in the Project Workbench.

    After this change your project runs correctly.
    4. You should add more checks like:
    If ThisApplication.ActiveImage Is Nothing Then Exit Sub
    as your macro throws errors if the active image is Welcome page.
     

    Regards,

    Yuri


  • 2017-03-05-145124

    Yuri --

    Thank you for your response.  Especially because on WEEKEND TIME.

    1)  I will address this ASAP.

    2)  I created the IPX file with a

        PREMIER + WORKBENCH + FILE + PACKAGE + AS PROJECT PACKAGE

    The only thing out-of-the-ordinary that I did was to put a DATE and TIME at the end of the IPX FILE NAME. 

    3A) 

    I made your suggested change from

        Optimizer Off

    to

        Optimizer On

    and the PROJECT / APP loads and operates in PREMIER 2D 9.2 and PREMIER 3D 9.3 with no complaints.  It still throws errors in 2D 9.1.4 but that is really not a problem

    Thank you very much.

    3A) 

    Regarding how OPTIMIZER got set to OFF, that is a mystery that I cannot explain.

    In the SCREEN CAPTURE below, please see the IPP FILES for 3 PROJECTS (with APP and MOD) that were created with P 3D 93, P 2D 92, and P 2D 914.  Please see that ON is the setting created by 3D93.  2D92 and 2D914 both created an IPP FILE with OFF as the setting.

    4)

    Thank you for the reminder.  There are many FEATURES and FUNCTIONS that need to be added to this to make it complete.

    **

    Thanks again for your assistance with this and other challenges I have had with IPPLUS and IPREMIER.  It has been very helpful.

    -- Matt

    *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-



  • Matt,

    Optimizer is a switch to use different macro engine. The new versions starting from 9.2 should use On (it is On by default starting from 9.3), it ensures code validation on compilation stage and has better .NET support. When it's Off, wrong types or undefined variables could be passed unnoticed, so it's not recommended (from 9.3.1 the Off flag will be detected and prompted to be set to On).

    Yuri

  • 2017-03-06-100207

    Yuri --

    Thank you for the additional information about OPTIMIZER and with the help provided debugging the issue I was experiencing related to it.

    -- Matt
Sign In or Register to comment.