Subscribe to this thread
Home - General / All posts - UI Script for Image Registration
grmapper
245 post(s)
#11-Apr-14 12:59

Hello All,

I have had some help in the past with UI scripting to convert RGBa images to Palette. I am hoping to do similar scripting so as to register an image with CPs to a vector grid drawing with the same CPs. My current process involves picking the CPs in both the image and the drawing which is no prob. I just want to script the actual registration process of a folder full of these images.

The biggest challenge may actually be figuring out how the script would know which vector file to use for each image in the folder. Perhaps having similar filenames or something like that. The controls I believe the new script will need are:

ComboBoxReference (vector source with CPs)

ComboBoxMethod (Numeric)

TextBoxOrder (3)

My other script which I was hoping to build on in included below if anyone is interested. Thanks for any help.

***************************************************************

' Grmapper - Feb 09, 2013

' With help from TJHP and the Manifold User Community

' Thanks everyone

'

' Script converts all images in a folder to Palette 256

' using UI scripting

Set app = Application

Set doc = Application.ActiveDocument

Set cmp = doc.ComponentSet(folderName)

set cset = Application.ActiveDocument.ComponentSet

folderName = app.InputBox("Enter Data Folder","","Images")

Sub DoSomething(cmp)

Dim fileChar

fileChar = cmp.Name

Set ui = Application.UserInterface

If cmp.Type = ComponentImage Then

Document.ComponentSet(fileChar).Open

ui.InvokeCommand "ImageConvertTo"

'***************************************************

'When using UI scripting, it's best to treat all lines

'of your script as if they were issued to Manifold asynchronously.

'If operation B depends on operation A, it's not enough to issue

'instruction B after instruction A. You have to test whether A

'has completely before attempting B. Sometimes the effective

'execution order can look *very* strange. Almost as if "Run is

'separate thread" means "Run each line its own thread".

'Above provided by TJHB at http://www.georeference.org/forum/t118443.7

Do ' Nothing

Loop Until ui.DisplaysModalDialog

Do ' Nothing

Loop Until ui.ModalDialog.Caption = "Convert To"

'****************************************************

Set dlg = ui.ModalDialog

dlg.ControlSet("ComboBoxTarget").Text = "Palette"

dlg.ControlSet("ComboBoxPalette").Text = "Adaptive"

dlg.ControlSet("TextBoxColors").Text = "256"

dlg.Accept

Application.WindowSet.ActiveWindow.Close

ElseIf cmp.Type = ComponentFolder Then

For Each child In cmp.Children

DoSomething child

Next

End If

End Sub

Sub Main

DoSomething Application.ActiveDocument.Componentset(folderName)

End Sub

cartomatic

905 post(s)
#11-Apr-14 13:55

some kind of naming convention would be ok, perhaps just a bit hard to maintain sometimes. Alternatively you could store the registration data in a table, and then just dynamically create all the control points and trigger the registration.

have you got an example of data that can be shared?


maps made easy - www.cartomatic.pl || www.cartoninjas.net

grmapper
245 post(s)
#12-Apr-14 14:00

Thanks for the interest and the major step forward from AdamW. I will start looking at doing multiple files from a folder. In the meantime I have attached a map file with an Image folder containing 3 test image files and also 3 target files.

The actual projected image is no good but for testing it meets all the criteria AdamW mentioned below. Data is just for testing.

Thanks again.

Attachments:
reg_test.map

adamw


10,447 post(s)
#12-Apr-14 15:12

An adaptation of the script below for this MAP file:

'VBScript

Sub WaitForDialog(name)

  Set ui = Application.UserInterface

  Do

    If ui.DisplaysModalDialog Then

      If ui.ModalDialog.Caption = name Then

        Exit Sub

      End If

    End If

  Loop

End Sub

 

Sub Register(src, tgt)

  src.Open

  Set ui = Application.UserInterface

  Set pane = ui.Panes("Control Points")

  pane.ControlSet("ViewControlPointsRegister").Push

  WaitForDialog "Register"

  Set dlg = ui.ModalDialog

  dlg.ControlSet("ComboBoxReference").Text = tgt.Name

  dlg.ControlSet("ComboBoxMethod").Text = "Numeric (polynomial)"

  dlg.ControlSet("TextBoxOrder").Text = "3"

  dlg.Accept

End Sub

 

Sub Main

  Set cset = Document.ComponentSet

  For Each cmp in cset("Images").Children

    If cmp.Type = ComponentImage Then

      index = cset.ItemByName(cmp.Name & "_Drawing")

      If index >= 0 Then

        Set dwg = cset(index)

        If dwg.Type = ComponentDrawing Then

          Register cmp, dwg

        End If

      End If

    End If

  Next

End Sub

The script will check all images in the folder named "Images", try to find a drawing corresponding to each image, then register the image to the drawing, if successful.

The first two subs are exactly the same as in the first script.

adamw


10,447 post(s)
#12-Apr-14 15:32

Just in case, you can bail out of the registration if, for example, there is not enough matching control points between the components, by re-checking the value of the respective control after an attempt to set, eg:

'VBScript

...

 

Sub Register(src, tgt)

  ...

  dlg.ControlSet("ComboBoxReference").Text = "Numeric (polynomial)"

  If dlg.ControlSet("ComboBoxReference").Text <> "Numeric (polynomial)" Then

    Exit Sub ' numeric option wasn't available

  End If

  ...

End Sub

 

...

I guess it would also be a good idea to log names of registered components so you can leave the script running overnight, and then see what exactly it did in the morning.

adamw


10,447 post(s)
#12-Apr-14 09:48

Example script (requires an image named "Image", a drawing named "Image Target", and enough common control points between them to have Numeric registration of order 3):

'VBScript

Sub WaitForDialog(name)

  Set ui = Application.UserInterface

  Do

    If ui.DisplaysModalDialog Then

      If ui.ModalDialog.Caption = name Then

        Exit Sub

      End If

    End If

  Loop

End Sub

 

Sub Register(src, tgt)

  src.Open

  Set ui = Application.UserInterface

  Set pane = ui.Panes("Control Points")

  pane.ControlSet("ViewControlPointsRegister").Push

  WaitForDialog "Register"

  Set dlg = ui.ModalDialog

  dlg.ControlSet("ComboBoxReference").Text = tgt.Name

  dlg.ControlSet("ComboBoxMethod").Text = "Numeric (polynomial)"

  dlg.ControlSet("TextBoxOrder").Text = "3"

  dlg.Accept

End Sub

 

Sub Main

  Set cset = Document.ComponentSet

  Register cset("Image"), cset("Image Target")

End Sub

The script has to be set to run in a separate thread.

Hope this helps somewhat.

Manifold User Community Use Agreement Copyright (C) 2007-2021 Manifold Software Limited. All rights reserved.