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

Options within IMAGE COMPARE . . .

All --

I have an application that I'm working on that involves two images.  They are:

    1) A SAMPLE IMAGE from a MICROSCOPE
    2) A PATTERN IMAGE from a STANDARDIZED TEST (Black Line Pattern on White Background)

The PATTERN IMAGE must be moved and rotated to line up with features in the SAMPLE IMAGE.

Using a recommendation from NIKITA, I am using the IMAGE COMPARE function to adjust the PATTERN via the following:

    1) XSHIFT
    2) YSHIFT
    3) ANGLE

Since IMAGE COMPARE does not have an AND FUNCTION on the APPLY, I would like to get a copy of the SHIFTED and ROTATED PATTERN IMAGE that I can AND with the SAMPLE IMAGE to get the kind of SAMPLE WITH PATTERN IMAGE that the end user desires.

Unfortunately, when I DELETE the SAMPLE IMAGE "LAYER" from the IMAGE COMPARE and then do an APPLY (VIEW) , the resulting image is not clipped so that I can AND it with the SAMPLE IMAGE.

I have tried all of the options (WEIGHTING, EXPORT, ALLOW RESIZE) that I see within IMAGE COMPARE, and I don't find any combinations that do what I need to do.

If I INVERT my PATTERN IMAGE (make it White Line Pattern on a Black Background) and then do a APPLY DIFFERENCE, I get almost what I'm looking for except that IMAGE COMPARE has changed the size of the RESULTING IMAGE.

I have included DEMO05 (below) that illustrates what I'm trying to do using two images that are

    Width (px):    1936   
    Height (px):    1456   

and named

    "C:\temp\A.tif"
    "C:\temp\Pattern.jpg"
   
Is there a way to modify this FUNCTION to do what I'm looking for or will I have to use the

    1) XSHIFT
    2) YSHIFT
    3) ANGLE

I learn from IMAGE COMPARE to do the SHIFT and ROTATE as separate functions?

Thanks.

-- Matt

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    Public Function demo05() As SimpleScript
        demo05 = New SimpleScript
        Dim docList1 = New List(1), doc1
        Dim docList2 = New List(1), doc2, doc3, image1, image2
        Dim var1 = "Image_Compare_View", doc4, image3

        With Application.DocumentCommands.Open(demo05)
            .Filenames = New String() {"C:\temp\A.tif"}
            .Run(docList1)
        End With

        With Application.DocumentCommands.Activate(demo05)
            .Run(docList1(0), doc1)
        End With

        With Application.DocumentCommands.Open(demo05)
            .Filenames = New String() {"C:\temp\Pattern.jpg"}
            .Run(docList2)
        End With

        With Application.DocumentCommands.Activate(demo05)
            .Run(docList2(0), doc2)
        End With

        With Process.CompareCommands.New(demo05)
            .Run(doc3)
        End With

        With Application.DocumentCommands.Activate(demo05)
            .Run(doc3, doc3)
        End With

        With Application.RibbonCommands.SelectRibbonTab(demo05)
            .TabName = "ImageCompare"
            .Run()
        End With

        With Process.CompareCommands.Add(demo05)
            .FilterInput = True
            .Run(doc3, doc1)
        End With

        With Process.CompareCommands.Add(demo05)
            .FilterInput = True
            .Run(doc3, doc2)
        End With

        With Adjust.ImageCommands.Define(demo05)
            .Run(doc2, image1)
        End With

        With Process.CompareCommands.SelectImage(demo05)
            .Selected = True
            .Run(doc3, image1)
        End With

        With Process.CompareCommands.SetPosition(demo05)
            .Center = New System.Drawing.PointF(1097.359F,543.195F)
            .Size = New System.Drawing.SizeF(1935F,1455F)
            .Run(doc3, image1)
        End With

        With Process.CompareCommands.SetAngle(demo05)
            .Angle = 20R
            .Run(doc3, Nothing)
        End With

        With Process.CompareCommands.SelectImage(demo05)
            .Selected = False
            .Run(doc3, image1)
        End With

        With Adjust.ImageCommands.Define(demo05)
            .Run(doc1, image2)
        End With

        With Process.CompareCommands.SelectImage(demo05)
            .Selected = True
            .Run(doc3, image2)
        End With

        With Process.CompareCommands.Remove(demo05)
            .Run(doc3, Nothing)
        End With

        With Application.RibbonCommands.SelectRibbonTab(demo05)
            .TabName = "Process"
            .Run()
        End With

        With Application.DocumentCommands.Activate(demo05)
            .Run(var1, doc4)
        End With

        With Process.CompareCommands.Apply(demo05)
            .Type = MediaCy.Addins.ImageCompare.ResultTypes.View
            .Cleanup = True
            .Run(doc3, image3)
        End With

    End Function



