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

Issues with ajustement setting not applying.

Hi,

I recorder this macro to switch from composite view, apply some adjustment to each channel and redisplay the composite view.

When I do It manually, the composite picture is displayed properly, but when I run the macro, the adjustment are applied to each channel in the non composite view but they are applied only to channel 3 in the composite display.

I tried to work directly on the composite view, but I have issues with referring the channels in the composite view.

Thanks  

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

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

        With Application.DocumentCommands.Active(NewMacro)
            .Run(doc1)
        End With

        With Process.Filter.EnhancementCommands.Gauss(NewMacro)
            .Passes = 1
            .KernelSize = Filters.mcKernelSize2.mcks3x3
            .Strength = 100
            .Run(doc1, image1)
        End With

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

        With View.ImageSetViewCommands.Options(NewMacro)
            .ColorCompositeView = False
            .Run(window1)
        End With

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

        With Adjust.LookupTableCommands.WhiteLevel(NewMacro)
            .WhiteLevel = 1000R
            .LUT = -1
            .Run(doc1)
        End With

        With View.ImageSetViewCommands.Options(NewMacro)
            .ViewLocation = New McImageSetLocations
            .ViewLocation.Add(mcImageSetDimensions.mcisdChannel, 1)
            .Run(window1)
        End With

        With Adjust.LookupTableCommands.WhiteLevel(NewMacro)
            .WhiteLevel = 1000R
            .LUT = -1
            .Run(doc1)
        End With

        With View.ImageSetViewCommands.Options(NewMacro)
            .ViewLocation = New McImageSetLocations
            .ViewLocation.Add(mcImageSetDimensions.mcisdChannel, 2)
            .Run(window1)
        End With

        With Adjust.LookupTableCommands.WhiteLevel(NewMacro)
            .WhiteLevel = 1000R
            .LUT = -1
            .Run(doc1)
        End With

        With View.ImageSetViewCommands.Options(NewMacro)
            .ColorCompositeView = True
            .Run(window1)
        End With

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

        With View.ImageViewCommands.Options(NewMacro)
            .View.AutoZoomMode = MediaCy.IQL.Display.Viewer.mcAutoZoomMode.mazmNone
            .Run(window1)
        End With

        With Application.WindowCommands.ExportToPowerPoint(NewMacro)
            .Export = Window.ExportToPowerPoint.ExportOptions.DocumentView
            .Run(New List({window1}))
        End With


    End Function

