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

Macro Control of IMAGE COMPARE TOOL . . .

2018-01-16-154048

All --

I have two images AA and BB that need to be ROTATED, TRANSLATED, and SCALED so that they are ALIGNED as well as possible.

I have tried using the ALIGNMENT TOOL but it does not seem to be as good a tool for the job as the IMAGE COMPARE TOOL.

Using the PREMIER MACRO RECORD TOOL, I generated the ROUTINE below while working with the IMAGE COMPARE TOOL to ROTATE, TRANSLATE, and SCALE the AA IMAGE (RED) to match the BB IMAGE (GRN).

QUESTIONS . . .

Q1) If the USER can manipulate the AA image using the MOUSE within the IMAGE COMPARE TOOL, how can the CODE extract the values for ROTATION, TRANSLATION, and SCALE that have been applied to AA to make it match BB from the IMAGE COMPARE TOOL?

Q2) If the USER has values for ROTATION, TRANSLATION, and SCALE, is there any problem feeding those to the IMAGE COMPARE TOOL via

        With Process.CompareCommands.SetAngle(NewMacro)
            .Angle = -142.926926647043R
            .Run(doc1, image2)
        End With

        With Process.CompareCommands.SetPosition(NewMacro)
            .Center = New System.Drawing.PointF(902.8478F,632.179F)
            .Size = New System.Drawing.SizeF(1714F,1349F)
            .Run(doc1, image2)
        End With

Q3) What FUNCTIONS would allow the CODE to handle the work done between IMAGE 2 and IMAGE 4 below?

Q4) Is there a function that would allow the CODE to extract the AA IMAGE that has been ROTATED, TRANSLATED, and SCALED from the IMAGE COMPARE TOOL so that it could be saved as something like AA+ as a very close match to BB?

Thanks in advance.

-- Matt

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


ROUTINE

    Public Function NewMacro() As SimpleScript
        NewMacro = New SimpleScript
        Dim doc1
        Dim var1 = "BB_RGB", image1
        Dim var2 = "AA_RGB", image2, window1
        Dim var3 = "Image_Compare_View", doc2, image3

        With Process.CompareCommands.[New](NewMacro)
            .Run(doc1)
        End With

        With Application.DocumentCommands.Activate(NewMacro)
            .Run(doc1, doc1)
        End With

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

        With Adjust.ImageCommands.Define(NewMacro)
            .Run(var1, image1)
        End With

        With Process.CompareCommands.Add(NewMacro)
            .FilterInput = True
            .Run(doc1, image1)
        End With

        With Adjust.ImageCommands.Define(NewMacro)
            .Run(var2, image2)
        End With

        With Process.CompareCommands.Add(NewMacro)
            .FilterInput = True
            .Run(doc1, image2)
        End With

        With Process.CompareCommands.SelectImage(NewMacro)
            .Selected = True
            .Run(doc1, image2)
        End With

        With Process.CompareCommands.SetAngle(NewMacro)
            .Angle = -142.926926647043R
            .Run(doc1, image2)
        End With

        With Process.CompareCommands.SetPosition(NewMacro)
            .Center = New System.Drawing.PointF(902.8478F,632.179F)
            .Size = New System.Drawing.SizeF(1714F,1349F)
            .Run(doc1, image2)
        End With

        With Application.WindowCommands.Define(NewMacro)
            .Run(doc1, window1)
        End With

        With Application.WindowCommands.ZoomPanScroll(NewMacro)
            .AutoZoom = Window.ZoomPanScroll.AutoZoomMode.None
            .Zoom = 28.3547257876313R
            .Pan = 36
            .Scroll = 0
            .Run(window1)
        End With

        With Process.CompareCommands.SetPosition(NewMacro)
            .Center = New System.Drawing.PointF(903.4931F,623.2288F)
            .Size = New System.Drawing.SizeF(1656.282F,1303.415F)
            .Run(doc1, image2)
        End With

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

        With Application.DocumentCommands.Activate(NewMacro)
            .Run(var3, doc2)
        End With

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

        With Application.DocumentCommands.Activate(NewMacro)
            .Run(doc1, doc1)
        End With

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

        With Process.CompareCommands.SelectImage(NewMacro)
            .Selected = False
            .Run(doc1, image2)
        End With

        With Application.DocumentCommands.Activate(NewMacro)
            .Run(doc2, doc2)
        End With

    End Function


IMAGE 1 -- ORIGINAL CONFIGURATION with MONO versions of AA and BB and RGB versions of AA and BB for simplifying IMAGE COMPARE.