Best Answers

  • Options
    Answer ✓
    Hi Matt,

    The macro should create the result image like you need:
    
        Public Function Image_Compare_Apply() As SimpleScript
            Image_Compare_Apply = New SimpleScript
            Dim doc1
    
            With Application.DocumentCommands.Active(Image_Compare_Apply)
                .Run(doc1)
            End With
    
            With Automate.ScriptingCommands.CodeCommand(Image_Compare_Apply)
                If .Run() Then
                    ' User Code Here
                    Dim ic As MediaCy.Addins.ImageCompare.McImageCompareDocument = TryCast(doc1, MediaCy.Addins.ImageCompare.McImageCompareDocument)
                    Dim sIm As McImage = Nothing, sImC As System.Drawing.PointF, pIm As McImage = Nothing, pImC As System.Drawing.PointF, pImA As Double
                    Dim temp As McImage, dX As Double, dY As Double, sX As Double, sY As Double
    
                    If ic IsNot Nothing Then
                        For Each info As MediaCy.Addins.ImageCompare.McInfo In ic.Info
                            If sIm Is Nothing Then
                                sIm = info.Image
                                sImC = info.Position.Center
                            ElseIf pIm Is Nothing Then
                                pIm = info.Image
                                pImC = info.Position.Center
                                pImA = info.Angle
                                Exit For
                            End If
                        Next
                    End If
    
                    If sIm IsNot Nothing AndAlso pIm IsNot Nothing Then
                        pIm = pIm.Duplicate(mcImageCreateFlags.mcicfNotVisible Or mcImageCreateFlags.mcicfNoAddToCollection) 'duplicate pattern image
                        pIm.LookupTable.Inverse = True : pIm.LookupTable.Realize : pIm.LookupTables.Apply 'invert pattern image
                        pIm = pIm.Geometry.Rotate(-pImA, MediaCy.IQL.Operations.mcWarpClip.mcwcClip, mcImageCreateFlags.mcicfNotVisible Or mcImageCreateFlags.mcicfNoAddToCollection) 'rotate
    
                        If pImC.X > sImC.X Then
                            dX = pImC.X - sImC.X : sX = -1
                        Else
                            dX = -1 : sX = sImC.X - pImC.X
                        End If
    
                        If pImC.Y > sImC.Y Then
                            dY = pImC.Y - sImC.Y : sY = -1
                        Else
                            dY = -1 : sY = sImC.Y - pImC.Y
                        End If
    
                        temp = .Application.Images.Add("temp", pIm.Width, pIm.Height, pIm.FrameCount, pIm.QuickType, mcImageCreateFlags.mcicfNotVisible Or mcImageCreateFlags.mcicfNoAddToCollection)
                        temp.Geometry.Paste(pIm, dX, dY, sX, sY) 'shift
                        pIm = temp
                        pIm.LookupTable.Inverse = True : pIm.LookupTable.Realize : pIm.LookupTables.Apply 'invert pattern image back
    
                        temp = sIm.Duplicate
                        temp.DisplayName = "Image_Compare_Apply"
                        temp.Op.And(pIm)
                    End If
                End If
            End With
        End Function
    Note:
    1) Image Compare view should be an Active View,
    2) The sample image should be added to the Image Compare view first (pattern - second).
    3) Pattern image is a black grid on white background

    Nikita.
  • Options
    Answer ✓
    Hi Matt,

    I added few lines to close the Image Compare window:

        Public Function Image_Compare_Apply() As SimpleScript
            Image_Compare_Apply = New SimpleScript
            Dim doc1, win1
    
            With Application.DocumentCommands.Active(Image_Compare_Apply)
                .Run(doc1)
            End With
    
            With Application.WindowCommands.Active(Image_Compare_Apply)
                .Run(win1)
            End With
    
            With Automate.ScriptingCommands.CodeCommand(Image_Compare_Apply)
                If .Run() Then
                    ' User Code Here
                    Dim ic As MediaCy.Addins.ImageCompare.McImageCompareDocument = TryCast(doc1, MediaCy.Addins.ImageCompare.McImageCompareDocument)
                    Dim sIm As McImage = Nothing, sImC As System.Drawing.PointF, pIm As McImage = Nothing, pImC As System.Drawing.PointF, pImA As Double
                    Dim temp As McImage, dX As Double, dY As Double, sX As Double, sY As Double
                    Dim w As McWindow = TryCast(win1, McWindow)
    
                    If ic IsNot Nothing Then
                        For Each info As MediaCy.Addins.ImageCompare.McInfo In ic.Info
                            If sIm Is Nothing Then
                                sIm = info.Image
                                sImC = info.Position.Center
                            ElseIf pIm Is Nothing Then
                                pIm = info.Image
                                pImC = info.Position.Center
                                pImA = info.Angle
                                Exit For
                            End If
                        Next
                    End If
    
                    If sIm IsNot Nothing AndAlso pIm IsNot Nothing Then
                        pIm = pIm.Duplicate(mcImageCreateFlags.mcicfNotVisible Or mcImageCreateFlags.mcicfNoAddToCollection) 'duplicate pattern image
                        pIm.LookupTable.Inverse = True : pIm.LookupTable.Realize : pIm.LookupTables.Apply 'invert pattern image
                        pIm = pIm.Geometry.Rotate(-pImA, MediaCy.IQL.Operations.mcWarpClip.mcwcClip, mcImageCreateFlags.mcicfNotVisible Or mcImageCreateFlags.mcicfNoAddToCollection) 'rotate
    
                        If pImC.X > sImC.X Then
                            dX = pImC.X - sImC.X : sX = -1
                        Else
                            dX = -1 : sX = sImC.X - pImC.X
                        End If
    
                        If pImC.Y > sImC.Y Then
                            dY = pImC.Y - sImC.Y : sY = -1
                        Else
                            dY = -1 : sY = sImC.Y - pImC.Y
                        End If
    
                        temp = .Application.Images.Add("temp", pIm.Width, pIm.Height, pIm.FrameCount, pIm.QuickType, mcImageCreateFlags.mcicfNotVisible Or mcImageCreateFlags.mcicfNoAddToCollection)
                        temp.Geometry.Paste(pIm, dX, dY, sX, sY) 'shift
                        pIm = temp
                        pIm.LookupTable.Inverse = True : pIm.LookupTable.Realize : pIm.LookupTables.Apply 'invert pattern image back
    
                        temp = sIm.Duplicate
                        temp.DisplayName = "Image_Compare_Apply"
                        temp.Op.And(pIm)
    
                        'close Image Compare window
                        ic.Modified=False
                        w.Close
                    End If
                End If
            End With
        End Function
    

    Nikita.

