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

Controlling and querying the ALIGNMENT TOOL . . .

2017-04-04-160624

All --

I have two images that vary from each other in ROTATION and TRANSLATION.  This is illustrated in the SCREEN CAPTURES below by the A1 and A2 images.

The PREMIER ALIGNMENT TOOL seems to do a good job of determining the ROTATION and TRANSLATION needed to ALIGN the two images.

This is shown in the BEFORE (TOP) and AFTER (BOTTOM) SCREEN CAPTURE IMAGES below.

When I record a macro during the use of the ALIGN TOOL, I get the routine below.

What code will query the ALIGN TOOL for the ROTATION VALUE (-0.263844698667526R) and TRANSLATION VALUES (39R,68R) represented in the AFTER SCREEN CAPTURE and in

.Transforms.Add(New AffineTransform(39R,68R,1R,-0.263844698667526R))

so that they can be reported to the user?

Thank you in advance for your

-- Matt

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






    Public Function TestAlignTool() As SimpleScript
        TestAlignTool = New SimpleScript
        Dim image1, doc1

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

        With Process.AlignCommands.Gadget(TestAlignTool)
            .CheckState = MediaCy.IQL.Application.McCommand.mcCheckState.Checked
            .Run()
        End With

        With Process.Align.WindowsCommands.AddAll(TestAlignTool)
            .Run()
        End With

        With Process.AlignCommands.Calculate(TestAlignTool)
            .Run()
        End With

        With Process.AlignCommands.Options(TestAlignTool)
            .AlignMethod = MediaCy.Addins.Align.eAlignMethod.FFT
            .DoRotation = False
            .Run()
        End With

        With Process.AlignCommands.Calculate(TestAlignTool)
            .Run()
        End With

        With Process.AlignCommands.Transforms(TestAlignTool)
            .Transforms = New System.Collections.Generic.List(Of AffineTransform)
                .Transforms.Add(New AffineTransform(0R,0R,1R,0R))
                .Transforms.Add(New AffineTransform(39R,68R,1R,-0.263844698667526R))
            .Run()
        End With

        With Process.AlignCommands.Apply(TestAlignTool)
            .Run(image1)
        End With

        With Application.DocumentCommands.Activate(TestAlignTool)
            .Run(image1, doc1)
        End With

        With Application.RibbonCommands.SelectRibbonTab(TestAlignTool)
            .TabName = "Automate"
            .Run()
        End With

    End Function

Best Answer

  • edited April 2017 Accepted Answer
    Hi Matt,

    The AlignTransforms command has GetTransforms function that can be used to retrieve calculated affine transforms. Here is a sample macro:
    
    
        Public Function TestAlignTool() As SimpleScript
            TestAlignTool = New SimpleScript
            Dim image1, doc1
    
            With Process.Align.WindowsCommands.AddAll(TestAlignTool)
                .Run()
            End With
    
            With Process.AlignCommands.Options(TestAlignTool)
                .AlignMethod = MediaCy.Addins.Align.eAlignMethod.FFT
                .DoRotation = True
                .Run()
            End With
    
            With Process.AlignCommands.Calculate(TestAlignTool)
                .Run()
            End With
    
            With Automate.ScriptingCommands.CodeCommand(TestAlignTool)
                If .Run() Then
                    ' User Code Here
                    Dim trc As Mediacy.Addins.Align.AlignTransformsCommand=(New Mediacy.Addins.Align.AlignTransformsCommand).GetTransforms()
                    For Each tr As AffineTransform In trc.Transforms
                        Debug.Print(String.Format("X= {0}, Y={1}, A={2}, S={3}",tr.dx,tr.dy,tr.angle,tr.scaleXY))
                    Next
                End If
            End With
        End Function
    


    Note, that rotation angle is in Radians.

    Yuri

Answers

  • 2017-04-04-162411

    P.S.

    Here are A1.TIF and A2.TIF.

    -- Matt


  • 2017-04-04-162534

    P.P.S.

    It seems the FORUM will not let me post TIF IMAGES.

    Here are A1.JPG and A2.JPG.

    Thanks.

    -- Matt




  • 2017-04-04-174056

    Yuri --

    Thank you for the response and sample code.

    Low battery.

    Will try tomorrow.

    Thanks again.

    -- Matt
  • 2017-04-05-121816

    Yuri --

    I tested the CODE that you provided and it gives me the tools to do the task at hand.

    I modified your SAMPLE CODE a bit (below) so that does not reselect the ALIGNMENT IMAGES and so that the results are shown in the APPLICATION AUTOMATION OUTPUT PANEL.

    I have also attached a SCREEN CAPTURE that shows a different SAMPLE and the ALIGNMENT done by PREMIER and the OUTPUT PANEL showing the VALUES and WITHOUT ALIGNMENT and WITH ALIGNMENT comparisons.

    Thank you again for your assistance.

    -- Matt

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

        Public Function TestAlignTool2() As SimpleScript
            TestAlignTool2 = New SimpleScript
            Dim image1, doc1
    
    '        With Process.Align.WindowsCommands.AddAll(TestAlignTool2)
    '            .Run()
    '        End With
    
            With Process.AlignCommands.Options(TestAlignTool2)
                .AlignMethod = MediaCy.Addins.Align.eAlignMethod.FFT
                .DoRotation = True
                .Run()
            End With
    
            With Process.AlignCommands.Calculate(TestAlignTool2)
                .Run()
            End With
    
            With Automate.ScriptingCommands.CodeCommand(TestAlignTool2)
                If .Run() Then
                    ' User Code Here
                    Dim trc As Mediacy.Addins.Align.AlignTransformsCommand=(New Mediacy.Addins.Align.AlignTransformsCommand).GetTransforms()
                    For Each tr As AffineTransform In trc.Transforms
                        Debug.Print(String.Format("X= {0}, Y={1}, A={2}, S={3}",tr.dx,tr.dy,tr.angle,tr.scaleXY))
                        ThisApplication.Output.Clear
                        ThisApplication.Output.PrintMessage(String.Format("X= {0}, Y={1}, A={2} (rad), S={3}",tr.dx,tr.dy,tr.angle,tr.scaleXY))
                        ThisApplication.Output.PrintMessage(String.Format("X= {0}, Y={1}, A={2} (deg), S={3}",tr.dx,tr.dy,tr.angle*(360/(2*3.14159)),tr.scaleXY))
                    Next
                End If
            End With
        End Function






Sign In or Register to comment.