IMAGE 2 -- RESULT OF RUNNING NEWMACRO ROUTINE




IMAGE 3 -- MANUAL RELOCATION AND RESIZE OF WINDOWS WITHIN PREMIER




IMAGE 4 -- MANUAL CLOSE OF IMAGE COMPARE TOOL AND RELOCATION AND RESIZE OF COMPARE VIEW




Answers

  • 2018-01-22-100922

    All --

    Can CODE within the PREMIER WORKBENCH control the IMAGE COMPARE TOOL as queried above?

    Thanks.

    -- Matt
  • Hi Matt,

    All you need is McImageCompareDocument. The ex returns the censer and angle of the first image.

        Public Sub GetImageCompareInfo
            Dim icd As MediaCy.Addins.ImageCompare.McImageCompareDocument
    
            icd = TryCast(ThisApplication.ActiveDocument, MediaCy.Addins.ImageCompare.McImageCompareDocument)
            If icd IsNot Nothing Then
                Debug.Print("Angle = " & icd.Info(0).Angle)
                Debug.Print("Center.X = " & icd.Info(0).Position.Center.X)
                Debug.Print("Center.Y = " & icd.Info(0).Position.Center.Y)
            End If
        End Sub
    To  control images in Image Compare view use McImageCompareDocument.SetPosition/SetAngle, etc.

    Thanks,
    Nikita.
  • 2018-01-22-155248

    Nikita --

    Thank you for the INFORMATION and CODE.

    I'll be working on that project this PM and the only other thing I think I may need is to know if you have any suggestions to address

    "Q3) What FUNCTIONS would allow the CODE to handle the work done between IMAGE 2 and IMAGE 4 below?

    Q4) Is there a function that would allow the CODE to extract the AA IMAGE that has been ROTATED, TRANSLATED, and SCALED from the IMAGE COMPARE TOOL so that it could be saved as something like AA+ as a very close match to BB?"

    The RECORD MACRO TOOL did not add anything to the CODE that helps me with these operations.

    Thanks again.

    -- Matt

  • 2018-01-22-201614

    Nikita --

    I have attempted to use the INFORMATION and CODE you provided and I have mixed results.

    The QUERY for the X, Y, and ANGLE works like a champ.  Thanks.

    The SET for the ANGLE (I have not tried X and Y yet) is not working properly.

    Will you please look at my CODE and tell me where I have gone wrong.

    ADDITIONAL INFORMATION . . .

    After the TIF IMAGES are added into the IMAGE COMPARE by the CODE behind the SETUP COMPARE BUTTON, they are closed in PREMIER.  I think this is what generated the ".tif0" entries when I do the RECORDING that generated the DIM STATEMENTS in UPDATE COMPARE IMAGE.

    Your assistance with this will be greatly appreciated.

    -- Matt

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

    The UPDATE COMPARE VALUES below reads the X, Y, and ANGLE values properly from the RED (DIAG) IMAGE (the SECOND IMAGE loaded into IMAGE COMPARE) and updates the DIALOG BOX.

        Private Sub button_UpdateCompareValues_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles button_UpdateCompareValues.Click
    
            Dim icd As MediaCy.Addins.ImageCompare.McImageCompareDocument
    
            icd = TryCast(ThisApplication.ActiveDocument, MediaCy.Addins.ImageCompare.McImageCompareDocument)
            If icd IsNot Nothing Then
                textBox_CompareCenterX.Text = _
                    Format(icd.Info(1).Position.Center.X,"#,##0.0000")
                textBox_CompareCenterY.Text = _
                    Format(icd.Info(1).Position.Center.Y,"#,##0.0000")
                textBox_CompareAngle.Text = _
                    Format(icd.Info(1).Angle,"#,##0.0000")
            End If
    
        End Sub

    The UPDATE COMPARE IMAGE below is my attempt to set the ANGLE based on the value in the TEXTBOX but the result is that BOTH IMAGES in the IMAGE COMPARE are ROTATED.

        Private Sub button_UpdateCompareImage_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles button_UpdateCompareImage.Click
    
            Dim var0 = "Image Compare Document", doc0
            Dim var1 = "TREAT-01_RGB.tif0", image1
            Dim var2 = "DIAG-01_RGB.tif0", image2
    
            With Application.DocumentCommands.Activate(Nothing)
                .Run(var0, doc0)
            End With
    
            With Adjust.ImageCommands.Define(Nothing)
                .Run(var1, image1)
            End With
    
            With Adjust.ImageCommands.Define(Nothing)
                .Run(var2, image2)
            End With
    
            With Process.CompareCommands.SelectImage(Nothing)
                .Selected = False
                .Run(doc0, image1)
            End With
    
            With Process.CompareCommands.SelectImage(Nothing)
                .Selected = True
                .Run(doc0, image2)
            End With
    
            Dim icd As MediaCy.Addins.ImageCompare.McImageCompareDocument
    
            icd = TryCast(ThisApplication.ActiveDocument, MediaCy.Addins.ImageCompare.McImageCompareDocument)
    
            If icd IsNot Nothing Then
                icd.SetAngle(image2,Val(textBox_CompareAngle.Text))
            End If
    
        End Sub

    This IMAGE shows the IMAGE COMPARE with the TREAT (GREEN) IMAGE added first and the DIAG (RED) IMAGE added second.


    This IMAGE shows that the UPDATE COMPARE VALUES performs properly.


    This IMAGE shows the results of running the UPDATE COMPARE IMAGE after the ANGLE TEXTBOX is set to 90.


  • Hi Matt,

    The angle applied to all images in the view if "image2" is null or not found in the view. Just verify what this image exists in the view. You can use McImageCompareDocument.Info to get complete information about the Image Compare View including images, angles, positions.

    Thanks,
    Nikita.
  • 2018-01-23-111415

    Nikita --

    Thank you for your response.

    I will try to weave the information you have provided into the CODE.

    I will update with the results ASAP.

    Thanks again.

    -- Matt

  • 2018-01-23-120256

    Nikita --

    I tried to apply the information you gave me and I was not successful.

    I went back to trying to RECORD and MODIFY and I have bumped into a similar issue.

    The RECORDED CODE applies the TRANSLATION and ROTATION to both images within IMAGE COMPARE.

    Please see the SCREEN CAPTURES and CODE below.

    Is there a resolution for this?

    Thanks.

    -- Matt

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

    Here is an image that shows PREMIER after the SETUP COMPARE


    Here is an image that shows PREMIER after recording NEW MACRO


    Here is NEW MACRO
        Public Function NewMacro() As SimpleScript
            NewMacro = New SimpleScript
            Dim doc1
            Dim var1 = "DIAG_01_RGB_tif", image1
    
            With Application.DocumentCommands.Active(NewMacro)
                .Run(doc1)
            End With
    
            With Adjust.ImageCommands.Define(NewMacro)
                .Run(var1, image1)
            End With
    
            With Process.CompareCommands.SelectImage(NewMacro)
                .Selected = True
                .Run(doc1, image1)
            End With
    
            With Process.CompareCommands.SetPosition(NewMacro)
                .Center = New System.Drawing.PointF(1100.03F,1179.746F)
                .Size = New System.Drawing.SizeF(1714F,1349F)
                .Run(doc1, image1)
            End With
    
            With Process.CompareCommands.SetAngle(NewMacro)
                .Angle = -27.6225073939496R
                .Run(doc1, image1)
            End With
    
            With Process.CompareCommands.SelectImage(NewMacro)
                .Selected = False
                .Run(doc1, image1)
            End With
    
        End Function

    Here is an image that shows IMAGE COMPARE after performing the same SETUP COMPARE and then running NEW MACRO.



  • Matt, works for me. Just one image moved and rotated. What is your version?

    Thanks,
    Nikita.
  • 2018-01-23-133826

    Here is the PRODUCT and VERSION information.


  • 2018-01-23-134342

    Nikita --

    Thinking that the IMAGE COMPARE TOOL might have been confused by all of the TRIAL and ERROR that it has been subjected to, I:

    ** shut down and restarted PREMIER
    ** opened the two images manually
    ** loaded the two images into IMAGE COMPARE manually
    ** ran NEW MACRO

    The result was the same . . . both layers ROTATED and TRANSLATED.

    Any suggestions?

    Thanks.

    -- Matt





  • Matt, I've downgraded IPP 3D to 9.3.2, took your images and macro and the result is correct.
    Try to update to 9.3.3, unload other projects and references, Try to run following macro and check what correct image is selected in the view:

        Public Function NewMacro() As SimpleScript
            NewMacro = New SimpleScript
            Dim doc1
            Dim var1 = "DIAG_01_RGB_tif", image1
    
            With Application.DocumentCommands.Active(NewMacro)
                .Run(doc1)
            End With
    
            With Adjust.ImageCommands.Define(NewMacro)
                .Run(var1, image1)
            End With
    
            With Process.CompareCommands.SelectImage(NewMacro)
                .Selected = True
                .Run(doc1, image1)
            End With
        End Function
    

    Nikita.
  • edited January 2018
    2018-01-23-143944

    Nikita --

    If I move the layers/images around manually before I run your NEW MACRO, the correct image is selected.




    When I add the SET ANGLE to it, everything is turned though
        Public Function NewMacro() As SimpleScript
    
            NewMacro = New SimpleScript
            Dim doc1
            Dim var1 = "DIAG_01_RGB_tif", image1
    
            With Application.DocumentCommands.Active(NewMacro)
                .Run(doc1)
            End With
    
            With Adjust.ImageCommands.Define(NewMacro)
                .Run(var1, image1)
            End With
    
            With Process.CompareCommands.SelectImage(NewMacro)
                .Selected = True
                .Run(doc1, image1)
            End With
    
            With Process.CompareCommands.SetAngle(NewMacro)
                .Angle = -27.6225073939496R
                .Run(doc1, image1)
            End With
    
        End Function

    When I put a msgbox in between the SELECT IMAGE and the SET ANGLE, the correct image is not selected.

    I only have one project loaded and I am not sure what references could be unloaded.

    Would it be possible to WEBEX to investigate this abnormal behavior?

    Thanks.

    -- Matt


  • 2018-01-23-164939

    Nikita --

    Checking WWW.MEDIACY.COM, the latest PREMIER 3D seems to be the V9.3.2 I am running.

    This is shown below.

    Any further thoughts on a way to make the CODE control the IMAGE COMPARE?

    Thanks.

    -- Matt

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


  • Hi Matt,

    I'll double check 9.3.3 patch for IPP 3D on website. The preferable way to check for updates is "Help/Check for Updates".

    I'm not sure why the simple macro works differently on your system. Could you try the next steps:
    1) cleanup user's identities:  %AppData%, Roaming\Media Cybernetics folder,
    2) cleanup program settings: %AppData% Local\Media_Cybernetics folder,
    3) cleanup user's document folder
    4) uninstall IPP 3D, #1, #2, #3, install IPP 3D

    Thanks,
    Nikita.
  • 2018-01-24-092226

    Nikita --

    Thank you for your response.

    I would like to avoid what seems like MAJOR SURGERY to resolve what seems like a MINOR ISSUE.

    I will transfer the app to my other computer which has PREMIER 9.3.3 and try it there.  If it works properly there, I will follow your suggestion.

    If it doesn't work there, I'll let you know and we can make a plan to investigate this.

    Thanks again.

    -- Matt
  • edited January 2018
    2018-01-24-113535

    Nikita --

    I loaded the IMAGES into IMAGE COMPARE and ran the NEW MACRO CODE on PREMIER 9.2 and it worked.

    If I used CODE to load the IMAGES into IMAGE COMPARE it did not work.

    As mentioned before, the CODE to load the IMAGES into IMAGE COMPARE closes the ORIGINAL IMAGES.

    When I load the IMAGES into IMAGE COMPARE and then close the IMAGES (leaving IMAGE COMPARE open) then NEW MACRO does not work.

    This seems to be the same in PREMIER 9.2 and PREMIER 3D 9.3.2

    Can you please check if your CODE works properly if you:

    OPEN IMAGES
    LOAD IMAGES INTO IMAGE COMPARE
    CLOSE IMAGES (LEAVING IMAGE COMPARE OPEN)
    RUN NEW MACRO

    If this works on your computer then we have a mystery.

    If this does not work on your computer, can you suggest a way to make this work because it does not seem that once the images are within IMAGE COMPARE that they should have to be open within PREMIER.

    Thanks.

    -- Matt

  • Hi Matt,

    Right, you cannot close source images because command
            With Adjust.ImageCommands.Define(NewMacro)
                .Run(var1, image1)
            End With
    checks open images. It just return nothing if not found.

    There is no mystery in my test. As you can see in the screenshot the source images kept open.

    Nikita.

  • 2018-01-24-131603

    Nikita --

    Sorry that I did not make it clear that the ORIGINAL IMAGES were being closed.

    I thought that
            With Adjust.ImageCommands.Define(NewMacro)
                .Run(var1, image1)
            End With
    was connecting with the images within the IMAGE COMPARE WINDOW.

    If the ORIGINAL IMAGES must remain open, I can deal with that.

    I hope the information we have posted here is helpful to another PREMIER PROGRAMMER working with CODE to control the IMAGE COMPARE TOOL.

    Thank you for helping resolving this mystery.

    -- Matt







Sign In or Register to comment.