Answers

  • Options
    Matt, the size of the result image depends from the size/position/scaling of the source images and covers all source images.
    If I understand correctly, the Image Compare result image is not working for you because 1) should be "AND" operation 2) should be clipped by sample image bounds. Just to confirm, please, add screenshots of the Image Compare view with 2 images and the result image you are trying to create - I'll make a macro for you.
  • Options
    Nikita --

    Thank you for your reply and your offer to assist.

    I have been unable to make an attachment work within this forum for a while so I have sent an e-mail to

        TECHSUPPORT@MEDIACY.COM

    that includes

        A.TIF <-- Sample Image
        PATTERN.JPG <-- Sample Pattern
        a vs pattern.txt <-- SHIFTS and ROTATES determined by IMAGE COMPARE
        A + Pattern Info for Nikita.jpg << SCREEN CAPTURE showing the issue

    I'll try to attach / submit those images her on the FORUM after I press the POST COMMENT BUTTON.

    Thanks again.

    -- Matt






  • Options
    Nikita --

    It looks like I was successful in ATTACHING a TXT FILE and two JPG FILES to this DISCUSSION / QUESTION but the FORUM does not seem to like the A.TIF IMAGE FILE (maybe too big . . . 8 MB).

    You can see what A.TIF looks like from the

        A + Pattern Info for Nikita.jpg

    image.

    The dimensions of

        a.tif
        Pattern.jpg

    are

        Width (px):    1936   
        Height (px):    1456   

    Thanks again.

    -- Matt

       






  • Options
    Nikita --

    Thank you for

     Public Function Image_Compare_Apply() As SimpleScript

    I'm working with different customer on a different project today but I'll test this out ASAP.

    Thanks again.

    -- Matt

  • Options
    Nikita --

    Thank you again for the

     Public Function Image_Compare_Apply() As SimpleScript

    I have been able to run this FUNCTION within PREMIER on my computer.

    It looks like your code will be the foundation for using IMAGE COMPARE for this PREMIER USER'S application.

    I'm sure that I'll learn some new things about PREMIER while adapting this code for this application.

    Thank again.

    -- Matt
  • Options
    Nikita --

    The

         Image_Compare_Apply

    code that you wrote is super.

    There is only one rough edge that I have tried to eliminate but I've not been successful.

    After your code runs, there are two "image" open within PREMIER.  They are:

        A) The IMAGE COMPARE IMAGE (actually it seems this is a document) (inactive)
        B) The IMAGE with the DISPLAY NAME = "Image_Compare_Apply" (active)

    I want to work with B but I no longer need A so I would like to close it .

    I can activate A with

            'Activate the IMAGE COMPARE IMAGE
            With Application.DocumentCommands.Activate(Nothing)
                .Run(doc1, doc1)
            End With
    But I do not seem to be able to close A with

        ThisApplication.ActiveImage.Close

    because A seems to be a DOCUMENT and not an IMAGE.

    I've tried doing a RECORD MACRO while closing A and nothing useful is generated

    The only solution I've come up with is to save B and then do a

            With Application.WindowCommands.CloseAll(Nothing)
                .Run()
            End With
    and then reopen B.

    This seems to be a brute force process that I would like to avoid if possible.

    Can you please point me toward the command or code that will resolve this issue?

    Thanks.

    -- Matt








  • Options
    Nikita --

    Thank you for the fast response and for the modifications that will make

         Image_Compare_Apply()

    close the IMAGE COMPARE WINDOW for the user after combining the SAMPLE IMAGE and PATTERN IMAGE.

    I have added

            Dim win1
    
    .
    .
    .

            With Application.WindowCommands.Active(Image_Compare_Apply)
                .Run(win1)
            End With

    .
    .
    .

    Dim w As McWindow = TryCast(win1, McWindow)

    .
    .
    .

    'close Image Compare window ic.Modified=False w.Close

    in the appropriate locations of the modified version of the routine that you created that is within the APP.

    Everything works great.

    Thanks again.

    -- Matt

Sign In or Register to comment.