Answers

  • I checked your macro and can see the problem. The issue is that the composite view is updated after some delay (when all messages are processed), so in the macro the view is exported to the PowerPoint before it gets updated.
    Adding some delay before exporting the view fixes the problem.
    I've added CodeCommand with DoEvents function. Here is the complete macro:

    Public Function NewMacro() As SimpleScript
            NewMacro = New SimpleScript
            Dim doc1, image1, window1,image2,window2,doc2
    
            With Application.RibbonCommands.SelectRibbonTab(NewMacro)
                .TabName = "Process"
                .Run()
            End With
    
            With Application.DocumentCommands.Active(NewMacro)
                .Run(doc1)
            End With
    
            With Process.Filter.EnhancementCommands.Gauss(NewMacro)
                .Passes = 1
                .KernelSize = Filters.mcKernelSize2.mcks3x3
                .Strength = 100
                .Run(doc1, image1)
            End With
    
            With Application.WindowCommands.Define(NewMacro)
                .Run(doc1, window1)
            End With
    
            With View.ImageSetViewCommands.Options(NewMacro)
                .ColorCompositeView = False
                .Run(window1)
            End With
    
            With Application.RibbonCommands.SelectRibbonTab(NewMacro)
                .TabName = "Adjust"
                .Run()
            End With
    
            With Adjust.LookupTableCommands.WhiteLevel(NewMacro)
                .WhiteLevel = 1000R
                .LUT = -1
                .Run(doc1)
            End With
    
            With View.ImageSetViewCommands.Options(NewMacro)
                .ViewLocation = New McImageSetLocations
                .ViewLocation.Add(mcImageSetDimensions.mcisdChannel, 1)
                .Run(window1)
            End With
    
            With Adjust.LookupTableCommands.WhiteLevel(NewMacro)
                .WhiteLevel = 1000R
                .LUT = -1
                .Run(doc1)
            End With
    
            With View.ImageSetViewCommands.Options(NewMacro)
                .ViewLocation = New McImageSetLocations
                .ViewLocation.Add(mcImageSetDimensions.mcisdChannel, 2)
                .Run(window1)
            End With
    
            With Adjust.LookupTableCommands.WhiteLevel(NewMacro)
                .WhiteLevel = 1000R
                .LUT = -1
                .Run(doc1)
            End With
    
            With View.ImageSetViewCommands.Options(NewMacro)
                .ColorCompositeView = True
                .Run(window1)
            End With
    
            With Automate.ScriptingCommands.CodeCommand(NewMacro)
                If .Run() Then
                    'wait until the composite view is updated
                    System.Windows.Forms.Application.DoEvents
                End If
            End With
    
            With View.ImageViewCommands.Options(NewMacro)
                .View.AutoZoomMode = MediaCy.IQL.Display.Viewer.mcAutoZoomMode.mazmNone
                .Run(window1)
            End With
    
    
            With Application.WindowCommands.ExportToPowerPoint(NewMacro)
                .Export = Window.ExportToPowerPoint.ExportOptions.DocumentView
                .Run(New List({window1}))
            End With
    
        End Function
    

    Yuri 
  • YuriG said:
    I checked your macro and can see the problem. The issue is that the composite view is updated after some delay (when all messages are processed), so in the macro the view is exported to the PowerPoint before it gets updated.
    Adding some delay before exporting the view fixes the problem.
    I've added CodeCommand with DoEvents function. Here is the complete macro:

    Public Function NewMacro() As SimpleScript
            NewMacro = New SimpleScript
            Dim doc1, image1, window1,image2,window2,doc2
    
            With Application.RibbonCommands.SelectRibbonTab(NewMacro)
                .TabName = "Process"
                .Run()
            End With
    
            With Application.DocumentCommands.Active(NewMacro)
                .Run(doc1)
            End With
    
            With Process.Filter.EnhancementCommands.Gauss(NewMacro)
                .Passes = 1
                .KernelSize = Filters.mcKernelSize2.mcks3x3
                .Strength = 100
                .Run(doc1, image1)
            End With
    
            With Application.WindowCommands.Define(NewMacro)
                .Run(doc1, window1)
            End With
    
            With View.ImageSetViewCommands.Options(NewMacro)
                .ColorCompositeView = False
                .Run(window1)
            End With
    
            With Application.RibbonCommands.SelectRibbonTab(NewMacro)
                .TabName = "Adjust"
                .Run()
            End With
    
            With Adjust.LookupTableCommands.WhiteLevel(NewMacro)
                .WhiteLevel = 1000R
                .LUT = -1
                .Run(doc1)
            End With
    
            With View.ImageSetViewCommands.Options(NewMacro)
                .ViewLocation = New McImageSetLocations
                .ViewLocation.Add(mcImageSetDimensions.mcisdChannel, 1)
                .Run(window1)
            End With
    
            With Adjust.LookupTableCommands.WhiteLevel(NewMacro)
                .WhiteLevel = 1000R
                .LUT = -1
                .Run(doc1)
            End With
    
            With View.ImageSetViewCommands.Options(NewMacro)
                .ViewLocation = New McImageSetLocations
                .ViewLocation.Add(mcImageSetDimensions.mcisdChannel, 2)
                .Run(window1)
            End With
    
            With Adjust.LookupTableCommands.WhiteLevel(NewMacro)
                .WhiteLevel = 1000R
                .LUT = -1
                .Run(doc1)
            End With
    
            With View.ImageSetViewCommands.Options(NewMacro)
                .ColorCompositeView = True
                .Run(window1)
            End With
    
            With Automate.ScriptingCommands.CodeCommand(NewMacro)
                If .Run() Then
                    'wait until the composite view is updated
                    System.Windows.Forms.Application.DoEvents
                End If
            End With
    
            With View.ImageViewCommands.Options(NewMacro)
                .View.AutoZoomMode = MediaCy.IQL.Display.Viewer.mcAutoZoomMode.mazmNone
                .Run(window1)
            End With
    
    
            With Application.WindowCommands.ExportToPowerPoint(NewMacro)
                .Export = Window.ExportToPowerPoint.ExportOptions.DocumentView
                .Run(New List({window1}))
            End With
    
        End Function
    

    Yuri 
    Thanks Yuri but the issue is already when the composite image is updated even before it saves it to PowerPoint. I added the part of code you suggested  after each lookup table adjustment. Now it manages to update 2 of the 3 channels. However sometime 1 and 3 are updated and sometime it's 2 and 3. As you can see on the picture the channels are updated on the little icons ( and on the single channel view)  but not on the composite view itself.
  • Important point is to have always the same starting conditions, in your case the 1st channel should be active when ColorComposite gets switched off (otherwise you need to record activation of the first channel).
    If it still doesn't work, try to reproduce the problem on one of the demo images (e.g. the one from Colocalization folder) and attach the complete macro project (packaged as IPX) to the post.

    Yuri

  • Hi,

    I tested the File in the colocalization folder and it's a hit and miss. Sometime it works sometime it does not. I wanted to upload the IPP file but I get the "File Format is no allowed" message

  • Do you mean that it's not always working for "15' HGF LAMP488 4.lsm" image (in Colocalization folder)? Or it's working for the demo image, but it's not working for your own image?

    Yuri
  • YuriG said:
    Do you mean that it's not always working for "15' HGF LAMP488 4.lsm" image (in Colocalization folder)? Or it's working for the demo image, but it's not working for your own image?

    Yuri
    It's not always working for the  "15' HGF LAMP488 4.lsm" image .  
  • Here is a more complex macro that will apply new LUT to color composite view:

        Public Function ApplyToCC() As SimpleScript
            ApplyToCC = New SimpleScript
    
            With Automate.ScriptingCommands.CodeCommand(ApplyToCC)
                If .Run() Then
                    ' User Code Here
                    If ThisApplication.ActiveWindowEx IsNot Nothing Then
                        If TypeOf ThisApplication.ActiveWindowEx.DocumentView Is MediaCy.Viewers.Set.McSetLocationViewBase Then
                            Dim sbv As MediaCy.Viewers.Set.McSetLocationViewBase = ThisApplication.ActiveWindowEx.DocumentView
    
                            If TypeOf sbv.BaseDocumentView Is MediaCy.Viewers.Image.McSeqView Then
                                Dim sv As MediaCy.Viewers.Image.McSeqView = sbv.BaseDocumentView
                                Dim ccd As MediaCy.Viewers.Image.McColorCompositeDocument = sv.ColorCompositeDocument
    
                                For Each im As McImage In ccd.Images.Keys
                                    Dim d As MediaCy.Viewers.Image.McDisplayInfo
                                    d = ccd.ImageDisplay(im)
                                    d.Reload = True             'restore image view display -> CC display sync
                                    d.Init(im)                  'init display from channel
                                    ccd.ImageDisplay(im) = d    'apply display to CC view
                                Next
                            End If
                        End If
                    End If
                End If
            End With
        End Function
    
    

    you can call this macro instead of System.Windows.Forms.Application.DoEvents , like this:

            With Automate.ScriptingCommands.CodeCommand(NewMacro)
                If .Run() Then
                    'wait until the composite view is updated
                    'System.Windows.Forms.Application.DoEvents
                    ApplyToCC
                End If
            End With
    

    Please test it and let us know if it fixes your problem.

    Yuri
Sign In or Register to comment.